Go Down

Topic: Yet another printf() hack (Read 934 times) previous topic - next topic

salvarsan

The avr-gcc stdio.h gives specific advice.
printf() needs a valid stdout descriptor,
which needs a generic  putc() function.
Code: [Select]
// ---- place globally,  above setup() ---

FILE serialStdout = {0} ;

static int uart_write(char c, FILE *stream)
{
  loop_until_bit_is_set(UCSR0A, UDRE0) ;
  UDR0 = c;
  return 0;
}//end of global stuff

// ---- place after Serial.begin() invocation  ----

  /* fill in the FILE structure  */
  fdev_setup_stream( &serialStdout, uart_write,
                           NULL,_FDEV_SETUP_WRITE);

  /* reassign stdout */
  stdout = &serialStdout ;

  /* ... and test the result */
  printf("stdout's address is %p\n", stdout) ;


bon appetit.



Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy