Menu

Making two PICs communicate each other with UART

Help
ma1069
2014-06-15
2014-06-19
  • ma1069

    ma1069 - 2014-06-15

    Hi guys,
    I am experiencing some issues when trying to make two PIC18F1320 to communicate each other by using the Hardware UART port.

    Basically, I connected together the TX/RX ports of a PIC to the RX/TX ports of the other one, and then I wrote two very trivial pieces of code, one continuously sending some bytes and the other one continuously receiving them.
    Here are the two pieces of code:

     #chip 18F1320, 8
     #define USART_BAUD_RATE 9600
     #define USART_BLOCKING true
     #define SerInPort PORTb.4
     #define SerOutPort PORTb.1
     Dir SerOutPort Out
     Dir SerInPort In
    
     main:
     wait 500 ms
     HSerPrint "Z"
     GoTo Main
    

    The other one, instead, is:

     'same defines as before
     ...
     Dir SerOutPort Out
     Dir SerInPort In
     Dim buffer as Byte
    
     main:
     wait 500 ms
     byte = HSerReceive
     ' Blink a LED
     ...
     GoTo Main
    

    Unfortunately, the LED doesn't blink, even if I see some movement on the serial line...
    Am I missing something? Am I using the HSerPrint/HSerReceive methods in a wrong way?

    Thank you,
    Matteo

    edit:
    to avoid issues, I have tried to explicitly disable any other thing that might occur on the same pins, by disabling the A/D converters and all the interrupts, but unfortunately nothing changed :(

     

    Last edit: ma1069 2014-06-15
  • ma1069

    ma1069 - 2014-06-18

    That was my starting point: the code I wrote took inspiration from that, but unfortunately it doesn't work... What do you think I could be missing?

     
  • Anobium

    Anobium - 2014-06-18

    Oh.

    Does the interrupt work on the chipset you are using? That is the first place I would start.

    But, communications maybe be easier using I2C. What is the distance or requirements for Serial comms?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.