[En-Nut-Discussion] Ethernut II RS485 Communication
Dusan Ferbas
dferbas at dfsoft.cz
Thu May 13 14:26:38 CEST 2004
Hi Alex,
you need to modify SW. First is to enable direction pin toggling (see 1).
Then properly initialize usart - use new driver and set USART_MF_HALFDUPLEX
mode (see 3 below).
You can live also with original Nut sources if you will set speed after
changing flow control mode. See example below.
You can omit setting speed if you use Damian Slee's bug correction. Look
for it in discussion archive 17th February, 16th April (BugFix: Usart half
duplex mode... )
Anyway: CVS maintainers what about to incorporate Damian's fixes ?
----
1) nut/include/cfg/modem.h
For RS485 you do not need RTS/CTS so only following has to be enabled.
Whole block is by default "#if 0". Do not enable (allow define) for
..._RTS/CTS_.... This adds more code and also processing within USART driver.
#if 1
/* Define half duplex for RS485 */
#define UART0_HDX_PORT PORTD
#define UART0_HDX_DDR DDRD
#define UART0_HDX_BIT 4
#endif
2) recompile Nut/OS libraries with 'make install'
3) example of initialization: call as InitUart0(9600);
FILE *InitUart0(u_long baud)
{
FILE *uart;
//u_long cooked_mode = 0; /* disable
replacing \n with \r\n */
NutRegisterDevice(&devUsartAvr0, 0, 0);
uart = fopen("uart0", "r+b"); /* select binary
mode */
u_long flags = USART_MF_HALFDUPLEX;
_ioctl(_fileno(uart0), UART_SETFLOWCONTROL, &flags); /* due to
bug in Nut/OS 3.5.0 do this BEFORE SETSPEED */
_ioctl(_fileno(uart), UART_SETSPEED, &baud);
//following is set automatically when binary mode is selected
//_ioctl(_fileno(uart), UART_SETCOOKEDMODE, &cooked_mode);
return uart;
}
>But I cann't get anything from my slave device so far. My questions are:
>
>1. Is there anything special for the hardware setting? Did I setup my
>board correctly?
>2. I knew the 485 on Ethernut is half duplex and have to use PD5 / PD4 to
>control the data direction, but based on Nut/OS, do I still need to do
>this? Is there any existing RS-485 UART driver for Nut/OS now?
>3. If the above answer is NO, do I have to wirte ISR for Mega128 to send
>and receive package?
>
>Thanks for any kindly help.
>
>Sincerely,
>Alex
Dusan Ferbas
www.dfsoft.cz
More information about the En-Nut-Discussion
mailing list