Uart Overrun error [OK]

Beta Testing discussion on mikroPascal PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Uart Overrun error [OK]

#1 Post by Dany » 04 Feb 2016 18:36

Added 2016-02-05: Can be solved by clearing the OERR_bit (overrun error). See 2nd post.

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.
The overrun here is caused by the 50 ms delay, limiting very much the speed at which serial data can be accepted.

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
abc
-continously pressing 'a' echoes e.g.
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- pressing 'abc' after that echoes
'aaa'
in stead of 'abc'

"Uartx_Data_Ready" seems to be still working Ok after overrun.

Anyone any ideas?
Thanks in advance!
Last edited by Dany on 05 Feb 2016 11:37, edited 4 times in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Uart Overrun error

#2 Post by Dany » 04 Feb 2016 19:01

Edited on 2016-02-07: changed the extra statement to add.

Hi, Apparently the overrun error bit is not cleared in the Uartx_read routine (which is a fair decision, if it would be the case, the user could never detect there was an overrun).

So, the phanomenon discribed above can be solved by adding

Code: Select all

if OERR_U1STA_bit = 1 then OERR_U1STA_bit := 0; // clear the overrun error
somewhere in the loop, e.g. after the "Uart1_Read" statement.

One question stays: why does the Uart_Read statement give the wrong character when the OERR bit stays on? Is it due to the Uart hardware that refuses to take input as long as the overrun condition occurs?
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing”