| Details | Message |
|---|
Read-Only Author Nantian Gumo Posted 20-Mar-2005 15:14 GMT Toolset C51 |  How to process the data from UART? Nantian Gumo Hi all . In one way ,all the messages is following a standard format ,like:"SOH,MSG ID, CMPL ID,MSG DATA LENGTH, MSG DATA ,CHECKSUM",so this format can be embed in UART_ISR to receive the message wanted.But,if have some different kinds of message which following different formats ,or baudrate is too high to process in the UART_ISR,how can the firmware process these message?Where have any referenced source code ? Thanks for help. |
|
Read-Only Author Hans-Bernhard Broeker Posted 21-Mar-2005 13:21 GMT Toolset C51 |  RE: How to process the data from UART? Hans-Bernhard Broeker It's quite certainly not a good idea to do any processing like the one you're talking about inside the ISR. Let the main code deal with it. All the ISR can usefully do is receive the data, a byte at a time, and push it into a circular buffer of adequate size. The main code will pull it out of that, and do whatever needs being done. |
|
Read-Only Author A.W. Neil Posted 21-Mar-2005 13:31 GMT Toolset C51 |  RE: How to process the data from UART? A.W. Neil "All the ISR can usefully do is receive the data, a byte at a time, and push it into a circular buffer of adequate size. The main code will pull it out of that, and do whatever needs being done."
Absolutely. Look at the interrupt-driven serial IO sample code on this very site.
I've used it almost straight from the can to do exactly the kind of thing you're talking about. |
|
Read-Only Author Nantian Gumo Posted 24-Mar-2005 14:43 GMT Toolset C51 |  RE: How to process the data from UART? Nantian Gumo I have tried my best ,but couldn't find the code example what you said.Can you tell me which site they are? Thanks a lot! |
|
Read-Only Author A.W. Neil Posted 24-Mar-2005 15:02 GMT Toolset C51 |  RE: How to process the data from UART? A.W. Neil Click 'Support' in the blue bar across the top of this screen
Click 'Download Files'
Click 'C51 Downloas Files'
Look for "Interrupt-Driven Serial I/O" (Hint: use your browser's 'Search' facility) |
|
Read-Only Author Nantian Gumo Posted 26-Mar-2005 07:28 GMT Toolset C51 |  RE: How to process the data from UART? Nantian Gumo Hi all, when the main_loop's code shown as following is running ,lots of messages in buffer couldn't be detected and lost.can you tell me how to correct it?
Serial ISR: void serial0(void) interrupt 4 { ES0 = 0; if (TI0) TI0 =0; if (RI0) { r_buf[r_in&0x7ff]=SBUF0; RI0 = 0; r_in=r_in+1; } ES0 = 1; } Main_Loop: void main() { ... while(1) { if ((r_in-r_out)>128) { serial0Flag = 1; } if(serial0Flag==1) { if (r_buf[r_out&0x7ff] ==' |
|
)
{
memcpy(sHeadFlag,&r_buf[(r_out+1)&0x7ff],5);
if (memcmp(sHeadFlag,sGpgs[0],5)==0)
{
GpgsvSol(&r_buf[r_out&0x7ff]);
}
if (memcmp(sHeadFlag,sGpgs[1],5)==0)
{
GpgsaSol(&r_buf[r_out&0x7ff]);
atelliteLocked=Gpgsa.cSatInSolTol;
}
}
r_out++;
}
}
} |
Read-Only Author A.W. Neil Posted 26-Mar-2005 07:55 GMT Toolset C51 |  RE: How to process the data from UART? A.W. Neil Your code is illegible because it's lost all its latout/formatting. This is because you didn't follow the instruction about posting code.
Please follow the instructions on how to post code - it's right there immediately above the box where you type your message! http://www.keil.com/forum/tips.asp |
|
Read-Only Author Dan Henry Posted 26-Mar-2005 19:46 GMT Toolset C51 |  RE: How to process the data from UART? Dan Henry Once serial0Flag has been set to 1, your main loop will scan r_buf[] continuously without any synchronization to the incoming data and without checking whether it's looking at old data after wrapping. |
|
Read-Only Author Nantian Gumo Posted 27-Mar-2005 06:49 GMT Toolset C51 |  RE: How to process the data from UART? Nantian Gumo I rewrite the source code as following:
//Serial ISR:
void serial0(void) interrupt 4
{
ES0 = 0;
if (TI0) TI0 =0;
if (RI0)
{
r_buf[r_in&0x7ff]=SBUF0;
RI0 = 0;
r_in=r_in+1;
}
ES0 = 1;
}
//Main_Loop:
void main()
{
...
while(1)
{
if ((r_in-r_out)>128)
{
serial0Flag = 1;
}
if(serial0Flag==1)
{
if (r_buf[r_out&0x7ff] =='
|
|
)
{
memcpy(sHeadFlag,&r_buf[(r_out+1)&0x7ff],5);
if (memcmp(sHeadFlag,sGpgs[0],5)==0)
{
GpgsvSol(&r_buf[r_out&0x7ff]);
}
if (memcmp(sHeadFlag,sGpgs[1],5)==0)
{
GpgsaSol(&r_buf[r_out&0x7ff]);
atelliteLocked=Gpgsa.cSatInSolTol;
}
}
r_out++;
}
}
}
How can i correct it well?
Thanks. |