[En-Nut-Discussion] I can't activate the 9.Bit of UART over Nut OS

Thomas Kuhnert T.Kuhnert at pemtec.de
Wed Aug 5 09:01:35 CEST 2009


I have the following problem. I want to build a network over 485
I need the 9 Bit Data frame for distinguishing address and data. When I
Enable the 9 Bit Data Frame I get an error and only the 8-bit transfer
is enabled. 

If I activated the 9.Bit in the USCR1B register, I can see on the
oscilloscope that it would be transmit but I have no influence on what
he transfers as long as I use the output stream. 

Only when I directly write in to the UDR register, I can write the bit
is reset the Bit. But then I missing my activation signal so that the
485 interface can operate half-duplex.
Here my Code:
#include <dev/board.h>
#include <sys/timer.h>
#include <string.h>
#include <stdio.h>
#include <io.h>
int main(void)
uint32_t baud_dbg = 115200;
uint32_t baud_485 = 230400;
uint32_t parity = 0;
uint32_t stopBit = 1;
uint32_t DataBit = 9;
uint32_t flow_485 = USART_MF_HALFDUPLEX;
uint32_t to_485 = 1000;
FILE *rs485;
outb(DDRB, 0xf0);
NutRegisterDevice(&DEV_DEBUG, 0, 0);
freopen(DEV_DEBUG_NAME, "w", stdout);
_ioctl(_fileno(stdout), UART_SETSPEED, &baud_dbg);
puts("\nRS485 Master Sample");
if (NutRegisterDevice(&devUsartAvr1, 0, 0)) {
puts("Failed to register " DEV_UART1_NAME);
if ((rs485 = fopen(DEV_UART1_NAME, "r+")) == NULL) {
puts("Failed to open " DEV_UART1_NAME);
if (_ioctl(_fileno(rs485), UART_SETFLOWCONTROL, &flow_485)) {
puts("Failed to set flow control");
if (_ioctl(_fileno(rs485), UART_SETSPEED, &baud_485)) {
puts("Failed to set baudrate");
if (_ioctl(_fileno(rs485), UART_SETDATABITS , &DataBit)) {
puts("Failed to set DataBit");
if (_ioctl(_fileno(rs485), UART_SETPARITY , &parity)) {
puts("Failed to set Parity");
if (_ioctl(_fileno(rs485), UART_SETSTOPBITS, &stopBit)) {
puts("Failed to set StopBits");
if (_ioctl(_fileno(rs485), UART_SETREADTIMEOUT, &to_485)) {
puts("Failed to set read timeout");
sbi(PORTD, 2);
sbi(UCSR1A, U2X);
sbi(UCSR1B, UCSZ12);    // Aktivier 9 BIT Modus
for (;;) {
UCSR1B |= TXB81;   // Set Bit 9 for Address
UCSR1B &= ~TXB81;  // reset Bit 9 for Data
fprintf(rs485, "Data");
return 0;
Thanks in advance
Yours sincerely,
Thomas Kuhnert

More information about the En-Nut-Discussion mailing list