UART Data not correct

General discussion on mikroPascal PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
rayhall
Posts: 58
Joined: 20 Oct 2006 08:00
Location: Cairns, Australia

UART Data not correct

#1 Post by rayhall » 08 May 2010 01:47

I am having problems getting serial data correct. I am using the Mega2561 at 11,059200 Mhz

I send 31 bytes that end with $7E. I recive back only the first two bytes then the $7E byte.

Below is my code.

Ray.

******* Sent Data ********
24 1A 00 80 A3 07 00 35 01 35 01 E2 01 38 00 99 01 66 02 0A 02 00 00 06 04 00 00 FF FB 1D 7E
******* Recived Data ********
24 1A 7E 00 12 00 00 00 01 00 00 00 02 00 00 00 35 36 00 00 12 00 00 00 01 00 00 00 03 00 00

Code: Select all

var
   Rxdata: array[1..31] of Byte;
   gotPCdata: Boolean;
   xv: Byte;

{----------------------- GetSerialData; ----------------------}
procedure GetSerialData;
 var
   x: Byte;
begin
   Rxdata[1]:= UART1_Read();
   if Rxdata[1] = $24 then begin
     Rxdata[2]:= UART1_Read();
     for x:= 3 to Rxdata[2] + 2 do begin
       Rxdata[x]:= UART1_Read();
     end;
     gotPCdata:= True;
   end;
end;

{********************* Main Program ******************}
begin
  { Main program }
  UART1_Init(57600);                         
  Delay_ms(100);                           

while (TRUE) do  begin                          
    if (UART1_Data_Ready() <> 0) then begin     
      GetSerialData;
      if gotPCdata = True then begin
        for xv:= 1 to 31 do begin
         UART1_Write(Rxdata[xv]);
        end;
        gotPCdata:= False;
      end;
end;

matrix
Posts: 203
Joined: 26 Jan 2006 07:21
Location: Bulgaria
Contact:

Re: UART Data not correct

#2 Post by matrix » 08 Jun 2010 15:41

You should use if (UART1_Data_Ready() <> 0) before each read.

Post Reply

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