AW: [En-Nut-Discussion] UART

Ernst Stippl ernst at stippl.org
Fri Oct 27 16:30:39 CEST 2006


Hi!

I grep'ed thru the Ethernut files and found IOCTL_GETINBUFCOUNT and
IOCTL_GEToutBUFCOUNT only used in TCPSOCK.C
It seems to me that this function is not implemented in USART.C 
Because I wrestle with a similar subject, I took your source, modified it
(one USART only) and tried how the timeout function
works.
The result is attached: both the source and the console log.
Its amazing that always just one character is returned by "_read". 
I tested on a Ethernut 3 board with Nus/OS 4.2.1

regards
Ernst

----------------------------------------------------------------------------
--------------
#include <io.h>                     // _open _ioctl 
#include <fcntl.h>                  // _O_RDWR  _O_BINARY
#include <dev/usart.h>
#include <dev/board.h>              // NutRegisterDevice DEV_UART0
DEV_UART0_NAME UART_SET... DEV_DEBUG DEV_DEBUG_NAME
#include <sys/timer.h>              // for nutsleep

u_char msg1[] = "\r\nStart\r\n\0";
u_char msg2[] = "\r\nErr -1\r\n\0";
u_char msg3[] = "\r\nno char\r\n\0";

u_char buf[30];

int uartA, errorA=0,  countA=0;

void write_int (int x)
{
u_char buf2[30];

buf2[0] = x + '0';                  // make ASCII from binay 0..9
buf2[1] = ':';                      // add : to buffer
buf2[2] = ' ';                      // add space to buffer
_write (uartA, buf2, 3);            // display buffer
}   

int main(void) {
  u_long baudrate    = 115200 ;
  u_long localecho   = 0 ;
  u_long readtimeout = 1000L ;

  NutRegisterDevice (&DEV_UART0, 0, 0) ;      // defined in board.h to
devUsartAt910 if eth3

  uartA = _open (DEV_UART0_NAME, _O_RDWR | _O_BINARY) ;
  
  _ioctl (uartA, UART_SETSPEED,       &baudrate   ) ;
//_ioctl (uartA, UART_SETLOCALECHO,   &localecho   ) ;
//  _ioctl (uartA, UART_SETREADTIMEOUT, &readtimeout) ;  <--
included/excluded during the 2 tests

_write (uartA, msg1, 9);                      // display start msg

for (;;) {
   countA = _read (uartA, buf, 30);

   switch  (countA) {                         // display read result
   
      case -1:  _write (uartA, msg2, 10);  break;
      case  0:  _write (uartA, msg3, 11);  break;
      default: { 
         write_int (countA);                  // display read length
		 buf[countA] = '\r';          // append cr
         buf[countA+1] = '\n';                // lf
         _write (uartA, buf, countA+2);       // echo input data
         }
      }
  
   }
   
}

----------------------------------------------------------------------------
--------
Test 1:

Start  (with UART_SETREADTIMEOUT enabled, set to 1000L)

no char  <- timeout

no char  <- timeout

no char  <- timeout

no char  <- timeout
1: a     <- typeing rapidly (!) on the keyboard
1: s     <- typeing rapidly (!) on the keyboard
1: d     <- typeing rapidly (!) on the keyboard

no char

no char

no char


----------------------------------------------------------------------------
---------

Test2:

Start (without UART_SETREADTIMEOUT enabled)
1: t    <- typeing rapidly (!) on the keyboard
1: a    <- no timeout => not "no char" message
1: s
1: d
1: f
1: g
1: h
1: j
1: k
1: l
1: o
1: o
1: o


----------------------------------------------------------------------------
--------

-----Ursprüngliche Nachricht-----
Von: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] Im Auftrag von Markus Kohlhaupt
Gesendet: Donnerstag, 26. Oktober 2006 13:20
An: en-nut-discussion at egnite.de
Betreff: [En-Nut-Discussion] UART

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:

... source ...

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



_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.11/497 - Release Date: 25.10.2006



-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.11/497 - Release Date: 25.10.2006





More information about the En-Nut-Discussion mailing list