Go Down

Topic: Yet another printf() hack (Read 1 time) previous topic - next topic


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,

  /* 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!

via Egeo 16
Torino, 10131