[En-Nut-Discussion] problem using fflush()

Klaus Kloos klaus.kloos at gmx.de
Sat Oct 22 09:32:38 CEST 2011


Hello

Im on a SAM7-EK using ethernut 4.10rc1
For sending DMX (250k, 8N2) I need to send a 0x00 at 9600 baud (Reset), then switch to 250kbaud and send the frame.
After sending with 9600 I use fflush(), but its not working as (I) expected.

Here the initialization

    NutRegisterDevice(&DEV_UART, 0, 0);
    /* Setup the uart device. */
    FILE* test = fopen(DEV_UART_NAME, "w");
    uint32_t wert = 250000;
    _ioctl(_fileno(test), UART_SETSPEED, &wert);
    wert = 2;
    _ioctl(_fileno(test), UART_SETSTOPBITS, &wert);
...

and the point of interest:

		wert = 9600;
		_ioctl(_fileno(test), UART_SETSPEED, &wert);

		unsigned char zeichen =0;
		gesendet = fwrite(&zeichen, 1, 1, test);			// 0 bei 9600 = break condition
		result = fflush(test);
// setting a breakpoint here gives a correct output, without breakpoint the byte is not send at 9600 and the result is not firm. 1 or 2 bits can be seen on the scope
		wert = 250000;
		_ioctl(_fileno(test), UART_SETSPEED, &wert);

		gesendet = fwrite(&zeichen, 1, 1, test);			// Startcode=0
		result = fflush(test);
...

Breaking at the function UsartFlushOutput() the  while (rc > left) part nether gets called. The buffer is empty, the send-byte is in the UART, ready to send but not gone (I think).
Calling _ioctl() leads to At91UsartSetSpeed() where the UART is disabled (without sending the byte).

What do I have to do for waiting until the sending of the 9600-byte is completed?
Do I have another possibility to control the UART-output directly, so the switching to 9600 will not be neccessary and I generate the Reset by hand?

Many thanks in avance.

Greetings Klaus 








More information about the En-Nut-Discussion mailing list