Sillycrackers 0 Posted March 3, 2013 Share Posted March 3, 2013 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;} Quote Link to post Share on other sites
ToF 0 Posted March 4, 2013 Share Posted March 4, 2013 Don't know if it helps, but http://homepages.ius.edu/RWISMAN/C335/HTML/msp430Interrupts.HTM says:The ADC ISR is unusual in requiring the CPU core to be turned On by clearing (setting to 0) the CPUOFF bit. While its not quite clear why it is necessary, failure to do so results in no further executions of the ADC ISR. _BIC_SR(CPUOFF); // Clear CPUOFF bit to re-enable CPU interrupt Quote Link to post Share on other sites
jsolarski 94 Posted March 5, 2013 Share Posted March 5, 2013 in his code the CPU is never turned off. Quote Link to post Share on other sites
Joule 0 Posted March 7, 2013 Share Posted March 7, 2013 I got the code to work by incorporating the suggestions of ToF above and Rick Nardone at e2e http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/249231.aspx #include <msp430g2452.h>void initAdc();volatile int flag = 0;volatile unsigned int cnt = 0;/////changed char var to int var becausevolatile unsigned int cntInterrupt = 0;/////debugger showed period '.' for charint main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P1DIR |= BIT6; P1OUT &= ~BIT6; initAdc(); __bis_SR_register(GIE); while(1){ ADC10CTL0 &= ~ENC; ///// You need to do this, but not sure why while (ADC10CTL1 & BUSY); ///// Wait if ADC10 core is active cnt++; ///// To use debugger to see how many times in loop ADC10SA = 0x200; ///// Need Data buffer start ADC10CTL0 |= ENC + ADC10SC; ///// Sampling and conversion start __bis_SR_register(CPUOFF + GIE); ///// LPM0, ADC10_ISR will force exit 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 transfers in each block ADC10AE0 |= 0x01; //Enables the corresponding pins for analog inputs}#pragma vector=ADC10_VECTOR__interrupt void ADC10_ISR(void) { flag = 1; cntInterrupt++; __bic_SR_register_on_exit(CPUOFF); ///// Clear CPUOFF bit from 0(SR)} Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.