• AVR Freaks

Hot!PIC to PIC Communication using UART

Author
salyMal
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2017/02/21 10:12:31
  • Location: 0
  • Status: offline
2020/03/25 10:10:11 (permalink)
0

PIC to PIC Communication using UART

 
I am using two pic32mz2048efh144  each connected to a explorer 16/32 (evaluation board) and  would like to do  communication between them 
 am testing the communication by the following example: when  click button s6 of the emitter explorer 16/32  the  sends the information (2) to the receiver. Then the led 3 of the receiver  16/32 should be on.
 UART  pin of pic1 is  with a wire  the UART Rx pin of the second pic
 is not working for me and i dont  know why.
 
kindly find attached the codes uploated to the emitter pic32 and the receiver pic32
 
The  is not on so  can conclude that the receiver   the data (2)
In debug mode  noticed that in the receiver code the system remains  the line  (while! IFS3bits.U1RXIF); and does not continue 
 maybe the problem is at the receiver side. 
 
Thank you for your time
 best regards
post edited by salyMal - 2020/03/25 12:21:50
#1

9 Replies Related Threads

    rodims
    Super Member
    • Total Posts : 1557
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: offline
    Re: PIC to PIC Communication using UART 2020/03/25 10:20:15 (permalink)
    0
    Did you have a look at your own post ?
    Your post seems to be completely corrupted, which likely is the result of simply pasting your code here. 
     
    Please use code tags for your code and be sure to paste a NEW copy then.
    You can edit your post and first remove almost everything. Then paste your code again using code tags.
     
    [ c o d e ]
    your code goes here
    [ / c o d e ]
     
    However you have to remove all the blank characters in the braces.
    If you use it that way it should look like this, and it will not be corrupted.

    your code goes here

     
    And don't forget to check what you have posted.
    #2
    salyMal
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2017/02/21 10:12:31
    • Location: 0
    • Status: offline
    Re: PIC to PIC Communication using UART 2020/03/25 12:11:51 (permalink)
    0
    thank you for your note, I attached the codes to my post as C files for an easier reading.
    #3
    LdB_ECM
    Super Member
    • Total Posts : 312
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: online
    Re: PIC to PIC Communication using UART 2020/03/25 13:13:21 (permalink)
    0
    You don't have the receive IRQ setup and you never clear it, so it's probably always going to be 1 .. fix that or alternatively just use the RXDA flag. I haven't checked all the PIN setups and taking it on good faith you did that all correct.
     
    For some reason I cant post your function name UART_g**_char it hits the forum filter, know thats what I mean but I can't use the exact name
    char UART_g**_char
    {
       while (U1STAbits.URXDA == 0){};
       return U1RXREG;
    }

    post edited by LdB_ECM - 2020/03/25 13:26:45
    #4
    salyMal
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2017/02/21 10:12:31
    • Location: 0
    • Status: offline
    Re: PIC to PIC Communication using UART 2020/03/25 14:33:33 (permalink)
    0
    thank you for your reply
    I did what you suggest me to do (if I understand correctly) I have removed the command:
    while(! IFS3bits.U1RXIF);

    and replace it by  
    while (U1STAbits.URXDA == 0){};

    but it didnt work
    led 3  of the receiver explorer 16/32 still off and in debug mode the system was blocked in the line of : 
    while (U1STAbits.URXDA == 0){};

     
    should i add more commands for the setup of the interrupt? 
    you said: You don't have the receive IRQ setup and you never clear it,
    where to do setup and where exactly should i clear it 
    #5
    ric
    Super Member
    • Total Posts : 26159
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC to PIC Communication using UART 2020/03/25 14:40:55 (permalink)
    5 (1)
    LdB_ECM
    For some reason I cant post your function name UART_g**_char it hits the forum filter, know thats what I mean but I can't use the exact name

    Any occurance of "char" followed by "(" will trigger the filter.
    Even a space in between won't help. Two spaces will, because one of them is encoded as an HTML "non-break space", which disrupts the firewall's scanning rules...
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    LdB_ECM
    Super Member
    • Total Posts : 312
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: online
    Re: PIC to PIC Communication using UART 2020/03/25 20:00:48 (permalink)
    0
    Looking at your transmitter code I am guessing it is not sending anything because it is using interrupt flag as well .. same issue use UTXBF flag instead
     
    void UART_send_char  (char bt)
    {
        while (U1STAbits.UTXBF == 1){};
        U1TXREG = bt;
    }

     
    Can I also say I don't get why you have both RX and TX setup in 9bit mode when your send and receive routines only use 8 bits (AKA char). Waste of transmission time.
     
     
    post edited by LdB_ECM - 2020/03/25 20:02:39
    #7
    malaksal
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2017/03/14 02:35:03
    • Location: 0
    • Status: offline
    Re: PIC to PIC Communication using UART 2020/03/26 03:19:09 (permalink)
    0
    thanks but sétill not working
    #8
    malaksal
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2017/03/14 02:35:03
    • Location: 0
    • Status: offline
    Re: PIC to PIC Communication using UART 2020/03/30 07:29:51 (permalink)
    0
    hello again i tried to enhance my code and i used interrupt in the uart receiver yet still not working
    should the transmission be also using interrupt?
    kindly find attached the new version of my codes
    #9
    Jan Audio
    Senior Member
    • Total Posts : 132
    • Reward points : 0
    • Joined: 2018/09/24 08:12:24
    • Location: 0
    • Status: offline
    Re: PIC to PIC Communication using UART 2020/03/30 07:54:47 (permalink)
    0
    *Sorry did not read your code.
     
    For start you make the receive working with something else, if you have a MIDI keyboard ?
    Then you can make the transmitter and all works.
     
    *my beginner knowledge
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5