|
|
View previous topic :: View next topic |
Author |
Message |
charles Guest
|
RS485 Connection - #use rs232 |
Posted: Thu May 11, 2006 6:42 pm |
|
|
Hi,
I am quite a 4 days old beginner in microcontroller programming...
I am trying to setting up a RS485 connection between two PICs.
I have a first problem, it is that if I set the communication to be at a certain speed the sender receive the data 2 times slower, if I set the sender to send at twice as many baud it works fine (at leat for the early test, one receive the caracters the other send).
Then, if I try to define 2 stream to deal with the asymetry, one to send and one to receive :
Code: | #use rs232(baud=SPEED_RX, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=9, /*long_data,*/ errors, stream=RS485RX)
#use rs232(baud=SPEED_TX, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=9, /*long_data,*/ errors, stream=RS485TX)
|
apparently the second declaration overwrite the first one, I can use both stream but both have the settings of the second one.
Any help or documentation would be greatly appreciated,
Thanks,
Charles. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 11, 2006 7:53 pm |
|
|
I assume you're using the hardware UART pins. If so, you can use
the setup_uart_speed() function to change the baudrate. Example:
Code: |
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#define SPEED_RX 4800
#define SPEED_TX 9600
#use rs232(baud=SPEED_RX, xmit=PIN_C6, rcv=PIN_C7, enable=PIN_C2, bits=9, /*long_data,*/ errors, stream=RS485RX)
#use rs232(baud=SPEED_TX, xmit=PIN_C6, rcv=PIN_C7, enable=PIN_C2, bits=9, /*long_data,*/ errors, stream=RS485TX)
//======================================
void main()
{
char c;
set_uart_speed(SPEED_TX, RS485TX);
fputc(0x55, RS485TX);
set_uart_speed(SPEED_RX, RS485RX);
c = fgetc(RS485RX);
while(1);
} |
|
|
|
Guest
|
|
Posted: Fri May 12, 2006 5:14 pm |
|
|
Hi, thanks for you help.
apparently the speed issue was due to the microcontrollers clock settings...
Thanks.
Charles. |
|
|
|
|
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
|