UART Rx stops reading
Posted: Fri Sep 02, 2022 5:29 pm
Hi All,
I wonder if someone could point me in the right direction with this please.
I am using a PIC18F45K42 specifically as it has 2 UART transceivers, I am using UART 1 to talk to a PC on pins C6 and C7 and then the one I am having problems with, UART 2 on pins Tx D2 and Rx D3, to talk to a couple of other PICs via a couple of transistors etc. I have it all working seamlessly most of the time, however I noticed very occasionally it would stop talking and the only way I can get it to work again is to reset the entire PIC. I have an oscilloscope attached to the Tx and Rx and I have noticed that it stops reading the receive at all. There are 2 Tx bytes being sent and instead of waiting for the read byte in between them they just get sent as one lump. I have identified the cause and that is if the Rx pin gets any corruption on it from an external source, eg. a finger to the 0V line!!! I would really like to be able to restart the receive without having to reset the entire thing. It's monitoring some equipment and reporting conditions.
I have read the U2FIFO register and when it's working normally I get a 0x2E or 46 and when it stops I get 0x2D or 45. The difference is 46, Read buffer empty, 45 Read buffer is full. I have tried writing to 0x2E to this register while it's in the fault situation, which the data sheet tends to indicate should clear the read buffer, but although it changes the situation and it looks like it starts reading again, the ReadNumber just brings back 0's. I am not using 0's in my code, so I know this is a comms error. I have tried using the initialise command in the UART component, and that doesn't have any effect at all.
I have very very limited knowledge of C++ hence I use Flowcode. This one has me stumped. The data sheet mentions using MOVWF but this is where my limited knowledge of C let me down.
If there are any ideas, I would be very grateful.
Thanks in advance.
Simon.
I wonder if someone could point me in the right direction with this please.
I am using a PIC18F45K42 specifically as it has 2 UART transceivers, I am using UART 1 to talk to a PC on pins C6 and C7 and then the one I am having problems with, UART 2 on pins Tx D2 and Rx D3, to talk to a couple of other PICs via a couple of transistors etc. I have it all working seamlessly most of the time, however I noticed very occasionally it would stop talking and the only way I can get it to work again is to reset the entire PIC. I have an oscilloscope attached to the Tx and Rx and I have noticed that it stops reading the receive at all. There are 2 Tx bytes being sent and instead of waiting for the read byte in between them they just get sent as one lump. I have identified the cause and that is if the Rx pin gets any corruption on it from an external source, eg. a finger to the 0V line!!! I would really like to be able to restart the receive without having to reset the entire thing. It's monitoring some equipment and reporting conditions.
I have read the U2FIFO register and when it's working normally I get a 0x2E or 46 and when it stops I get 0x2D or 45. The difference is 46, Read buffer empty, 45 Read buffer is full. I have tried writing to 0x2E to this register while it's in the fault situation, which the data sheet tends to indicate should clear the read buffer, but although it changes the situation and it looks like it starts reading again, the ReadNumber just brings back 0's. I am not using 0's in my code, so I know this is a comms error. I have tried using the initialise command in the UART component, and that doesn't have any effect at all.
I have very very limited knowledge of C++ hence I use Flowcode. This one has me stumped. The data sheet mentions using MOVWF but this is where my limited knowledge of C let me down.
If there are any ideas, I would be very grateful.
Thanks in advance.
Simon.