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

Klaus Kloos klaus.kloos at gmx.de
Mon Oct 24 20:00:48 CEST 2011


Hello Ole
> 
> 
>> 	    outr(PIOA_PDR, _BV(1));     	// PIO Disable Register
>> 	   zeichen = 0;
>> 	   gesendet = fwrite(&zeichen, 1, 1, dmxOut);			// Startcode=0
>> 
>> 	    gesendet = fwrite(buffer, 1, 512, dmxOut);
here is the 200us delay
>> 	    fflush(dmxOut);
>> 	    NutSleep(10);
> 
> After disabling the PIO, the UART will gain back the control. You will
> see the default UART output level, until the data transmissions starts.
> It might take additional time until the first data is send out, as some
> thread switching might be needed before.
> 

Ive seen this while debugging, but that not 200us.
There is new understanding on my side. The delay is coming from the fwrite(buffer, 1, 512, dmxOut). 
If I write all the bytes one by one there is no delay. Using fflush() after each byte or after the block, does no change this.

	    #define blockgroesse 1	// 2^n, works up to 4, 8 generates delays
	    for(lauf=0; lauf<512/blockgroesse; lauf++){
			gesendet = fwrite(&buffer[lauf*blockgroesse], 1, blockgroesse, dmxOut);
	    }
	    fflush(dmxOut);

This is a solution for my needs, but there seems to be a problem.

> So you might better want to implement the break function directly into
> the UART driver.
> 
I think thats beyond my possibilities at the moment. Ethernut  and even ARM is new for me. Where to start? Is there an example somewhere?

Thanks and greetings
Klaus


More information about the En-Nut-Discussion mailing list