feldwebel 0 Posted May 8, 2016 Share Posted May 8, 2016 Hello, I am writing a program to use LoRa RN2483 with MSP430G2553 sending to LoRa the readings from some sensors. First I had a temperature sensor DS18B20 (digital reading), the internal temperature from MSP, the internal supply voltage from MSP and the code worked great, the readings we're good and were succesfully sent to LoRa using UART. Now I am trying to add a humidity sensor on P1.4 and a photoresistor on P1.5 ( using a 10k resistor like this: Vcc --- photoresistor -- P1.5 --- 10k resistor --- GND). These sensors are analogue so that I need 2 ADC to read them. I made something like this: void humInit(void) { ADC10CTL1 = INCH_4 + ADC10DIV_3 ; // Channel 4, ADC10CLK/3 ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; // Vcc & Vss as reference, Sample and hold for 64 Clock cycles, ADC on, ADC interrupt enable ADC10AE0 |= BIT4; // ADC input enable P1.4 } int humOut(void) { float value; __delay_cycles(1000); // Wait for ADC Ref to settle ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start while (ADC10CTL1 & BUSY); //waiting for conversion to finish value = ADC10MEM; // Assigns the value held in ADC10MEM t ADC10CTL0&=~ENC; //disable adc conv return (unsigned int)(100-(value/1023 * 100)); } and in the Main() function I have something like this: humInit(); hum = humOut(); where hum is a global variable. The transmission part is something like this: #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCIAB0TX_VECTOR __interrupt void USCI0TX_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(USCIAB0TX_VECTOR))) USCI0TX_ISR (void) #else #error Compiler not supported! #endif { if (f == '1') { UCA0TXBUF = string1[i++]; // TX next character if (i == sizeof string1 - 1) // TX over? { P1OUT|= BIT6; __delay_cycles(5000000); P1OUT&=~BIT6; f = '2'; i = 0; } } if (f == '2') { UCA0TXBUF = string2[i++]; if (i == sizeof string2 - 1) { P1OUT|= BIT6; __delay_cycles(2000000); P1OUT&=~BIT6; f = '3'; i = 0; } } } where f is a flag to know which string to send. The transmission stars in Main() like: i = 0; f = '1'; IE2 |= UCA0TXIE; // Enable USCI_A0 TX interrupt UCA0TXBUF = string1[i++]; The problem is that after I'm adding the ADC for the humidity and read it (the reading is correct) the transmission stops after the first character of the first string. I tried to put a breakpoint in the TX interrupt and it doesn't seem to reach it. It seems that the ADC is somehow affecting the TX interrupt. Any ideas on this ? Thank you. main.c Quote Link to post Share on other sites
cubeberg 540 Posted May 9, 2016 Share Posted May 9, 2016 Do you have a copy of the working code as well? That might help Quote Link to post Share on other sites
feldwebel 0 Posted May 9, 2016 Author Share Posted May 9, 2016 Yes I do have. Also I managed to solve the problem by not using the TX interrupt. I will attach the old working code and the new one (without the interrupt). I am still curious to find out what was the problem. new code.c old working code.c Quote Link to post Share on other sites
cubeberg 540 Posted May 9, 2016 Share Posted May 9, 2016 Think I found at least one problem. Doesn't explain why the interrupt didn't fire, but it would definitely mess up your baud rate.Old working code: UCA0BR0 = 0x11; // 57600 bps - (0x11,0x00,0x52) 9600bps - (0x68,0x00,0x04) Broken code: UCA0BR0 = 0x68; // 57600 bps - (0x11,0x00,0x52) 9600bps - (0x68,0x00,0x04) Fixed code: UCA0BR0 = 0x11; // 57600 bps - (0x11,0x00,0x52) 9600bps - (0x68,0x00,0x04) Quote Link to post Share on other sites
feldwebel 0 Posted May 13, 2016 Author Share Posted May 13, 2016 That is not a problem. I am just modifying the baud rate, when I'm testing it on PC i'm using 9600 (because launchpad is limited at 9600) and when I'm testing it on the full schematic I am using 57600. Quote Link to post Share on other sites
Lyon 3 Posted May 14, 2016 Share Posted May 14, 2016 Hello, I am writing a program to use LoRa RN2483 with MSP430G2553 sending to LoRa the readings from some sensors. First I had a temperature sensor DS18B20 (digital reading), the internal temperature from MSP, the internal supply voltage from MSP and the code worked great, the readings we're good and were succesfully sent to LoRa using UART. Now I am trying to add a humidity sensor on P1.4 and a photoresistor on P1.5 ( using a 10k resistor like this: Vcc --- photoresistor -- P1.5 --- 10k resistor --- GND). These sensors are analogue so that I need 2 ADC to read them. I made something like this: void humInit(void) { ADC10CTL1 = INCH_4 + ADC10DIV_3 ; // Channel 4, ADC10CLK/3 ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; // Vcc & Vss as reference, Sample and hold for 64 Clock cycles, ADC on, ADC interrupt enable ADC10AE0 |= BIT4; // ADC input enable P1.4 } int humOut(void) { float value; __delay_cycles(1000); // Wait for ADC Ref to settle ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start while (ADC10CTL1 & BUSY); //waiting for conversion to finish value = ADC10MEM; // Assigns the value held in ADC10MEM t ADC10CTL0&=~ENC; //disable adc conv return (unsigned int)(100-(value/1023 * 100)); } and in the Main() function I have something like this: humInit(); hum = humOut(); where hum is a global variable. The transmission part is something like this: #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCIAB0TX_VECTOR __interrupt void USCI0TX_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(USCIAB0TX_VECTOR))) USCI0TX_ISR (void) #else #error Compiler not supported! #endif { if (f == '1') { UCA0TXBUF = string1[i++]; // TX next character if (i == sizeof string1 - 1) // TX over? { P1OUT|= BIT6; __delay_cycles(5000000); P1OUT&=~BIT6; f = '2'; i = 0; } } if (f == '2') { UCA0TXBUF = string2[i++]; if (i == sizeof string2 - 1) { P1OUT|= BIT6; __delay_cycles(2000000); P1OUT&=~BIT6; f = '3'; i = 0; } } } where f is a flag to know which string to send. The transmission stars in Main() like: i = 0; f = '1'; IE2 |= UCA0TXIE; // Enable USCI_A0 TX interrupt UCA0TXBUF = string1[i++]; The problem is that after I'm adding the ADC for the humidity and read it (the reading is correct) the transmission stops after the first character of the first string. I tried to put a breakpoint in the TX interrupt and it doesn't seem to reach it. It seems that the ADC is somehow affecting the TX interrupt. Any ideas on this ? Thank you After (f=='2'), f is changed to '3' where there is not any option to process for that. Shouldn't be f=1 again to toggle between the two options? L Quote Link to post Share on other sites
colotron 5 Posted May 14, 2016 Share Posted May 14, 2016 ... The transmission part is something like this: #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCIAB0TX_VECTOR __interrupt void USCI0TX_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(USCIAB0TX_VECTOR))) USCI0TX_ISR (void) #else #error Compiler not supported! #endif { if (f == '1') { UCA0TXBUF = string1[i++]; // TX next character if (i == sizeof string1 - 1) // TX over? { P1OUT|= BIT6; __delay_cycles(5000000); P1OUT&=~BIT6; f = '2'; i = 0; } } if (f == '2') { UCA0TXBUF = string2[i++]; if (i == sizeof string2 - 1) { P1OUT|= BIT6; __delay_cycles(2000000); P1OUT&=~BIT6; f = '3'; i = 0; } } } ... Any ideas on this ? Don't use delay_cycles inside the interrupt. Take that out and check if it works. 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.