How to receive stream of bytes using PIC USART


Closed Thread
Results 1 to 35 of 35

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Sorry, but this is confusing..

    How does the PC know when to tell the PIC that the time is right to receive data?

    Why not have the PC work at 4800 baud also?

    Seems like by the time the PC some how decides the time is right and sends this to the PIC the time would have passed for the data?
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Jun 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    How does the PC know when to tell the PIC that the time is right to receive data?
    The data from SpO2 module is sent out continuously. The updated data is sent out from the module all the time. The PC just send request whenever it wants to and the PIC will responsible to grab a few current data bytes from the SpO2 module and extract out the targeted bytes, which are SpO2 data byte and pulse rate data byte.

    Why not have the PC work at 4800 baud also?
    I need to send the data through a wireless transceiver module which works at 9600 baud rate eventually. For testing purpose, I am connecting the PIC directly to the PC UART instead of the transceiver.

  3. #3
    Join Date
    Jun 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    I have tried with sending out data bytes that received from the modules to PC immediately but the data displayed on the PC is different from the data that I connected the module directly to PC. It seems like the data of the bytes stream corrupts when it passes through the PIC.

    This is the testing code:

    Code:
    INCLUDE "modedefs.bas"
    DEFINE LOADER_USED 1    	
    DEFINE OSC 20 
    B0 VAR BYTE
    
    'PB.7 = Rx, PB.6 = Tx
    TRISB = %10000000 
    
    loop:
    '4800 baud rate
    'read byte from SpO2 module
    SerIn2 PORTB.7,16572,[B0]
    'send byte to PC
    SerOut2 PORTB.6,16572,[B0]
    GoTo loop
    End
    What should I do to avoid the data from crashing in Rx buffer of PIC UART, provided I cannot control over the stream of bytes received?
    Last edited by unifoxz; - 14th June 2009 at 03:00.

  4. #4
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Are you sure it's not just an inverted vs true problem? If it is a buffer problem, you could switch to the hardware uart and use something like they do for reading gps strings:

    Code:
    MAXDATA      CON 70       'The buffer Size for GPS Data  was 70  
    gpsdata         VAR BYTE[MAXDATA]    '  70 byte array.
    HSerin 200, Main, [WAIT("$GPRM"), STR gpsdata\MAXDATA\13]
    http://www.scalerobotics.com

  5. #5
    Join Date
    Jun 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    I was thinking it could be inverted vs true problem too. However my assumption was found to be fault after I receive unknown characters on the screen of PC.
    I also have tried similar method as suggested but the problem remains. The PIC reading is not the supposed data.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Here are several examples of serial in and out.
    http://www.melabs.com/resources/samples/pbp/ser2mod.bas

    Now for the
    What should I do to avoid the data from crashing in Rx buffer of PIC UART, provided I cannot control over the stream of bytes received?
    You are using software for serial so the only time anything gets into the PIC is when you ask for it. If you were using hardware then the buffers would need to be cleared.

    'send byte to PC
    SerOut2 PORTB.6,16572,[B0]
    Earlier you said the PC was running the port at 9600? Did you change it for the above test to 4800?

    And modifiers. The examples on the above link talks about DEC and such VS ASC||. You might need one.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Jun 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Yes, I tried to set up a simple test to check what is actually happening on the bytes I receive. I use 4800 baud rate for both module and PC this time.

    You are using software for serial so the only time anything gets into the PIC is when you ask for it. If you were using hardware then the buffers would need to be cleared.
    I tried with PIC hardware UART to receive the bytes from module too but the result is the same. The data is not the one it should be.

    May I know how to clear hardware UART buffer? I tried to reset CREN and read in the data after the reset, it is not working as well. I am not sure whether it is the way to clear the buffer.

  8. #8
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    This automatically clears it, but then you can't read what it stuck on. But seeing as this data gets resent over and over, it really should be a problem. You should catch it on the next round.

    Code:
    DEFINE HSER_CLROERR 1                  'Auto Reset Buffer Overrun Errors
    Last edited by ScaleRobotics; - 14th June 2009 at 07:14.
    http://www.scalerobotics.com

Similar Threads

  1. Replies: 6
    Last Post: - 31st August 2007, 09:31
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  3. 16F876 Usart Receive
    By syscoder in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st March 2007, 15:43
  4. Replies: 1
    Last Post: - 6th September 2005, 16:32
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts