Hi,
I would like to send and receive data between two PIC24F microcontrollers via RS485. Here i'm using SP3485 IC. I've set one microcontroller as
transmitter and another one has receiver. My microcontroller has 4 uart. One of the uart(here i use UART4) is connected with RS485 IC(SP3485) for both. As usual data pins 'A' to 'A' and 'B' to 'B' are connected. Below is the image shows which PIC24F pins are connected with RS485 IC. I'm transmitting data from one pic to another pic via RS485. In receiver side i've connected UART1 with hyperterminal for seeing the received data.The problem is While i print the received data in the hyperterminal it shows junk data. I've checked the UART1 its working fine. I've checked the UART4 configuration looks fine. What is the problem?
int main()
{
init_processor();
PORTBbits.RB5=1; //RB5 is RE/DE
while(1)
{
uart4str("Hello\r\n");
Delayms(1000);
}
return 0;
}
main.c receiver:
Code:
int main()
{
init_processor();
PORTBbits.RB5=0; //RB5 is RE/DE
while(1)
{
uart1str(uartrec4()); //printing received uart4 data in hyperterminal
Delayms(1000);
}
return 0;
}
An isolated RS-485 with common mode termination resistors is often used without common ground (e.g. in PROFIBUS standard), non-isolated should better have a ground wire. But missing ground is not necessarily the reason for failure.
The "uartsend(uartrec4());" construct must be looped without any delay, otherwise you'll get receiver overrun. Useful debugguíng steps could be:
- checking the RX signal with an oscilloscope
- tracing code execution with a debugger adapter