Hi JT,Hi C.Code:On High Interrupt Save System If RCSTA.OERR = 1 Then 'BIT1..if over run error then flush RXD buffer If RCSTA.FERR = 1 Then 'BIT2..framing error(can be cleared by reading RCREG register And receiving Next valid Byte) RCSTA.CREN = 0 RCSTA.CREN = 1 'BIT4 ENABLES RECEIVER char = RCREG '1 char = RCREG '2 err = 1 'ERROR Endif Endif
One idea. You test for OERR but then require that FERR is also set before you fix the UART. You are unlikely to get a framing error if your baud rate is correct. In this code, if you get an overrun error without a framing error (likely), you will never get to the required fixup code and the UART will be kaput. You don't need to reset the UART on a framing error, it will still continue to receive characters and generate interrupts (but you have to discard the data). Treat the errors as separate with separate fixes.
A thought for you: Once I get a serial link set up, I never turn it off. I always receive every character sent with the appropriate error checking/recovery. The problem with on and off is that you don't know where you are in the input stream when you turn it back on. Clearly a good error detection / recovery scheme will handle that (as it must when you are powering up or after a uC reset) but I just don't like jumping into a stream mid-character. My solution is to have a flag to indicate when I don't want to process any characters. Receive/error check/recover as normal then check the flag to see if the received character should be processed or discarded. That way, a simple flag turns the data stream on and off. In your case, enabling the data processing would also begin looking for the '$'. Such a scheme also allows you to monitor the presence and integrity (no hardware error flags) of the stream continuously, even if you are not processing the data.
Why have any delays at all? Get a buffer full, parse and process it, use that data then get back to the top and wait for the next buffer full. Mixing real-time processing needs (receiving from a UART with no flow control) with blocking delays is pretty much guaranteed to drive you crazy, especially when you try to get lucky with just-in-time timings. Ask me how I know these things.
While we're at it. Keep in mind that any test you send to the terminal is likely using a blocking delay. Most simple implementations write to TXREG then poll a flag to see when that character has been sent and the UART can take another. At 9600 baud, each character is about 1ms. So saying 'ERROR!' bogs your system down 60ms more or less. Note that the simulator may not take the time to transmit into account but just put the characters up on the window adding to your timing woes between sim and hardware. I don't know how Oshensoft does it but have been bit by that on other systems.
Just my .02
Good luck!
I'm out of my depth, so my answer may seem limited!
1/ Regarding OERR and FERR, as 'J' advised me to [ OR ] them. Does this change your question, and solution?
See attachment:
2/ Regarding 'jumping into a stream' There is a [ If BAUDCON.RCIDL = 1 Then 'Avoid framing error-BIT6 ] to check that there is a character. Again does this change your question and solution (Which for me is too difficult)
3/ Regarding delays: I added some to allow the process, and don't know how to set the length, and I added one so I can watch it in the simulator. I intend to remove them by experiment as I get each section working.
"is pretty much guaranteed to drive you crazy" To late
4/ The last paragraph, and in general, I hoped I could write an INTERRUPT PARSE routine, but it seems I am incapable of it. As too much time and effort has been spent over the years from me and other forum members, on this project, I have to keep trying, till I get some results. It's actually almost working, even though it may be a mess.
Thanks, C.
Attachments
-
960 bytes Views: 9