|
|
View previous topic :: View next topic |
Author |
Message |
DMH Guest
|
RS485 problems |
Posted: Wed Apr 27, 2005 9:23 am |
|
|
I'm having problems implementing the RS485.c code that's available with the complier. I'm using this code in conjunction with the ex_RS232_485.c that's also available with the complier.
I have 1 card configured as a master and another card configured as a slave, and the master card will transmit 1 character at a time over the RS485 bus. The slave card is receiving the character from the bus and then converted from 485 to 232 using a MAX1487 TXRX. The PIC18F6620 that I'm using receives the character from the MAX1487 as it should. I have 8 LEDs connected to Port E on the PIC, and I am trying to output the character on the LEDs with no success.
Can anyone help me with this?
The code I'm using is basically the same as the code in examples\ex_RS232_485.c
void main()
{
int8 i, msg[32];
enable_interrupts(INT_RDA);
enable_interrupts(INT_RDA2);
enable_interrupts(GLOBAL);
rs485_init();
for(;;)
{
if(rs485_get_message(msg, FALSE))
{
for(i=0; i<msg[1]; ++i)
{
fputc(msg[i+2], RS485_CD);
msg[i] = bgetc();
output_e(msg[3]);
}
for(i=0; bkbhit && i<sizeof(msg); ++i)
msg[i] = bgetc();
if(i > 0)
{
rs485_wait_for_bus(FALSE);
while(!rs485_send_message(RS485_DEST_ID, i, msg))
{
delay_ms(RS485_ID);
}
}
}
} |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Apr 27, 2005 10:44 am |
|
|
Quote: | The PIC18F6620 that I'm using receives the character from the MAX1487 as it should. |
So you know for a fact the the proper message is received?
If so, then why not try a simple test to see if the LED's function
Code: |
for (i=0;i<8;i++)
{
output_e(1<<i);
delay_ms(1000);
} |
|
|
|
DMH Guest
|
|
Posted: Thu Apr 28, 2005 2:32 am |
|
|
Mark
The code you suggested works perfectly!
I'm using Hyperterminal on my laptop which connnects to a 232-485 converter, which connects to RDA on the PIC. RDA2 connects to the MAX1487. When I measure RO on the MAX1487 with a scope and type 'U' in Hyperterminal, I see 1010101. I've also got an RS485 sniffer card connected across the bus from the master to slave cards, which is connected to a desktop PC running Hyperterminal. When the 'U' character is typed on my laptop, I see 5 characters displayed on the Desktop PC which represent source, destination, data-length, data, and checksum, as the 485.C code defines The 4th character displayed is 'U'.
Can you suggest any other way of displaying the character on port e?
The master card displays the incoming character from my laptop on port e perfectly.
Darren |
|
|
funmix
Joined: 27 Mar 2007 Posts: 33
|
|
Posted: Thu Apr 05, 2007 9:35 am |
|
|
Hi DMH,
Can you share your working code here? I wish to study the 485 communiction with PICs
Thanks! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|