I am currently working on a RS485 communication, I use a PIC16F18855 and a THDV1505. I communicate with my computer using a USB/RS485 converter.
The PIC receives the data well, but I have a problem sending the data. The data I receive are chaotic, for the moment I just try to send 0 / 1 / 2 / 3 /.... / 8, and what I get is :
Here is the schematic of the RS485 part, [edit] resistors R8 and R9 of 100R are not mounted :
Here you will find the code, the interrupt that manages the communication:
if(PIR3bits.RCIF){
t_rx[etape_it_uart] = RC1REG;
etape_it_uart++;
if(etape_it_uart > SIZE_RX_TRAME){
etape_it_uart = 0;
rx_trame_ok = true;
}
if(RC1STAbits.OERR)
{
RC1STAbits.CREN = 0;
RC1STAbits.CREN = 1;
}
}
if(PIR3bits.TXIF){
EN485_SetHigh();
if (nb_octet_tx < SIZE_TX_TRAME) {
TX1REG = t_tx[nb_octet_tx];
nb_octet_tx++;
} else {
tx_trame_ok = 1;
TX1STAbits.TXEN = 0;
EN485_SetLow();
}
}
Here you will find the part of the code that starts the transmission :
case 21 :
t_tx[0] = 0x00;
t_tx[1] = 0x01;
t_tx[2] = 0x02;
t_tx[3] = 0x03;
t_tx[4] = 0x04;
t_tx[5] = 0x05;
t_tx[6] = 0x06;
t_tx[7] = 0x07;
t_tx[8] = 0x08;
etat_uart = 30;
break;
case 30:
nb_octet_tx = 0;
tx_trame_ok = 0;
etat_uart = 40;
TX1STAbits.TXEN = 1;
break;
case 40:
if (tx_trame_ok) {
etat_uart = 0;
etape_it_uart = 0;
TX1STAbits.TXEN = 0;
}
break;
Hoping to come across someone who will help me solve this problem!
Thank you all and have a nice day.
[EDIT] Here are the signals I read on the oscilloscope :
And for more explanation on wiring with the termination resistor:
[EDIT 2] The 2 pictures of the signals above correspond to the USB/RS485 => PCB signals, error on my part on the signal plug. The frame sent is 0x05 / 0x10 / 0x06 / 0x16 / 0x04.
Below are the PCB => RS485/USB signals. The frame sent is 0x00 / 0x01 / 0x02 ..... 0x07 / 0x08.
And here is the EN signal, only 8ms in high state :