Solution for getting printf working with DAVE4.1.2 and XMC1100 (xmc2go)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
This is what worked for me to get printf working with DAVE4.1.2 and XMC1100 (xmc2go).
If anyone has a better solution - please post it here...


/* This "wires" the putchar/printf functions to transmit to UART_0 */
int _write(int file, uint8_t *buf, int nbytes)
{
if(UART_Transmit(&UART_0, buf, nbytes) == UART_STATUS_SUCCESS) {
while(UART_0.runtime->tx_busy) {
}
}
return nbytes;
}

/* This "wires" the getchar function to receive from UART_0 */
int _read(int file, uint8_t *buf, int nbytes)
{
if(UART_Receive(&UART_0, buf, 1) != UART_STATUS_SUCCESS) {
nbytes = 0;
} else {
nbytes = 1;
}
return nbytes;
}


best regards,
Tom Moxon
www.patternagents.com
@PatternAgents
0 Likes
3 Replies
Not applicable
Hi Tom,

how can I print an ADC value using this function?

thanks in advance,
0 Likes
WilhelmBrezovit
Employee
Employee
First solution authored Welcome! 10 replies posted
Dear Alen,

use sprintf - for example:

void main(void)
{
char mb[200]; // message buffer for sprintf()
int dummy;

sprintf(mb,"Variable wait = %d",dummy); // Write formatted data to string mb
myprintf(mb);
}



All the best,
Wilhelm
0 Likes
Not applicable
Hi Wilhelm,

I am new to C, do I have to create my own header file and name it myprintf and put those two write and read functions in it and use your example in my project, is this correct?
and for example how do you select between Uart0_Ch0 or Uart0_Ch1 ,Uart1_Ch0 and etc.? in my project I am using UART0_CH1

thanks in advance,
0 Likes