Jump to content

Search the Community

Showing results for tags 'interrupt'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • News
    • Announcements
    • Suggestions
    • New users say Hi!
  • Spotlight!
    • Sponsor Spotlight
    • Sponsor Giveaways
  • Energia
    • Energia - MSP
    • Energia - TivaC/CC3XXX
    • Energia - C2000
    • Energia Libraries
  • MSP Technical Forums
    • General
    • Compilers and IDEs
    • Development Kits
    • Programmers and Debuggers
    • Code vault
    • Projects
    • Booster Packs
    • Energia
  • Tiva-C, Hercules, CCXXXX ARM Technical Forums
    • General
    • SensorTag
    • Tiva-C, Hercules, CC3XXX Launchpad Booster Packs
    • Code Vault
    • Projects
    • Compilers and IDEs
    • Development Kits and Custom Boards
  • Beagle ARM Cortex A8 Technical Forums
    • General
    • Code Snippets and Scripts
    • Cases, Capes and Plugin Boards
    • Projects
  • General Electronics Forum
    • General Electronics
    • Other Microcontrollers
  • Connect
    • Embedded Systems/Test Equipment Deals
    • Buy, Trade and Sell
    • The 43oh Store
    • Community Projects
    • Fireside Chat
  • C2000 Technical Forums
    • General
    • Development Kits
    • Code Vault
    • Projects
    • BoosterPacks


There are no results to display.

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Website URL





Found 32 results

  1. I'm following the attached I2C example code provided by TI. The MCU is put into LPM0 with three interrupts enabled. On a pending RX interrupt, the ISR stores one byte of the receive buffer and clears the LPM0 SR bits taking the MCU out of LPM0 (lines 133-135). What's the reason for exiting LPM0? And why isn't the __bic_SR_register_on_exit(LPM0_bits) used for the NACIFG and BCNTIFG? msp430fr235x_euscib0_i2c_10.c
  2. Hi, I am developing a monitor that will wake up every 15 minutes read and sensor and send some data. I'm using an EXP430G2 onto which I have successfully soldered the 32KHz crystal. The interrupts are working OK, waking every 16 seconds and toggling a LED. I'm using TACTL = TASSEL_1 +ID_3 + MC_2 +TAIE and Timer0-A1. My problem occurs whenever I try to use either the serial port (using Serial.print) or the AirBooster Pack. Then nothing happens - the system freezes. I'm assuming this has something to do with use of interrupts by the Serial and Airbooster libraries but I have no idea what. Any pointers on how to resolve this much appreciated. (Note serial and airbooster work fine when not using interrupts) Cheers brian
  3. Thanks in advance for helping. New to microcontrollers, not fluent in C so would prefer higher level language like Energia. Using an MSP430F5529LP to drive a stepper motor, creating a square wave using timer A interrupt handler. That works fine, but would like an additional input to the MSP to increase/decrease the speed. In the following code, the external interrupt is detected when the TA0CCR0 assignment is commented out. With the line included, the external interrupt is not recognized. Thanks again. int TESTPIN1 = P1_5; int state = LOW; void setup() { // put your setup code here, to run once: pinMode(P1_6,OUTPUT); // step motor clock output pinMode(GREEN_LED,OUTPUT); digitalWrite(GREEN_LED, state); pinMode(TESTPIN1, INPUT_PULLUP); // Configuration word // Bits 15-10: Unused // Bits 9-8: Clock source select: set to SMCLK (16MHz) // Bits 7-6: Input divider: set to 1 // Bits 5-4: Mode control: Count up to TACCRO and reset // Bit 3: Unused // Bits 2: TACLR : set to initially clear timer system // Bit 1: Enable interrupts from TA0 // Bit 0: Interrupt (pending) flag : set to zero (initially) TA0CTL=0b0000001000010010; TA0CCR0=1200; // Set TACCR0 = 2000 to generate a 1ms timebase @ 16MHz with a divisor of 8 TA0CCTL0=BIT4; // Enable interrupts when TAR = TACCR0 attachInterrupt(digitalPinToInterrupt(TESTPIN1), TestISR, CHANGE); } void loop() { // put your main code here, to run repeatedly: } #pragma vector=TIMER0_A0_VECTOR __interrupt void timerA0ISR(void) { // Timer A0 Interrupt service routine static int msCount=0;// Count milliseconds to allow a 1 second pulse static int state=0; // Remember state for toggling purposes msCount++; if (msCount >= 18) { msCount = 0; digitalWrite(P1_6,state); // Write stepper output state=~state; // toggle state } } void TestISR() { state = !state; digitalWrite(GREEN_LED, state); }
  4. I'm trying to create a toggle button but the code is not working. The code is as shown below: #include <msp430g2553.h> int main(void) { WDTCTL = WDTPW + WDTHOLD; // stop watchdog timer P1DIR &= ~BIT3; //P1.3 i/p P1REN |= BIT3; //P1.3 enable pullup resistor P1IES |= BIT3; //P1.3 high to low transition P1IFG &= ~BIT3; //P1.3 clear interrupt flag P1IE |= BIT3; //enable P1.3 interrupt P1DIR |= BIT0; //P1.0 o/p P1OUT &= ~BIT0; //clear P1.0 _BIS_SR(LPM0_bits + GIE); //enter LPM0 with interrupts enabled } #pragma vector = PORT1_VECTOR __interrupt void Port1(void) { P1IFG &= ~BIT3; //clear P1IFG P1OUT ^= BIT0; //toggle LED at P1.0 } Please let me know why it is not working. I am using MS430G2553 launchpad kit. Thanks!
  5. Greetings, I have a project idea to control SCRs connected to three phase electric heater. I need to know which phase is behind and which phase is ahead with respect to selected/chosen phase. IMO, three pins with interrupts attached to them may satisfy the need. Each interrupt will be driven/triggered by seperate zero crossing circuits. After deciding which phase leading which one lagging, I may be capable to fire the SCRs at desired angles. Could someone tell me which msp430gXYZ chip is suitable for the job and has available (more than one) interrupt pins? I am a mechanical engineer by education. So, feel free to criticise my approach with terms of electrics discipline. Murat
  6. I need a one example of timer interrupt like timerone.h for arduino, yhank you, for help me!!!
  7. MSP Launchpad Exp430G2 with Exp430G2553 Rev 1.5 Energia 1.6.10E18 MacOS Sierra 10.12.6 Hello friends, When I call attachInterrupt at the end of a service Routine after I detached it from a pin, I find that it takes a long time for that call to finish (two seconds). Do you have any hint how I can make that faster? Thanks
  8. MSP Launchpad Exp430G2 with Exp430G2553 Rev 1.5 Energia 1.6.10E18 MacOS Sierra 10.12.6 Hello friends, Is it possible to use the functions "attachInterrupt" or "Interrupts" inside an Interrupt Service Routine? For me, it doesn't seem to work. I made a little example: I have to pins with momentary switches attached to them. One is externally configured with a PullUp-Resistor, and the other is externally configured with a PullDown-Resistor. Both switches should be attached to another ISR. But I need to turn off the ISR that is not used, if one ISR is entered, because in both ISR's I need to listen for both switches. I can successfully detach the remaining ISR from the other pin when I enter one ISR, but when I try to re-attach it to the other pin at the end of the ISR with attachInterrupt oder with the combination "noInterrupts" and "interrupts" , the program crashes or stops for at least 3 seconds. volatile int switchPin = P2_3; volatile int espPin = P2_6; volatile int ledPin = P2_7; void ToggleFast(volatile int pinu) { volatile unsigned long n = 100000; digitalWrite(pinu,HIGH); do{n--;} while(n>0); digitalWrite(pinu,LOW); n = 100000; do{n--;} while(n>0); digitalWrite(pinu,HIGH); n = 100000; do{n--;} while(n>0); digitalWrite(pinu,LOW); n = 100000; do{n--;} while(n>0); } void setup() { pinMode(ledPin, OUTPUT); attachInterrupt(switchPin, myISR, FALLING); attachInterrupt(espPin, myISR2, RISING); } void loop() { //toggle slow digitalWrite(ledPin, LOW); delay(400); digitalWrite(ledPin, HIGH); delay(400); } void myISR() { detachInterrupt(espPin); ToggleFast(ledPin); // if I uncomment this, the program crashes or stops for at least 3 seconds. . It is the same when using "noInterrupts" and "interrupts" //attachInterrupt(espPin, myISR2, RISING); } void myISR2() { ToggleFast(ledPin); ToggleFast(ledPin); ToggleFast(ledPin); ToggleFast(ledPin); }
  9. I am trying to read a .wav file from sd card and play it using I2S on CC3200 audio booster in Energia. I have modified the Wifi audio example of CC3200 sdk for this. The dma is setup in ping pong mode and sd card loads data into the buffer but the tx dma interrupt fires only once in primary mode and once in alternate mode. I could not understand why its firing only once. I have configured I2S in stereo mode with 16KHz sampling frequency and 16 bit size. This is my tx dma handler .
  10. Hello all, Im using the MSP430 connecting to a device which outputs 4 bits sequence (parallel) every once in a while and I want to get an interrupt for each new input sequence in port 1. The input sequence voltage level is 3.6V and the MSP powered from the micro-USB (connected to the PC). I also connected the GND of the device to the GND of the MSP. this is my code : void setup(){ Serial.begin(9600); pinMode(P1_2,INPUT); pinMode(P1_3,INPUT); pinMode(P1_4,INPUT); pinMode(P1_5,INPUT); attachInterrupt(P1,intFunc,CHANGE); }; void intFunc(){ Serial.print("this is an interrupt - the value of P3.1 is :"); Serial.println(digitalRead(P1_3)); } void loop() { delay(2000); Serial.println("the is the main routine"); }
  11. Hello all, Im using the MSP430 connecting to a device which outputs 4 bits sequence (parallel) every once in a while and I want to get an interrupt for each new input sequence in port 1. The input sequence voltage level is 3.6V and the MSP powered from the micro-USB (connected to the PC). I also connected the GND of the device to the GND of the MSP. this is my code : void setup(){ Serial.begin(9600); pinMode(P1_2,INPUT); pinMode(P1_3,INPUT); pinMode(P1_4,INPUT); pinMode(P1_5,INPUT); attachInterrupt(P1,intFunc,CHANGE); }; void intFunc(){ Serial.print("this is an interrupt - the value of P3.1 is :"); Serial.println(digitalRead(P1_3)); } void loop() { delay(2000); Serial.println("the is the main routine"); }
  12. Hi, How can I use UART interrupt in Energia? I tried but could not find any example or sample work.
  13. Hello! I recently started playing with Energia and the CC3200 LaunchPad. I tried the example for "attachInterrupt" in the link: http://energia.nu/reference/attachinterrupt/ I changed the code a little by modifying pinMode and attachIntterrupt #define PUSH 4 ... pinMode(PUSH, INPUT); // I want Pin 4 as my interrupt or SW3 on the board, only Input because the board has a pull down resistor already attachInterrupt(PUSH, blink, FALLING); } void loop() { ... } When I run this example, the interrupt is serviced multiple times at random without me touching the button. I wanted to know if anybody else has encountered the same problem or could someone try it and let me know if the interrupt works for them? I'm not sure what I'm doing wrong. Any advice is welcomed! Thank You!
  14. Hello, I have a problem with strange behavior of gcc compiler, which does not seem to generate interrupt vectors correctly. I tried to search for hints on the forum, but could not find any helpful information. I have the following C code: void __attribute__((interrupt(TIMER0_A0_VECTOR))) timer0_isr(void) { //IMPORTANT !!!!!!! //Clear TAIV by reading it !!!! (void) TAIV; /* ... */ } void __attribute__((interrupt(TIMER0_A1_VECTOR))) timer0_a1_isr(void) { P1OUT ^= PIN0; } volatile int qq; __attribute__((interrupt(USCIAB0TX_VECTOR))) void usci_tx_isr(void) { qq=1; P1OUT ^= PIN6; IFG2 &= ~UCA0TXIFG; } __attribute__((interrupt(USCIAB0RX_VECTOR))) void usci_rx_isr(void) { qq=2; P1OUT ^= PIN6; if(IFG2 & UCA0RXIFG) { (void) UCA0RXBUF; } IFG2 &= ~UCA0RXIFG; } Only the TIMER0_A0_VECTOR ISR contains meaningful code at the moment, and the other 3 procedures are just placeholders. For some strange reason, the only ISRs which are linked in the executable code to the interrupt vector table are TIMER0_A0_VECTOR and TIMER0_A1_VECTOR: Disassembly of section .vectors: 0000ffe0 <__ivtbl_16>: ffe0: 6c c1 bic.b @r1, r12 ffe2: 6c c1 bic.b @r1, r12 ffe4: 6c c1 bic.b @r1, r12 ffe6: 6c c1 bic.b @r1, r12 ffe8: 6c c1 bic.b @r1, r12 ffea: 6c c1 bic.b @r1, r12 ffec: 78 c4 bic.b @r4+, r8 ffee: 8e c4 6e c4 bic r4, -15250(r14);0xc46e(r14) fff2: b8 c3 6c c1 bic #-1, -16020(r8);r3 As==11, 0xc16c(r8) fff6: 6c c1 bic.b @r1, r12 fff8: 6c c1 bic.b @r1, r12 fffa: 6c c1 bic.b @r1, r12 fffc: 6c c1 bic.b @r1, r12 fffe: 00 c0 bic r0, r0 I must be doing something wrong, but I can't find where is the mistake. Target CPU is MSP430G5553, and here is the information about the compiler: $ ~/.platformio/packages/toolchain-timsp430/bin/msp430-g++ -v Using built-in specs. Reading specs from ~/.platformio/packages/toolchain-timsp430/bin/../lib/gcc/msp430/4.6.3/../../../../msp430/lib/msp430mcu.spec COLLECT_GCC=~/.platformio/packages/toolchain-timsp430/bin/msp430-g++ COLLECT_LTO_WRAPPER=~/.platformio/packages/toolchain-timsp430/bin/../libexec/gcc/msp430/4.6.3/lto-wrapper Target: msp430 Configured with: ../../gcc/configure --enable-languages=c,c++ --disable-nls --target=msp430 --prefix=/home/robertinant/opt/mspgcc_energia --with-pkgversion='MSPGCC 20120406 (With patches: sf3540953 sf3559978)' Thread model: single gcc version 4.6.3 20120301 (mspgcc LTS 20120406 unpatched) (MSPGCC 20120406 (With patches: sf3540953 sf3559978)) Has anybody encountered similar problems? EDIT: Moving void before __attribute__ has no effect.
  15. Hey all! Finicky issue, and I've been up for way too many hours so I'm breaking from usual habit and posting after only doing minimal digging. Hopefully it's a simple solution. Fingers crossed. Board: TM4C1294NCPDT IDE: CCSv6.1 OS: Ubuntu 16.04 Compiler: GNU v4.9.3 (Linaro) So here's what's up: I'm versed using timers and setting up my vector table properly, or so I thought. Code Composer Studio isn't finding my interrupt handler... It's confuzzling me to say the least... Here's what I'm doing: In startup_gcc.c //......Skipping top of file for readability, all is stock // External declarations for the interrupt handlers used by the application. extern void Timer1AIntHandler(void); //......Skipping a bunch of nonsense for readabilities sake //Beginning of vector table (NOT Blizzard, but Snowflake/RA0) #else __attribute__ ((section(".isr_vector"))) void (* const g_pfnVectors[])(void) = { (void *)&_estack, // The initial stack pointer ResetISR, // The reset handler NmiSR, // The NMI handler FaultISR, // The hard fault handler IntDefaultHandler, // The MPU fault handler IntDefaultHandler, // The bus fault handler IntDefaultHandler, // The usage fault handler 0, // Reserved 0, // Reserved 0, // Reserved 0, // Reserved IntDefaultHandler, // SVCall handler IntDefaultHandler, // Debug monitor handler 0, // Reserved IntDefaultHandler, // The PendSV handler SysTickIntHandler, // The SysTick handler GPIOAIntHandler, // GPIO Port A GPIOBIntHandler, // GPIO Port B GPIOCIntHandler, // GPIO Port C GPIODIntHandler, // GPIO Port D GPIOEIntHandler, // GPIO Port E UARTStdioIntHandler, // For UARTStdio - UART0 Rx and Tx UARTIntHandler1, // UART1 Rx and Tx IntDefaultHandler, // SSI0 Rx and Tx IntDefaultHandler, // I2C0 Master and Slave IntDefaultHandler, // PWM Fault IntDefaultHandler, // PWM Generator 0 IntDefaultHandler, // PWM Generator 1 IntDefaultHandler, // PWM Generator 2 IntDefaultHandler, // Quadrature Encoder 0 ADC0IntHandler, // ADC Sequence 0 IntDefaultHandler, // ADC Sequence 1 IntDefaultHandler, // ADC Sequence 2 IntDefaultHandler, // ADC Sequence 3 IntDefaultHandler, // Watchdog timer IntDefaultHandler, // Timer 0 subtimer A IntDefaultHandler, // Timer 0 subtimer B Timer1AIntHandler, // Timer 1 subtimer A (Thar she blows...) And then in my main project file: // Only showing relevant pieces... // // Prototypes // ========== // Bunch of skipped out-of-scope stuff... void init_Timer(void); void Timer1AIntHandler(void); void init_Timer(void) { // Enable interrupts to the processor. ROM_IntMasterEnable(); // Enable Timer Peripheral ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); // Configure Timer1 to be Periodic, with a 100Hz interrupt ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, g_ui32SysClock / 100); // Setup the interrupts for Timer1 timeout. ROM_IntEnable(INT_TIMER1A); ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); // Enable Timer1A. ROM_TimerEnable(TIMER1_BASE, TIMER_A); } // void loop() is there somewhere, but it's HUGE, doesn't use the timer anyway. void Timer1AIntHandler(void) { // Clear the timer interrupt. ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); // Call the FatFs tick timer. disk_timerproc(); } I need the timer for FatFS by ChaN. CCS gives me this on building (skipped everything until the linker output): Sooo what's going on here? Does the Energia part of CCS do something different with the timer section of the vector table? I have a custom ADC0IntHandler which works just fine... If anyone needs more info, I'm more than glad to provide it. Frustrations abound, and it especially sucks 'cuz after a 20 hour coding marathon, a problem like this is just... Awful.
  16. I need to configure a MMA8653FCR1 accelerometer to cause an interrupt when a certain level of movement is detected. I was looking at the datasheet for it and there was a ton of minutia. Just wondering if somebody has already implemented a library for this device for use with Energia. If you know where I might find some source code for this, I'd greatly appreciate it. Before I get too many flames, I have searched google and the forums for this, but I am unable to find a satisfactory solution. Any assistance here would be greatly appreciated.
  17. Hello Everyone, I am working with the MSP432 launchpad in Energia and I can't seem to use digitalRead() in and ISR? I'm hoping that someone can give me some indication as to why or find the bug in my code This is for a rotary encoder and the interrupts must fire on both Rising and Falling Edges. This Is why I try to determine the state of the pin that was just interrupted. The ISR's will be a bit more complex for the actual encoding but first I need to be able to read the state of the pins. Thanks Guys! const int encoder0PinA = 11; const int encoder0PinB = 31; volatile int pinACount = 0; volatile int pinBCount = 0; volatile bool Aflag = false; volatile bool Bflag = false; /////////////////////////////////////////////////////////////////////////////////// ////////////////////////////// S E T U P ////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// void setup(){ Serial.begin(9600); Serial.println("COUNTER STARTING UP"); pinMode(11,INPUT); pinMode(31,INPUT); attachInterrupt(encoder0PinA, doEncoderA, CHANGE); attachInterrupt(encoder0PinB, doEncoderB, CHANGE); } /////////////////////////////////////////////////////////////////////////////////// //////////////////////////////// L O O P ////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// void loop(){ // SANITY CHECK Serial.println(digitalRead(11)); // Here to see that the pin does change states Serial.println(digitalRead(31)); // Here to see that the pin does change states Serial.print("A Flag: "); Serial.print(Aflag); // I never see either of these get set to 1. Serial.print(" B Flag: "); Serial.println(Bflag); ; Serial.println(); delay(500); } void doEncoderA(){ Aflag = digitalRead(encoder0PinA); } void doEncoderB(){ Bflag = digitalRead(encoder0PinB); }
  18. Hy, I worked on a source half a year ago with an older Energia (I do not know exactly which one.). I was able to acces UartIntHandler and UartIntHandler2() functions directly. As I remember I do not change the content of Energia under OSX. Now I try to modify 1-2 things for example in the startup_gcc.c or hardwareserial.c, but the are not working. Can you help me how could I reach the UART interrupt handlers from Energia? (The setup of UART module worked on CCS or IAR before.) Can I use something like attachinterrupt()?
  19. Hi , I have written my scheduler which uses the Timer0 subtimer A to generate interrupt for Multi-tasking. I have tested the waverforms generating accurately and arriving at the right time periods. Now the issue that I am facing is PWM waves are not arrived at the expected time. Is PWM interfere with the Timer functionality? What is the work around? Are there any free timers available which I can use it for my scheduler? Some insights to this would really help. Thanks, Peeyush
  20. Hi, I wonder if it is possible to cause a interrupt when receiving serial data. This would have the big advantage to be able to wake up from sleep mode if new serial data is available. By now, serial data is written in the rx buffer even in sleep mode, but afaik it's not possible to notice that in Energia. I found lots of code for CCS for exactly this application, but i'm not able to port it for Energia. Does anybody already has some example code or may help me to make the CCS code working in Energia? Thanks!
  21. Hello! So I'm building a robot that is eventually supposed to implement an autonomous functionality, which means obstacle avoidance. I'll be using the HC-SR04 as the ultrasonic sensor of choice. I started out by verifying that the sensor works by running it using Energia, which is the standard "loop infinitely and take a measurement every so many microseconds". In my actual application, however, I want to send out a pulse on command. So when I say so, the ultrasonic will do a measurement (or an average of a few measurements) to tell me if an object is in the path of my robot or not. My actual code is a combination of C (my main function) and a modification of the original Energia project I started with, whose functionality I call from my main application. In my application I'm using uart interrupts on both A0 and A1, and when a certain character is received by A1 I want to access the ultrasonic sensor and take a reading to see if there is an object in the way of my robot or not. There are a few issues that I've been having. The first is that the micros() function doesn't work, so I've taken to making my own delays by using a volatile integer and burning clock cycles that way. The main issue that I'm having (and the reason for this post) is that no matter what I do, the pulseIn() does not work properly. I've pasted the relevant code below. Note that the sensors.cpp file was originally made in Energia, then imported into code composer so that it could be integrated with the main.c file. So this is how my code works. In main.c, U1 will receive an 'I' as an interrupt. In this case, I will call the function fwd(). In the fwd() function, I call the function detectUltraFwd(), which is in sensors.cpp. (It's labeled fwd because later there will be a second ultrasonic sensor for the reverse direction). detectUltraFwd() calls detectUltrasonic(int trig, int echo), where "trig" and "echo" are the specific pins where the ultrasonic sensor is connected to the msp. (Note again, this file came from Energia, so it's a little different than a standard code composer c file). The problem arrives at the line with the pulseIn() function, which was taken from Arduino. According to the function, 0 is returned when there was no measured pulse within the specified timeout. I've tried timeout values varying from 100us to 1s, the maximum value for the function, to no avail. This function always returns 0 and I don't know why. I'm not sure if it's even possible to take a single sample using an ultrasonic sensor. I've tried having the detectUltrasonic() function loop a few times in case just the initial reading was zero, but that wasn't it. The conclusion that I've come to is that it has something to do with micros() not working. Since I'm using interrupts, calling micros() will return 0. (Which is why I'm using the volatile integers to pass time. And yes, I am well aware that I need to play around with the timing to get it close enough to the values I want.) So maybe it's possible that I just don't have my loops timed right, but I ran the original Energia infinite loop code using my made up senswait() function and it worked, so I don't think that's the case. Any insight / help with this matter would be appreciated. My initial searches did not show a resolution to this issue. main.c: #include <msp430.h> #include <string.h> #include <stdlib.h> #include "motors.h" // my file used for motor control #include "sensors.h" // my file used for sensor control int sensingDist=46; //cm int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT // initialize A0 uart for communication P3SEL = BIT3+BIT4; // P3.4,5 = USCI_A0 TXD/RXD UCA0CTL1 |= UCSWRST; // **Put state machine in reset** UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 = 9; // 1MHz 115200 (see User's Guide) UCA0BR1 = 0; // 1MHz 115200 UCA0MCTL |= UCBRS_1 + UCBRF_0; // Modln UCBRSx=0, UCBRFx=0, over sampling UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt // initialize A1 uart for communication P4SEL |= BIT4+BIT5; // P4.4,5 = USCI_A1 TXD/RXD UCA1CTL1 |= UCSWRST; // **Put state machine in reset** UCA1CTL1 |= UCSSEL_2; // SMCLK UCA1BR0 = 9; // 1MHz 115200 (see User's Guide) UCA1BR1 = 0; // 1MHz 115200 UCA1MCTL |= UCBRS_1 + UCBRF_0; // Modln UCBRSx=0, UCBRFx=0, UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine** UCA1IE |= UCRXIE; // Enable USCI_A1 RX interrupt // Set the pinout for the motor controller. setup(); // see motors.h P1DIR |= 0x01; // set blue led as output 1.0 P4DIR |= 0x80; // set green led as output 4.7 P4OUT |= 0x80; // turn on green led P1OUT &= ~0x01; // turn off blue led __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled __no_operation(); // For debugger } // lots of irrelevant code was removed, including the A0 interrupt. // USCI_A1 interrupt -- bluetooth module (or terminal if debugging) #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCI_A1_VECTOR __interrupt void USCI_A1_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void) #else #error Compiler not supported! #endif { switch(UCA1IV) { case 0:break; // no interrupt case 2: // RXIFG - received a character! if('I' == UCA1RXBUF) { // Move forward fwd(); } break; case 4: break; // TXIFG - sending a character default: break; } } void fwd() { // Check to see if there's an object in the way int dist = detectUltraFwd(); if(dist > sensingDist) // if the returned distance is greater than sensingDist, we can freely move forward. { forward(rotateSpeedFB, rotateLengthFB); // see motors.h - tells the robot to move forward. } else // otherwise the ultrasonic sensor has detected an object in the way. blink the blue led a couple times as an indication. { toggleBlue(); volatile int c = 0; for(c=0; c<10000; c++); toggleBlue(); for(c=0; c<10000; c++); toggleBlue(); for(c=0; c<10000; c++); toggleBlue(); for(c=0; c<10000; c++); toggleBlue(); } } sensors.cpp #include "Energia.h" #include "sensors.h" const int ultraTrigFwd = P3_5; const int ultraEchoFwd = P3_6; int detectUltraFwd() { return detectUltrasonic(ultraTrigFwd, ultraEchoFwd); } //ultrasonic function int detectUltrasonic(int trig, int echo) { long duration, cm; // set pin as output pinMode(trig, OUTPUT); // set it low & wait 2us - in order to get a clean signal. digitalWrite(trig, LOW); senswait(3); // Then set it high for 5 us - i.e. begin taking the measurement. digitalWrite(trig, HIGH); senswait(10); digitalWrite(trig, LOW); // now stop taking the measurement //setting up input pin, and receiving the duration in microseconds pinMode(echo, INPUT); duration = pulseIn(echo, HIGH, 1000); // *** THIS RIGHT HERE ALWAYS RETURNS ZERO *** cm = microSecondsToCentimeter(duration); return cm; } long microSecondsToCentimeter(long microseconds) { //The speed of sound is 340 m/s or 29 microseconds per centimeter. //Convert speed return microseconds/29/2; } // This function is being used since micros() will always return zero. So I'm burning clock cycles this way. void senswait(int delay) { for(int i=0; i<delay; i++) { volatile unsigned int x; x = 5000; do x--; while(x !=0); } } If there are small issues like a missing function declaration or header or something, it's because I've had to remove the rest of my project that was irrelevant to my question; my entire code does compile and run! Last notes: the puleIn() function comes directly from Energia. My suspicion is that is somehow is using time, though I did take a look at it and between the bitmasks and counting I didn't see an explicit call to micros() but I'm not sure. All I know is that pulseIn() always returns zero even when I know it shouldn't be. Also if I've violated some rule or completely missed another forum post that's relevant please nudge me in the right direction. And thanks in advance for any help!
  22. Hi I am using tm4c123gh6pz UART. I am getting Interrupt but while I enable FIFO and try to get interrupt using following command, UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8); for the Receive, I get interrupt after 2 byte. I think Receive FIFO is 12 bit x 16 FIFO. To get interrupt after each byte I have to disable the FIFO. Is there any other way to keep the FIFO and get interrrupt after each Byte. Please let me know Thanks
  23. Hey all, I've run into a peculiar problem where my main loop doesn't execute. I know my interrupt routine is executing because I can uncomment the led toggle and I can see it blink. From what I've researched thus far, I believe the issue might be that the ISR is starving the main loop from ever executing. If that is the case, I'm not sure what the solution would be. The reason I have my main loop set up this way is because I am going to need different functions executing at different intervals. I'm still fairly new to MSP430 development, so any help will be appreciated! #include <msp430g2553.h> #define MS_TIME 1000 volatile unsigned int s_cnt = 0; unsigned int last_cnt = 0; int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR |= BIT0 + BIT6; // P1.0 and P1.6 are the red+green LEDs P1OUT &= ~(BIT0 + BIT6); // Both LEDs off TA0CCTL0 = CCIE; // Enable Timer A0 interrupts TA0CCR0 = 22; // Count limit TA0CTL = TASSEL_1 + MC_1; // Timer A0 with ACLK, count UP _BIS_SR(LPM0_bits + GIE); // Enable interrupts while(1) { if (last_cnt != s_cnt) { last_cnt = s_cnt; if (last_cnt == MS_TIME) { P1OUT ^= BIT6; // Toggle green LED s_cnt = 0; } } } } #pragma vector=TIMER0_A0_VECTOR // Timer0 A0 interrupt service routine __interrupt void Timer0_A0 (void) { s_cnt++; //P1OUT ^= BIT6; }
  24. Sorry if this has been asked and answered before, but the results from searches didn't explain the reason not working on my device and code.. Basically trying to do a very simple debounce in an interrupt for an Energia code sketch that paint a 1602 LCD: const int buttonPin = PUSH1; // the number of the pushbutton pin int buttonState; // the current reading from the input pin volatile int lastButtonState = LOW; // the previous reading from the input pin volatile long lastDebounceTime = 0; // the last time the output pin was toggled volatile long debounceDelay = 500; // the debounce time; increase if the output flickers void setup() { ... pinMode(buttonPin, INPUT_PULLUP); attachInterrupt(buttonPin, switchDisplayMode, FALLING); } ... void switchDisplayMode() { int reading = digitalRead(buttonPin); if (reading != lastButtonState) { // reset the debouncing timer lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: buttonState = reading; // start displayMode++; if (displayMode > 5) { displayMode = 0; } // delayMicroseconds(6000000); refreshDisplay(); // end lastButtonState = reading; } } In the above code, debounce did not work all the times, like 3 in 5 times it seem to work, the rest are not. The displayMode variable incremented twice for each button clicked event. The target device is F5529 LP. I have tried the delayMicroseconds which I believed to be irrelevant to the debounce logic if implemented correctly, but that doesn't seem to do the trick either.. Am I doing it wrongly? Any advice will be much appreciated. Thanks in advance.
  25. Hardware: MSP430F5529 Launchpad, CC3000 Boosterpack. Hi, im running a webduino port on the Launchpad and connected a chip (cannot disclose which chip), which requires software spi since it doesnt have a CS pin, to the launchpad. P2.5 is connected to the Data Ready Pin / Data Out pin of the chip. P2.4 to SCLK of the Chip When Data is available, the chip signals with a falling edge on Data Ready Pin, i attached an interrupt to that pin - attachInterrupt(dataReadyPin,readChip,FALLING); The interrupt gets invoked about ten times a second and when continously polling a webpage (small xml document with the chip readings, about every 500ms) the main loop hangs after a while (about 2-5 minutes). My interrupt is still running, i'm toggling the red_led in the interrupt routine and its still blinking. The CC3000 responds to pings. So i suspect there is some problem with the communication of the Launchpad with the CC3000. After rewiring the DataReadyPin to P1.5, and therefore attaching the interrupt to port 1, everything works fine, the server is running for an hour without problems now. So i suspect there is a problem in either the energia code for the interrupts or the SimpleLinkWifi interrupt handler since the CC3000 IRQpin is connected to P2.0. best regards, Nick
  • Create New...