[En-Nut-Discussion] UART
Markus Kohlhaupt
markus.kohlhaupt at bluewin.ch
Thu Oct 26 13:20:20 CEST 2006
hello
i'm using ethernut-4.2.1 with a atmega128 and have some problems using
the uarts.
for uart0 and uart1 i recive the same output : 0 -1
I try to know, how many characters are in the input buffer available.
my prog:
#include <cfg/crt.h>
#include <string.h>
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
#include <dev/uartavr.h>
#include <dev/nicrtl.h>
#include <dev/board.h>
#include <sys/version.h>
#include <sys/heap.h>
#include <sys/timer.h>
#include <sys/socket.h>
#include <sys/confnet.h>
#include <arpa/inet.h>
#include <net/route.h>
#include <netdb.h>
#include <net/errno.h>
#include <pro/dhcp.h>
int main(void) {
int uartA, uartB, errorA=0, errorB=0, countA=0, countB=0 ;
u_long baudrate = 115200 ;
u_long localecho = 0 ;
u_long readtimeout = 2000 ;
char temp[10] ;
NutRegisterDevice (&devUart0, 0, 0) ;
NutRegisterDevice (&devUart1, 0, 0) ;
uartA = _open ("uart0", _O_RDWR | _O_BINARY) ;
uartB = _open ("uart1", _O_RDWR | _O_BINARY) ;
_ioctl(uartA, UART_SETSPEED, &baudrate) ;
_ioctl(uartA, UART_SETLOCALECHO, &localecho) ;
_ioctl(uartA, UART_SETREADTIMEOUT, &readtimeout) ;
_ioctl(uartB, UART_SETSPEED, &baudrate) ;
_ioctl(uartB, UART_SETLOCALECHO, &localecho) ;
_ioctl(uartB, UART_SETREADTIMEOUT, &readtimeout) ;
while (1) {
errorA = _ioctl (uartA, IOCTL_GETINBUFCOUNT, &countA) ;
errorB = _ioctl (uartB, IOCTL_GETINBUFCOUNT, &countB) ;
itoa (countA, temp, 10) ;
_write (uartA, "A : ",4) ;
_write (uartA, temp, strlen(temp)) ;
itoa (errorA, temp, 10) ;
_write (uartA, temp, strlen(temp)) ;
_write(uartA, "\r", 1) ;
itoa(countB, temp, 10) ;
_write (uartB, "B : ",4) ;
_write (uartB, temp, strlen(temp)) ;
itoa (errorB, temp, 10) ;
_write (uartB, temp, strlen(temp)) ;
_write(uartB, "\r", 1) ;
NutSleep (3000) ;
}
}
what is wrong ?
What are the differences to use uart or usart ?
I' will read characters from uart0, convert the characters and send it
uart1, and vs., all this in raw-mode. I will not use blocking-read, so i
'm locking for a function to know, how many characters are collected in
the buffer.
Thanks for help
Markus
More information about the En-Nut-Discussion
mailing list