I've been playing with this library.
But I have some problem that I do not yet understand. I want to include a printf to display the values of sensors. And this is the problem.
I use an example from the library: avr4g2_8qt_example.
Apparantly it works since I get a signal on the debug lines (actually port C1/C0).
Now I add the following routine to the code
#include "touch_api_atmega168.h" #include#include #include #include #include #include "rs232-t.h" //Define functions for rs232 //====================== void ioinit(void); // initializes IO static int uart_putchar(char c, FILE *stream); // stream based i/o. used for printf and scanf static int uart_getchar(FILE *stream); uint8_t uart_get_c(void); // gets ascii character static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW); void ioinit (void) { // set default baud rate UART0_UBRR_HIGH = (UART_BAUD_SELECT >> 8); UART0_UBRR_LOW = UART_BAUD_SELECT; #if defined (ATMEGA_USART) // enable receive, transmit and ensable receive interrupts UART0_CONTROL = (1<<RXEN)|(1<<TXEN)|(1<<RXCIE); // set default format, asynch, n,8,1 #ifdef URSEL UCSRC = (1<<URSEL)|(3<<UCSZ0); #else UCSRC = (3<<UCSZ0); #endif #elif defined (ATMEGA_USART0 ) // enable receive, transmit and ensable receive interrupts UART0_CONTROL = (1<<RXEN0)|(1<<TXEN0)|(1<<RXCIE0); #endif stdout = stdin = &mystdout; //Required for printf init } static int uart_putchar(char c, FILE *stream) { if (c == '\n') uart_putchar('\r', stream); loop_until_bit_is_set(UCSR0A, UDRE0); UDR0 = c; return 0; } static int uart_getchar(FILE *STREAM) { while( !(UCSR0A & (1<<RXC0)) ); return(UDR0); } uint8_t uart_get_c(void) { while( !(UCSR0A & (1<<RXC0)) ); return(UDR0); }
and using the rs232-t.h file:
#define sbi(var, mask) ((var) |= (uint8_t)(1 << mask)) #define cbi(var, mask) ((var) &= (uint8_t)~(1 << mask)) #define STATUS_LED 0 // requires the constant F_CPU to be set to the frequency of the CPU crystal #if !defined F_CPU #error Constant F_CPU not set ! #endif #if defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) || \ defined(__AVR_ATmega32__) || defined(__AVR_ATmega8515__) || \ defined(__AVR_ATmega8535__) || defined(__AVR_ATmega323__) // // Single USART devices // #define ATMEGA_USART #define UART0_UBRR_HIGH UBRRH #define UART0_UBRR_LOW UBRRL #define UART0_RECEIVE_INTERRUPT SIG_UART_RECV #define UART0_TRANSMIT_INTERRUPT SIG_UART_DATA #define UART0_STATUS UCSRA #define UART0_CONTROL UCSRB #define UART0_DATA UDR #define UART0_UDRIE UDRIE #elif defined(__AVR_ATmega168__) #define ATMEGA_USART0 #define UART0_UBRR_HIGH UBRR0H #define UART0_UBRR_LOW UBRR0L #define UART0_RECEIVE_INTERRUPT SIG_USART_RECV #define UART0_TRANSMIT_INTERRUPT SIG_USART_DATA #define UART0_STATUS UCSR0A #define UART0_CONTROL UCSR0B #define UART0_DATA UDR0 #define UART0_UDRIE UDRIE0 #elif defined(__AVR_ATmega644__) #define ATMEGA_USART0 #define UART0_UBRR_HIGH UBRR0H #define UART0_UBRR_LOW UBRR0L #define UART0_RECEIVE_INTERRUPT SIG_USART_RECV #define UART0_TRANSMIT_INTERRUPT SIG_USART_DATA #define UART0_STATUS UCSR0A #define UART0_CONTROL UCSR0B #define UART0_DATA UDR0 #define UART0_UDRIE UDRIE0 #elif defined(__AVR_ATmega162__) || \ defined(__AVR_ATmega64__) || \ defined(__AVR_ATmega128__) // // Dual USART devices // #define ATMEGA_USART0 #define UART0_UBRR_HIGH UBRR0H #define UART0_UBRR_LOW UBRR0L #define UART0_RECEIVE_INTERRUPT SIG_USART0_RECV #define UART0_TRANSMIT_INTERRUPT SIG_USART0_DATA #define UART0_STATUS UCSR0A #define UART0_CONTROL UCSR0B #define UART0_CONTROL2 UCSR0C #define UART0_DATA UDR0 #define UART0_UDRIE UDRIE0 #define ATMEGA_USART1 #define UART1_UBRR_HIGH UBRR1H #define UART1_UBRR_LOW UBRR1L #define UART1_RECEIVE_INTERRUPT SIG_USART1_RECV #define UART1_TRANSMIT_INTERRUPT SIG_USART1_DATA #define UART1_STATUS UCSR1A #define UART1_CONTROL UCSR1B #define UART1_CONTROL2 UCSR1C #define UART1_DATA UDR1 #define UART1_UDRIE UDRIE1 #else // // unsupported type // #error "Processor type not supported in uart.c !" #endif // // UART Default Baud rate calculation // #define UART_BAUD_RATE 115200 // On some computers this introduces errors. // Too fast to receive. perhaps a jumper/test on the atmega and using setspeed? // #define U2X 0 // not using u2x // u2x0 for atmega644 #define USING_U2X0 (F_CPU < 2000000ul && defined(U2X0)) #define BAUD_DIV (USING_U2X0? 8: 16) #define UART_BAUD_SELECT (((F_CPU + (UART_BAUD_RATE) * (BAUD_DIV / 2)) / ((UART_BAUD_RATE) * BAUD_DIV) - 1))
it still puts debug data on my C1/C0 port.
but if I add a printf statement, the output stops. I also do not get a proper output from the printf.
Now this is bothering me since the code stops completely.
Anyone idea's?