[En-Nut-Discussion] RS485 on NutOS

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


Hi,

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
 */
INTERRUPT(SIG_UART1_RECV)
{
  // read the character
  serinbuffer[(int)serinin]=UDR1;
  serinin++;
  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;
 ch=serinbuffer[(int)serinout];
 serinout++; if (serinout>sizeof(serinbuffer)) serinout=0;
 return ch;
}

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

    for (;;)
    {
        NutThreadSetPriority(64);
     // 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);
        }

        NutThreadSetPriority(128);
        NutThreadYield();
    }
}


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

Thorsten





More information about the En-Nut-Discussion mailing list