Hi, in some cases, when the uart data comes in too fast, the Uart hardware is overrun (the previous data is not fetched yet, while new data comes in already). This is normal, but subsequent characters are read in wrongly: the character received is always the same as the one that caused the overrun.
Consider this simple code:
Code: Select all
program Serial_Overrun;
// P24FJ64GB002
{ Declarations section }
var Dummy: byte;
begin
{ Main program }
// Uart1
PPS_Mapping (8, _INPUT, _U1RX); // RP7 is uart1 input pin 17
PPS_Mapping (7, _OUTPUT, _U1TX); // RP6 is uart1 output pin 16
Uart1_init(115200);
delay_ms(250);
while true do
begin
if Uart1_Data_Ready = 1 then
begin
Dummy := Uart1_Read; // reveive character from e.g. hyperterminal
Uart1_write(Dummy); // echo character
end;
delay_ms(50);
end;
end.
When an overun occurred (e.g. by sending contiously a character e.g. from Hyperterminal, keeping the key pressed for a longer time), the character echoed is always the same as the one that caused the overrun, not any more the character that should be received.
So:
-typing 'abc' echoes
-continously pressing 'a' echoes e.g.abc
- pressing 'abc' after that echoesaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
in stead of 'abc''aaa'
"Uartx_Data_Ready" seems to be still working Ok after overrun.
Anyone any ideas?
Thanks in advance!