Other Parts Discussed in Thread: MSP-FET
Tool/software: Code Composer Studio
Hello...
I have code where I do some clock, gpio and uart set up functions then a while(1) loop. I have one rx/tx ISR active. I frequently am finding that my code is somehow resetting....If I place one breakpoint before the while loop I run to it then hit run again and after a short period the code will circle out of the while loop and break at that point.....If I remove the TXIE in INITUART I no longer have the issue. I am convinced that somehow one of my pointers is running away and causing grief....Can anyone see anything glaring about how I may be poorly handling pointers to cause grief? In particular the pTx.....
#include <msp430.h>
#include <string.h>
#include <stdint.h>
#include "rc.h"
#include "LPRSradio.h"
volatile char *pRx;
char incoming[20];
const char *pTx;
const char *configCmdAck[3] = {r_RSSIon, r_bandSet, r_USAFCC};
const char *testack = "ACK";
uint8_t i = 0;
boolean tx = T;
int k;
unsigned int r;
boolean redflag = F;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
IOconfig;
initClockTo16MHz();
initUART();
pRx = incoming;
pTx = configCmdAck[0];
__bis_SR_register(LPM3_bits + GIE); //go to sleep: LPM3
while (i<3)
{
__bis_SR_register(LPM3_bits + GIE); //go to sleep: LPM3
if (tx) {
pTx++;
}
else {
if (!strncmp(incoming, configCmdAck[i], strlen(configCmdAck[i])))
{
pTx = testack;
i++;
redflag = T;
}
pRx++; //see note below...Do not put at end of loop!
if (redflag) {
// redflag = F;
/*URGENT: Setting UCTXIFG must be the last line of code. If set earlier we will go into ISR, come out and process the next line of code
* before going back into ISR because TXIFG will get set because of TXBUF going empty...This unfortunate event will promote a double character instance.
* redflag will alert us that we want to go back into ISR...hence prepare everything, create redflag then use it at very end of if statement to generate ISR
* such that when we return we will move to next line of code (ie LPM3 sleep), then TXIFG will wake us at beginning again.
*/
UCA1IFG |= UCTXIFG;
}
}
}
UCA1IE &= ~UCTXIE;
__bis_SR_register(LPM3_bits + GIE);
}
#pragma vector=USCI_A1_VECTOR
__interrupt void M(void)
{
switch(__even_in_range(UCA1IV, USCI_UART_UCTXCPTIFG))
{
case USCI_NONE: break;
case USCI_UART_UCRXIFG:
tx = F;
*pRx = UCA1RXBUF;
__bic_SR_register_on_exit(LPM3_bits);
break;
case USCI_UART_UCTXIFG:
tx = T;
if (*pTx != '\0')
UCA1TXBUF = *pTx;
else {
if (redflag) {
redflag = F;
pRx = incoming;
pTx = configCmdAck[i];
for (r = 0; r<2000; r++); //2000 minimum
UCA1TXBUF = *pTx;
}
}
__bic_SR_register_on_exit(LPM3_bits);
break;
case USCI_UART_UCSTTIFG: break;
case USCI_UART_UCTXCPTIFG: break;
}
}