Issues sending and receiving data


+ Reply to Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Jul 2024
    Posts
    28

    Default Issues sending and receiving data

    Hi guys,

    I'm trying to send/receive data between 2 PICs on the same circuit.
    The first one (16F1508) is sending data with debug command.

    Code:
    INCLUDE "modedefs.bas" 
    
    DEFINE DEBUG_REG PORTA             ' Set Debug pin port
    DEFINE DEBUG_BIT 2                ' Set Debug pin bit
    DEFINE DEBUG_BAUD 2400            ' Set Debug baud rate 
    DEFINE DEBUG_MODE 0                ' Set Debug mode: 0 = true, 1 = inverted
    
    
    PreAmble     CON     $A5
    
    
    debug PreAmble,$af,$c2,$b5,$ef,13,10
    The second one (16F1503) is receiving the data with debugin command.

    Code:
    INCLUDE "modedefs.bas" 
    
    DEFINE DEBUG_REG PORTC             ' Set Debug pin port
    DEFINE DEBUG_BIT 2                ' Set Debug pin bit
    DEFINE DEBUG_BAUD 2400            ' Set Debug baud rate 
    DEFINE DEBUG_MODE 0                ' Set Debug mode: 0 = true, 1 = inverted
    
    
    DEFINE DEBUGIN_REG PORTA        ' Set Debugin pin port 
    DEFINE DEBUGIN_BIT 1            ' Set Debugin pin bit  
    DEFINE DEBUGIN_BAUD 2400        ' Set Debugin baud rate (same as Debug baud) 
    DEFINE DEBUGIN_MODE 0            ' Set Debugin mode: 0 = true, 1 = inverted 
    
    
    Main:
    DEBUGIN 1000,timeoutlabel,[WAIT("$af"),DAT1,DAT2,DAT3]
    pause 3000
    
    IF DAT1=$c2 THEN
    GOTO SELECTION
    ENDIF
    
    
    
    goto main
    
    
    timeoutlabel:
    debug DEC 99,DAT1,DAT2,DAT3,13,10
    pause 3000
    
    
    goto main
    The data validation fails and the code jumps to the timeout label.

    The timeout label is sending the received information out for troubleshooting purposes.
    For troubleshooting I'm using a Microchip Pickit serial analyzer.

    The information sent is different from the information received.

    This is the data sent from PIC #1 and captured with the analyzer:

    Code:
    [00][A5][AF][C2][B5][EF][0D][0A]
    And this is the data sent from PIC #2 (when in timeoutlabel) and captured with the analyzer:

    Code:
     [4E][4E][BF][79][0D][0A][00]
    Why is the data different? The only data that seems to be correct are the carriage return bytes.
    What am I doing wrong?

    Thanks
    Last edited by PaulMaker; - 28th October 2024 at 19:39.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    I do not see a loop in the sending device. Seems it sends the data once and then stops.

    So the receiving device, if fails to receive first time correct data, loops in the timeout sub.

    Then spits out the data that are randomly stored in the variables, since you do not have a CLEAR command on the top of your program. CLEAR will ensure all variables are set to zero.

    The PAUSE 3000 are not needed I guess, since you have a 1 sec timeout.

    Ioannis.

  3. #3
    Join Date
    Jul 2024
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    Greetings Ioannis,

    thank you so much for your help.

    The sending device is actually running on a loop to troubleshoot the issue. I failed to copy that in here but it's something like this:

    Code:
    main:
    
    debug PreAmble,$af,$c2,$b5,$ef,13,10
    
    
    pause 3000
    
    
    goto main
    The receiving pic is also on a loop and that's the reason for the pause 3000 before going back to Main.

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    You also have to disable the analog inputs of port A, set by default on PIC reset, by clearing the ANSELA register.

    If you drive the output as in the sender program, then the port is set as digital output. Still I would disable the analog function. But as input it will operate as Analog input, not digital.

    Also get rid of the PAUSE 3000. They offer nothing really useful.

    Ioannis

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    ...... [WAIT("$af"),DAT1,DAT2,DAT3]........ [WAIT($af),DAT1,DAT2,DAT3]

  6. #6
    Join Date
    Jul 2024
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    Greetings all,

    thanks for the replies.

    Regarding the I/O setup, I have included the "INCLUDE "ALLDIGITAL.pbp"" on both receiver and sender codes.

    And even with the "[WAIT($af),DAT1,DAT2,DAT3]" modification, I still get the wrong data on the receiver PIC.

    Any additional thoughts?

    Thank you so much.

Similar Threads

  1. SERIN2 Receiving Wrong Data
    By rsocor01 in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 4th May 2024, 20:31
  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 : 15

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