#include <stdio.h>
Remember to include a terminating "\n" in your printf – stdout doesn't flush until it encounters one by default!!!!
printf("Hello world!\n");
printf("%i bytes read : %s\n", rx_length, rx_buffer);
printf("data_h: %02x\n", sensor_data_h);
printf format codes
d or i – int, decimal (base ten) number
x or X – int, hexadecimal number. Also "%02x" to specify length of digits
ld – long, decimal number ('l' can also be applied to any of the above to change the type from 'int' to 'long')
u – unsigned, decimal number
lu – unsigned long, decimal number
c – char, single character
s – char pointer, string
f – float, number with six digits of precision
g – float, number with up to six digits of precision
e – float, number with up to six digits of precision, scientific notation
lf – double, number with six digits of precision
lg – double, number with up to six digits of precision
le – double, number with up to six digits of precision, scientific notation
Display Buffer
//************************************
//************************************
//********** DISPLAY BUFFER **********
//************************************
//************************************
static void display_buffer (uint8_t* buffer, int len)
{
int count;
for (count = 0; count < len; count++)
{
printf("%02x ", buffer[i]);
if (( count + 1 ) % 16 == 0)
{
printf("\n");
}
}
printf("\n");
}
printf in a multi thread environment
Watch out for clashes causing bugs! This can happen with irq's using printf, different threads using it, etc.
Using a semaphore to proect
This is one option to stop clahses, e.g.
#include "semphr.h"
//Create semphore
SemaphoreHandle_t print_semaphore = NULL;
print_semaphore = xSemaphoreCreateMutex();
//Use sempahore
xSemaphoreTake(print_semaphore, portMAX_DELAY);
printf("Something");
printf("Something");
xSemaphoreGive(print_semaphore);