Understanding the sprintf function
I want to transmit a variable over UART and also LCD, the UART is a generated function with argument of uint8_t, the data i need to transmit is both signed and unsigned and it is 16 bit. How do i transmit the signed value if the argument is unsigned value?
Code:
void USARTWrite(uint8_t txData)
{
}
My array is of size of 100 of bit16. To transmit the data i have used the sprintf function and i have made mistake in that as well. I have written something like this
Code:
void Send(int16_t a_data_s16)
{
int16_t l_buffer_a[10];
uint8_t l_index_u8=0;
sprintf(l_buffer_a,"%d",a_data_s16);
while(l_buffer_a[l_index_u8] != 0)
{
USARTWrite((uint8_t)l_buffer_a[l_index_u8]);
l_index_u8++;
}
}
I realized that int sprintf(char *str, const char *string,...);
, so i made a mistake of making it as int16_t. I have completely messed up all the code. What is the best approach now. Please help.