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.
"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.
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!
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)
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++; } } }
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
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.
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++; } } }