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.

Found 23 results

  1. 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"); }
  2. 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"); }
  3. Hi, How can I use UART interrupt in Energia? I tried but could not find any example or sample work.
  4. Hello! I recently started playing with Energia and the CC3200 LaunchPad. I tried the example for "attachInterrupt" in the link: 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!
  5. 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.
  6. 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.
  7. 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.
  8. 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); }
  9. 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()?
  10. 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
  11. 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!
  12. 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!
  13. 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
  14. 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; }
  15. 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.
  16. 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
  17. Hello, I am trying to read in two PWM signals from an RC receiver. I have managed to read in one and have got the result I expected. However, I am unable to read in two channels. The interrupt handlers never get called. I have modified the startup.ccs.c file to call the appropriate handler. Here is the configuration code that I am using: //Enable PortB Interrupt SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIOPinConfigure(GPIO_PB0_T2CCP0); GPIOPinConfigure(GPIO_PB1_T2CCP1); GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0); GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_1); TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME | TIMER_CFG_B_CAP_TIME); TimerControlEvent(TIMER2_BASE, TIMER_A, TIMER_EVENT_BOTH_EDGES); TimerControlEvent(TIMER2_BASE, TIMER_B, TIMER_EVENT_BOTH_EDGES); TimerEnable(TIMER2_BASE, TIMER_BOTH); TimerIntClear(TIMER2_BASE, TIMER_CAPA_EVENT | TIMER_CAPB_EVENT); // // Enable interrupts to the processor. // ROM_IntEnable(INT_TIMER2A | INT_TIMER2B); TimerIntEnable(TIMER2_BASE, TIMER_CAPA_EVENT | TIMER_CAPB_EVENT); ROM_IntMasterEnable(); I have put breakpoints at the interrupt handlers and it never reaches them. I had this working with one channel, now expanding to two. Thanks
  18. Hello there, I am doing a project where I have to read in a square wave and determine the frequency of the wave then output that number. I found out that I am using a 1MHz clock, then I set up an interrupt to count the edges for my square wave input. I don't think my interrupt is working though. I even changed it to a push button and tried to get it to turn on led's it didn't work. ps. I'm using energia btw. pps. I'm using msp430 revision 1.5 Hope someone can help me out Thanks a bunch!! if you don't know what energia is is where you can find information My code so far //LED PINS int ledPin0 = 3;// select the pin for the LED int ledPin1 = 4; int ledPin2 = 5; int ledPin3 = 6; int ledPin4 = 8; //Inputs volatile int sensorPin = A7; // select the input pin for the potentiometer //Variables volatile int temp=0; //int count=0; volatile int count1=0; volatile int number=0; void setup() { // declare the ledPin as an OUTPUT: pinMode(ledPin0, OUTPUT); pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(ledPin4, OUTPUT); pinMode(sensorPin, INPUT_PULLUP); //attachInterrupt(analogRead(sensorPin),inter,CHANGE); } void loop() { if (analogRead(sensorPin == HIGH)){ count1 = count1++; } else{ number = count1; count1 =0; } //Check for Frequency //number = 1000000/count1; //Make temp Variable to change temp = number; //Coverts that number to binary //Checks if it need to turn on light 5 if(temp >= 16){ digitalWrite(ledPin4, HIGH); temp = temp - 16; } else{ digitalWrite(ledPin4, LOW); } //Checks for light 4 if(temp >= 8){ digitalWrite(ledPin3, HIGH); temp = temp-8; } else{ digitalWrite(ledPin3, LOW); } //Checks for light 3 if(temp >= 4){ digitalWrite(ledPin2, HIGH); temp = temp - 4; } else{ digitalWrite(ledPin2, LOW); } //Checks for light 2 if(temp >= 2){ digitalWrite(ledPin1, HIGH); } else{ digitalWrite(ledPin1, LOW); } //Checks for light 1 if(temp >= 1){ digitalWrite(ledPin0, HIGH); } else{ digitalWrite(ledPin0, LOW); } delay(5); //count1 =0; } //Interuppt Routine //void inter() //{ //count1=count1++; //}
  19. Hi, sorry I'm attempting to do an interrupt in Energia IDE. with attachInterrupt() but, still given me an error. if you can help me, i will appreciate you.
  20. Hello, I'm a beginner so I think the answer is simple. I have an HC-SR04 connected to 4 AA batteries at 5.4V. The echo from the ultrasonic sensor goes through a voltage divider with 20k and 10k ohm resistors before going into P1.1. My f2013 is being powered by the usb programming tool and is using P1.2 as the out/trigger pin for the hc-sr04. I beleive the sr04 can take a 3.3V trigger. This is my code below, I just can't figure out why my interrupt isn't triggering. I borrowed some code from the internet. I can't remember his username, but the guy with the wall racer with two hc-sr04's. For quick reference: F2013 Datasheet #define LED0 BIT0 #define ECHO BIT1 #define TRIG BIT2 #include <msp430f2013.h> volatile unsigned distance_in_cm=0; volatile unsigned int start_time; volatile unsigned int total_time; volatile unsigned int up=0; void main(void) { //setup ports, cpu speed, timers //send 2 microseconds of off to p1.1 //send 10 microseconds of on to p1.1 //wait 60 microseconds // listen and count time on p1.0 //distance in cm is counted time/58 WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; //set speed to 1 megahertz TACTL = 0; //stop the clock P1DIR = (LED0 + TRIG); // set all of P1.0 P1.2 to output and P1.1 to input P1SEL = ECHO; //select echo pin as input for timerA TACCTL0 |= CM_3 + SCS + CAP + CCIE + CCIS_0; //capture rising and falling edge, syncronize(always do this),capture mode, interrupt enabled TACTL = TASSEL_2 + ID_0 + MC_2; // SMCLK,/1, continuous up mode, clear _BIS_SR(GIE); // general interrupt enable while (1) { volatile unsigned int i = 0; up = 1; //Next catch on Timer1A0 should be rising edge - helps with capture timer P1OUT |= TRIG; //turn trig on _delay_cycles(20); //double the required 10 microseconds for good measure //TODO set to 10 again if possible P1OUT &= ~TRIG; //turn trig off _delay_cycles(60000); //wait 60ms before testing again. the interrupt should happen somewhere here } } #pragma vector=TIMERA0_VECTOR __interrupt void timerA0 (){ if (up){ start_time = TACCR0; } else { total_time = TACCR0 - start_time; distance_in_cm = total_time/58; if (distance_in_cm < 20){ P1OUT |= LED0; } else{ P1OUT &= ~LED0; } } up=!up; //if this was the rising edge, the next one will be a falling edge, and vice-versa TA0CTL &= ~TAIFG; //clear timer A interrupt flag, so the chip knows we handled the interrupt TACCTL0 &= ~CCIFG;//clears capture interrupt flag, should already be done automatically though TODO } /* #define MC_0 (0*0x10u) Timer A mode control: 0 - Stop #define MC_1 (1*0x10u) Timer A mode control: 1 - Up to CCR0 #define MC_2 (2*0x10u) Timer A mode control: 2 - Continous up #define MC_3 (3*0x10u) Timer A mode control: 3 - Up/Down #define ID_0 (0*0x40u) Timer A input divider: 0 - /1 #define ID_1 (1*0x40u) Timer A input divider: 1 - /2 #define ID_2 (2*0x40u) Timer A input divider: 2 - /4 #define ID_3 (3*0x40u) Timer A input divider: 3 - /8 #define TASSEL_0 (0*0x100u) Timer A clock source select: 0 - TACLK #define TASSEL_1 (1*0x100u) Timer A clock source select: 1 - ACLK #define TASSEL_2 (2*0x100u) Timer A clock source select: 2 - SMCLK #define TASSEL_3 (3*0x100u) Timer A clock source select: 3 - INCLK #define CCIS_0 (0*0x1000u) Capture input select: 0 - CCIxA #define CCIS_1 (1*0x1000u) Capture input select: 1 - CCIxB #define CCIS_2 (2*0x1000u) Capture input select: 2 - GND #define CCIS_3 (3*0x1000u) Capture input select: 3 - Vcc #define CM_0 (0*0x4000u) Capture mode: 0 - disabled #define CM_1 (1*0x4000u) Capture mode: 1 - pos. edge #define CM_2 (2*0x4000u) Capture mode: 1 - neg. edge #define CM_3 (3*0x4000u) Capture mode: 1 - both edges */
  21. I'm using Energia with a Launchpad (LM4F120XL), and I've found some strange behavior when using a timer interrupt. When the interrupt setup code is compiled in, functions that do string processing (atoi, strtoul, strtok, etc.) do not return the expected value. In the code below, atoi() will return 0 when given the input "12". Note that the timer interrupt hasn't even been set up at the point where atoi() is called. In particular, it's the call to IntRegister() that causes the problem. The same code will work as expected if IntRegister() is commented out. Also note that everything works fine if an infinite loop is placed immediately before the initTimer() call -- in that case, I'm guessing the compiler is optimizing out everything in initTimer() because it's unreachable. strcmp() was also misbehaving (i.e. returning nonzero values for identical strings), but when I moved the const char* comparison string from global scope to function-level scope, the comparison began working as expected. Anyone have any ideas about this? It seems like it might have something to do with the arrangement of symbols in memory. --Colin #include "inc/hw_ints.h" #include "driverlib/sysctl.h" #include "driverlib/interrupt.h" #include "driverlib/timer.h" void timer0_handler(void) { TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); } void initTimer(unsigned Hz) { SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER); unsigned long ulPeriod = (SysCtlClockGet() / Hz) / 2; TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod - 1); IntEnable(INT_TIMER0A); IntRegister(INT_TIMER0A, timer0_handler); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); IntMasterEnable(); TimerEnable(TIMER0_BASE, TIMER_A); } void setup() { IntMasterDisable(); Serial.begin(9600); } void loop() { const char *dbuf = "12"; Serial.println(atoi(dbuf)); initTimer(3); while (1); }
  22. Hey all, I'm completely stumped on a bug for my design day project. I've got a rotary encoder that is used to change a value on an LCD screen. The code works perfectly when the encoders state at power up is 00. However if either pin is high, it doesn't work at all. Some transitions will cause the value on the screen to move in the wrong direct, and some transitions don't seem to trigger an interrupt at all. This is the code I'm using and would LOVE some help! Is it possible that the MSP430 is recording the initial values as reference voltages causing subsequent interrupts to not work? #pragma vector=PORT2_VECTOR //Port 2 interrupt triggered by either rotary encoder pin __interrupt void Port_2(void) { //int gray0=P2IN&GRAY0; //int gray1=P2IN&GRAY1; if(P2IFG&GRAY0) { (P2IN&GRAY1)? parameter++ : parameter-- ; if(parameter>999) parameter=0; P2IFG&=~GRAY0; } else if(P2IFG&GRAY1) { (P2IN&GRAY0)? parameter++ : parameter-- ; P2IFG&=~GRAY1; if(parameter<0) parameter=999; } inactivity=0; //interaction has been seen, so reset the inactivity counter }
  23. Hi, I am having trouble getting the ADC interrupt working for the msp430g2452. I am simply trying to turn on a flag when the interrupt goes off but it doesn't seem to be working. Code below.... #include <msp430g2452.h> void initAdc(); volatile char flag = 0; int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P1DIR |= BIT6; P1OUT &= ~BIT6; initAdc(); __bis_SR_register(GIE); while(1){ if(flag == 1){ P1OUT |= BIT6; }else{ P1OUT &= ~BIT6; } } return 0; } void initAdc(){ ADC10CTL1 = CONSEQ_2 + ADC10DIV_3; //Channel A0 for conversion, ADC10OSC clock used for sampling, repeat single channel ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE + ADC10SC + ENC; //sample and hold time every 16 clocks, Multiple sample conversion, turn on ADC, enable interrupts for ADC, every 16 clock cycles take a sample ADC10DTC1 |= 0x01; //Number of transers in each block ADC10AE0 |= 0x01; //Enables the corresponding pins for analog inputs } #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { flag = 1; }