Part Number: MSP430FR2355
I have a function (see below) and no matter what I try (both timer3 or UCRXIFG checking) I end up in a forever loop that doesn't come back in the RESPONSE section of the state machine....Can anyone tell me what I am missing??.....
#include <msp430.h>
#include <string.h>
#include <stdint.h>
#include "rc.h"
#include "LPRSradio.h"
char* radioReg(char *p) {
char f;
radioStates state;
const char *configAck = "ACK";
char response[10] = {0};
char *pResponse;
uint8_t length;
length = strlen(p);
state = CMD;
pResponse = response;
/*
* categorizing radio commands into 1 of 3 bins
*/
if ((*(p + (length - 2)) == 'T') || (*(p + (length - 3)) == 'N') || (*(p + (length - 3)) == 'L'))
f = 2;
else if (*(p + (length - 1)) == '?')
f = 1;
else
f = 0;
while (state != DONE) {
switch (state) {
case CMD:
tx = T; ack = F;
UCA1TXBUF = (*p);
UCA1IE |= UCTXIE;
__bis_SR_register(LPM3_bits + GIE);
*(p++);
if (*p == '\0') {
UCA1IE &= ~UCTXIE;
if ((f == 2) || (f == 0))
state = ECHO;
else
state = RESPONSE;
}
break;
case ECHO:
tx = F; ack = F;
if (howMany < length)
__bis_SR_register(LPM3_bits + GIE);
else {
howMany = 0;
p = configAck;
pRx = incoming;
state = ACK;
}
break;
case ACK:
tx = T; ack = T;
UCA1TXBUF = (*p);
UCA1IE |= UCTXIE;
__bis_SR_register(LPM3_bits);
*(p++);
if (*p == '\0') {
UCA1IE &= ~UCTXIE;
p = *(configCmd);
if (f == 0) {
state = DONE;
}
else {
state = RESPONSE;
}
/*
* give rx a chance to respond with
* response...longest response is 17 char
* at 19200 baud or 8.85ms + about 3.5ms
* delay after ack = ~12.5ms...timer set
* to wake up after 20ms
*/
// __bis_SR_register(LPM3_bits);
}
break;
case RESPONSE:
tx = F; ack = F;
memset(incoming, 0, 20);
TB3CTL |= MC__UP;
TB3CCTL0 |= CCIE;
if ((!timerExpired)) {//(UCA1IFG & UCRXIFG)
__bis_SR_register(LPM3_bits);
}
else {
pRx = incoming;
howMany = 0;
memcpy (response, incoming, sizeof(incoming));
state = DONE;
}
break;
case DONE:
break;
default : break;
}
}
return pResponse;
}