I tried this too to connect the serial device to the USB UART
Hi,
I am wondering if there is something special that I need to do to get fprintf to work on the Teensy3.1. If I use fprintf anywhere in the program in hangs the program. e.g. fprintf(stderr, "Test"); Do I need to redirect the stderr to the Teensy Serial port? The code base I am using was ported from an Arduino Due and it worked there. Any thoughts most welcome.
Cheers /DD
I tried using this example from the Arduino site and this will compile with the Teensy2.0 but not with Teensy 3.0 or 3.1. This attaches the file output to the serial device. While the hardware is quite different not sure why it cant find the [FONT=Arial [U]fdev_setup_stream[/U] function, Cheers /DD
// we need fundamental FILE definitions and printf declarations
#include <stdio.h>
// create a FILE structure to reference our UART output function
static FILE uartout = {0} ;
// create a output function
// This works because Serial.write, although of
// type virtual, already exists.
static int uart_putchar (char c, FILE *stream)
{
Serial.write(c) ;
return 0 ;
}
void setup(void)
{
// Start the UART
Serial.begin(9600) ;
// fill in the UART file descriptor with pointer to writer.
fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
// The uart is the standard output device STDOUT.
stdout = &uartout ;
}
void loop(void)
{
float seconds ;
// wait 1000 milliseconds
delay(1000) ;
// calculate seconds as a floating point value
seconds = (float) millis() /1000.0 ;
// report seconds since starting
printf("Alive %.3f sec", seconds ) ;
/*
// without printf(), you would do this:
Serial.print("Alive ") ;
Serial.print(seconds,3) ;
Serial.print("sec") ;
*/
#if 0
// you can explicitly use a FILE structure like this:
fprintf( &uartout, "Alive %.3f sec", seconds ) ;
#endif
}