• AVR Freaks

Hot!PIC32MZ RS485 communication: data transmission problem

Author
saikumar.k
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2020/01/22 00:16:45
  • Location: 0
  • Status: offline
2021/03/01 04:24:14 (permalink)
0

PIC32MZ RS485 communication: data transmission problem

Hi,
I observed a strange problem when using rs485 for communication. Microcontroller is able to transmit data to DTE(terminal software) at specific clocks at specific baud rates. Receiving data successfully but transmission problem only. While transmitting t data continuously, junk data sent to DTE during some iterations .
 
Following are the details:
MCu: PIC32MZ1025DAR176
System clock: 200 MHZ
PBCLK2 clock: 100 MHZ(max)
Rs485 IC : sn65hvd75
 
While having trail and error with PBCLK, at 10MHZ and 66MHZ able to perform both RX and TX at some specific baud rates i.e 9600,19200,115200.
This is the code i am using for sending data:
 
void Send_RS485_Uart(unsigned char *str, unsigned int str_len)
{
LATGbits.LATG15 = 1;

while (str_len)
{
while ((U2STAbits.UTXBF)); //1= full and 0 means empty
/* Send character */
U2TXREG = *str++;
while (!(U2STAbits.TRMT)); // 1 = empty and last transmission is completed
str_len--;
}

LATGbits.LATG15 = 0;



}
 
Appreciate your help..!
Thank you!
#1

7 Replies Related Threads

    ric
    Super Member
    • Total Posts : 30195
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC32MZ RS485 communication: data transmission problem 2021/03/01 04:38:28 (permalink)
    5 (2)
    Move the wait for TRMT to after your send string loop, then wait one more bit time before disabling the buffer.

    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!
    #2
    saikumar.k
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2020/01/22 00:16:45
    • Location: 0
    • Status: offline
    Re: PIC32MZ RS485 communication: data transmission problem 2021/03/01 04:52:02 (permalink)
    0
    Hi ric,
    Thanks for the quick reply!
     
    i did like this and still issue present.
    void Send_RS485_Uart(unsigned char *str, unsigned int str_len)
    {
    LATGbits.LATG15 = 1;

    while (str_len)
    {
    while ((U2STAbits.UTXBF)); //1= full and 0 means empty
    /* Send character */
    U2TXREG = *str++;
    str_len--;

    }
    while (!(U2STAbits.TRMT)); // 1 = empty and last transmission is completed

    LATGbits.LATG15 = 0;

    // RS485_Tick = SYS_TIME_CounterGet();
    }
    #3
    malaugh
    Super Member
    • Total Posts : 428
    • Reward points : 0
    • Joined: 2011/03/31 14:04:42
    • Location: San Diego
    • Status: offline
    Re: PIC32MZ RS485 communication: data transmission problem 2021/03/01 08:23:14 (permalink)
    4 (1)
    Look in the errata for the chip.  I remember some time ago there was an error in the UART where TRMT would assert before the transmitter was empty.  I think putting in a few NOPs before switching off the RS485 driver may cure the problem.  Not sure about this, just something to check.
     
    I think the second version of your code looks good.
     
    #4
    ric
    Super Member
    • Total Posts : 30195
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC32MZ RS485 communication: data transmission problem 2021/03/01 12:24:48 (permalink)
    5 (1)
    saikumar.k
    i did like this and still issue present.

    You added the first thing I suggested, and skipped the second.
    The extra delay is required because TRMT goes active at the start of the final STOP bit, which is why you need to delay for one bit time before turning off the transmitter.
     

    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!
    #5
    saikumar.k
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2020/01/22 00:16:45
    • Location: 0
    • Status: offline
    Re: PIC32MZ RS485 communication: data transmission problem 2021/03/01 22:58:28 (permalink)
    0
    I added a bit time which is 1/19200 approx 52 microSec. Still issue presents. When i added 1 msec delay then it is working. 
    Also want to inform you that problem had been resolved when i followed the work around given in the errata for PIC32mz Graphics family. This time no delay added and code is as 1st version . Enabled BRGH = 0 and calculated BRG manually  solved the problem and uart clock is 100 MHz.
    When uart clock is 10 MHz , again problem occured.
     
    So can you please suggest a work around irrespective of clock?
    #6
    Jerry Messina
    Super Member
    • Total Posts : 694
    • Reward points : 0
    • Joined: 2003/11/07 12:35:12
    • Status: offline
    Re: PIC32MZ RS485 communication: data transmission problem 2021/03/02 07:45:40 (permalink)
    5 (1)
    Does it help if you set it to transmit 2 stop bits?
    #7
    Stefiff
    Super Member
    • Total Posts : 120
    • Reward points : 0
    • Joined: 2012/07/15 15:26:29
    • Location: 0
    • Status: offline
    Re: PIC32MZ RS485 communication: data transmission problem 2021/03/09 14:47:48 (permalink)
    0
    Two things, I use the similar processor - PIC32MZ2064DAS176.
    1. You can't just write random frequencies. There is a formula by which it is calculated. You have to get a minimal error, otherwise there will just be permanent errors. I use almost all the hardware modules in the processor /UART, SPI, I2S, I2C, Timers, DMA, GPU, SDcard ../, and I have taken this into account. Just choose something that works for you. For me, for example, it works at 192MHz, PBCLK2=96MHz, UART=38400b/s. But no problem with other UART speeds.
    2. For me, everything works in ISR, and there is no problem. The bytes are glued, FIFO does its job perfectly. For the CPU, the transmission is practically transparent, and does not loaded it. BRGH=0! RS485 pin (RX/TX) for 65176 chip is switching from ISR (last byte).
    Without Harmony.
    post edited by Stefiff - 2021/03/09 14:49:12
    #8
    Jump to:
    © 2021 APG vNext Commercial Version 4.5