- Joined
- Jul 4, 2009
- Messages
- 16,572
- Helped
- 5,158
- Reputation
- 10,349
- Reaction score
- 5,226
- Trophy points
- 1,393
- Location
- Aberdyfi, West Wales, UK
- Activity points
- 140,152
This would be my approach:
This should capture everything after a '+' to the end of the line, it clears the buffer at each new line, checks the buffer doesn't overflow and the result in 'GSMbuff' is a terminated string.
Reset 'gsmFlag' when you have processed the string so it is ready for next time.
Brian.
Code:
// adjust this to the length of the longest response + 1
#define BUFFERSIZE 20
// this is the ISR
void __interrupt() ISR(void)
{
if(PIR1bits.RCIF)
{
if(RCSTAbits.OERR)
{
RCSTAbits.CREN = 0;
RCSTAbits.CREN = 1;
}
else
{
ByteReceived = RXREG;
gsmFlag = 1;
}
}
// this is in your main loop
if(gsmFlag)
{
if(ByteReceived == '+') GSMindex = 0; // start of message found
if(ByteReceived == '\n') STAT = !STAT; // or whatever you want to do with the data
else
{
if(GSMindex < BUFFERSIZE)
{
GSMbuff[GSMindex++] = ByteReceived;
GSMbuff[GSMindex] = 0;
}
}
}
Reset 'gsmFlag' when you have processed the string so it is ready for next time.
Brian.