[En-Nut-Discussion] half duplex USART driver
Dusan Ferbas
dferbas at dfsoft.cz
Wed Apr 7 13:37:56 CEST 2004
Hi,
I browsed several months of discussion list and did not find if anybody had
problem with using old uartavr serial driver for half duplex port mode (for
RS485). Is there anybody who can share such an experience ?
Anyway new usartavr driver solves immediate direction switching. I found 2
bugs (described below).
I have different applications where different pin is used to switch RS485
direction. How can I use usart driver to minimize changes from application
to application. Any simple advice ?
Thanks
---
1) I think code cut and paste problem. It can work if RTS pin is used for
direction change. But if RTS flow control is not desired then this produces
compilation errors.
*** usartavr.c Wed Apr 7 11:00:02 2004
--- usartavr(ori).c Mon Dec 15 21:25:34 2003
***************
*** 1082,1089 ****
#ifdef UART_HDX_BIT
if (hdx_control) {
/* Enable half duplex transmitter. */
! //DF 7.4.2004 (typo): sbi(UART_RTS_PORT, UART_RTS_BIT);
! sbi(UART_HDX_PORT, UART_HDX_BIT);
}
#endif
--- 1082,1088 ----
#ifdef UART_HDX_BIT
if (hdx_control) {
/* Enable half duplex transmitter. */
! sbi(UART_RTS_PORT, UART_RTS_BIT);
}
#endif
2) When uart is opened and half duplex mode is then set, this does not work.
Code behaves this way because 'hdx_control' is changed in
AvrUsartSetFlowControl() but AvrUsartEnable() is not called to reflect this.
You can satisfy this if you set uart speed every time you change half
duplex mode (flow control). AvrUsartSetSpeed() calls AvrUsartEnable() at
its end.
This can be demonstrated if you exchange line 7. with line 8. in following
code fragment.
1. FILE *uart;
2. u_long flags;
3.
4. NutRegisterDevice(&devUsartAvr1, 0, 0);
5. uart = fopen("uart1", "r+b");
6. flags = USART_MF_HALFDUPLEX;
7. _ioctl(_fileno(uart), UART_SETFLOWCONTROL, &flags);
8. _ioctl(_fileno(uart), UART_SETSPEED, &baud);
Dusan
More information about the En-Nut-Discussion
mailing list