[En-Nut-Discussion] UART Problems

Manuel Mausz manuel at mausz.at
Fri Jan 2 18:59:14 CET 2004


Hi,

I have a problem with the UART1 device. my program opens the device like the
example uart.c and sends everything very well but recieves the buffer from
the last execution!

example:
#1 - first i reset the ethernut board
#2 - i send a string from the uart1 of the ethernut board to the device on
the other side which returns it immediately. (_write)
#3 - i recieve an emtpy string. (_read)
#4 - i send another string
#5 - i recieve the returned string from the first transmission

---------

The main code is from the httpserv.c. i have only copyied my modifications.

FILE *uart2;

int main(void) {
  ...
  u_long baud2 = 38400;
  /*
  * Initialize the uart1 device.
  */
  NutRegisterDevice(&devUart1, 0, 0);
  uart2 = fopen("uart1", "r+");
  _ioctl(_fileno(uart2), UART_SETSPEED, &baud2);
  _read(_fileno(uart2), 0, 0);
  NutSleep(200);
  ...
}

static int nLQuery(FILE *stream, REQUEST *req)
{
    int buf;
    char inbuf[11];
    int i;
    char *send_string = "\x01\0x36\x06";

    fflush(uart2);

    _write(_fileno(uart2), send_string, strlen(send_string));
    _write(_fileno(uart2), 0, 0);

    NutSleep(60);
    buf = _read(_fileno(uart2), inbuf, sizeof(inbuf));

    // print the recieved bytes to the uart1 for debugging
    for (i=0; i < strlen(inbuf); i++) {
        printf("%x-", inbuf[i]);
    }
    printf("\n");

    NutHttpSendHeaderTop(stream, req, 200, "Ok");
    NutHttpSendHeaderBot(stream, "text/html", -1);

    // print the recieved bytes to the httpd
    if(req->req_query) {
        fputs(inbuf, stream);
    }
    else
        fputs("None", stream);
    fflush(stream);

    return 0;
}

hopefully somebody can give me a hint. but i wish everyone a happy new year
:-)

Regards
Manuel Mausz








More information about the En-Nut-Discussion mailing list