[En-Nut-Discussion] RS485 on NutOS

Hugo Simon hugo.simon at gmx.de
Wed Oct 24 22:41:17 CEST 2007


I now put my mega16 RS485 routines on the Ethernut using NutOS. I use native
interrupts but I don't get a good receiving. There are crumbled or lost
characters, even if I transmit with large gaps between the characters. Do I
have to disable the NutOS Usart1 driver somehow?

My simple receive test routine is like this, the debug-Stream is routed to
UART0 in main:

FILE *debug = NULL;
T_PACKET *rcv_buffer;
u_char RS485MyAddr=0x11;
volatile unsigned char serinbuffer[32];     // serial input buffer
volatile char serinin,serinout;   // serial buffer pointer

 * serial receive isr
  // read the character
  if (serinin>sizeof(serinbuffer)) serinin=0;

 * read serial character
int UartGetChar(int timeout)
 unsigned char ch;
 while ((serinin==serinout) && timeout) timeout--;
 if (serinin==serinout) return -1;
 serinout++; if (serinout>sizeof(serinbuffer)) serinout=0;
 return ch;

 * From RS485 receiver thread
THREAD(RS485Receiver, arg)
 int ch;

    for (;;)
     // read a character from RS485
//        if ((cnt = fread(&buffer, 1, 1, RS485)) > 0) // this works using
NutOS drivers

        if ((ch=UartGetChar(0)) >= 0)
         if (debug) fprintf(debug,"%02X ",ch);


Thank you for any hints. I am lost at the moment.


More information about the En-Nut-Discussion mailing list