SERIN2 Receiving Wrong Data


+ Reply to Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 Receiving Wrong Data

    I'm still troubleshooting.
    alone, until you provide at least a minimal, complete and verifiable example [MCVE]

    posting useless snippets is a good example of a worthless bad example


    my guess for the nearest to the pot Calcutta is inadequate power supplies
    Warning I'm not a teacher

  2. #2
    Join Date
    Aug 2011
    Posts
    414


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 Receiving Wrong Data

    Code:
    'Code at device A, PIC18F4550
    SendData:
       pause 5
       SEROUT2 PORTB.7,32,[STR RFID_IN\7]    
    goto SendData
    You're only allowing device B 5ms between transfers to receive the data and display it.
    If device B is not finished and sitting back at the SERIN2 statement before device A does another transmission it will fail.
    Try increasing the 'pause 5' to 'pause 500' and see if things get better.

    You might also have to break the single SEROUT2 statement into something a little slower, like sending the RFID_IN array data a byte at a time with a pause in between the bytes to allow device B time to receive, save it, and be ready for the next byte. As I mentioned before, you're using a software SERIN2 on device B which is VERY timing-dependent and prone to failure. A hardware UART is much better suited for this, especially for receiving data.

    You could also be having issues with osc accuracy between the two... on each end send a 'U' (hex 55) and measure the bit timing. At 19200 baud each bit should be 520us +/-15us, give or take (about 3%).

    My bet would be on one of the first two above.

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    654


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 Receiving Wrong Data

    Tumbleweed, I had very strong suspicions that the issues were in the communication lines. I changed the Baud rate from 19200 to 9600 and I haven't got anymore wrong data at the receiver. I remember from my EE school days that the higher the frequency, the more prone to line noise the data is. So, by lowering the Baud rate it worked. I was pulling my hair out for a few days. At first I thought that it was some kind of SERIN2/SEROUT2 software issue.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  4. #4
    Join Date
    Aug 2011
    Posts
    414


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 Receiving Wrong Data

    By lowering the baud rate you're now allowing device B (and SERIN2) twice the time to receive the bits and assemble the byte.
    That's probably what's helping a lot more than any line noise issue.

    A software UART has a lot of potential timing issues, especially when it comes to receiving.

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    654


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 Receiving Wrong Data

    Quote Originally Posted by tumbleweed View Post
    By lowering the baud rate you're now allowing device B (and SERIN2) twice the time to receive the bits and assemble the byte.
    That's probably what's helping a lot more than any line noise issue.
    There is probably a little bit of both. I did a search in the forum, but couldn't find anyone having the same issue.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,821


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 Receiving Wrong Data

    What is the clock of each PIC you use?

    Ioannis

  7. #7
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    654


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 Receiving Wrong Data

    Quote Originally Posted by Ioannis View Post
    What is the clock of each PIC you use?

    Ioannis
    The sending device has the typical 18F4550 USB setup and it is set to "Define OSC 48". The receiving device is set to "DEFINE OSC 16".
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,821


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 Receiving Wrong Data

    As Richard noted, the problem could be in any other part of your code. So you are alone on this as we cannot guess what may be happening there.

    However, the part you posted does not somehow checks for valid incoming message. For example you could on the sending device use a string of "hey" and then the data.

    On the receiving device wait("hey") and then collect your data. In this case you will not receive data in the middle of the transmission.

    Ioannis

  9. #9
    Join Date
    Aug 2011
    Posts
    414


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 Receiving Wrong Data

    Just to correct myself in #9...

    At 19200 baud each bit should be 52us +/-1.5us, give or take (about 3%).

    I was thinking byte times, not bit times.

  10. #10
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    654


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 Receiving Wrong Data

    Ioannis, yes I'm doing data validation checks all the time. The first byte of the array is always 174. If this condition is not met, then the reading is discarded.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

Similar Threads

  1. Replies: 6
    Last Post: - 19th August 2013, 11:22
  2. how to display data receiving from xbee to LCD
    By NURULHAIZA in forum mel PIC BASIC
    Replies: 2
    Last Post: - 19th November 2010, 21:24
  3. Sending/receiving data using Linx modules
    By Goat 403 in forum Serial
    Replies: 3
    Last Post: - 21st May 2009, 13:57
  4. Receiving and Transmitting Serial data at the same time
    By BobP in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th April 2007, 22:00
  5. Receiving data from more than one serial Port
    By PICtron in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th March 2005, 10:20

Members who have read this thread : 17

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