Hallo everyone, I have a function to read the data from the uart, which is :
void serial_read_appConfig(uint8_t *buffer, uint8_t noOfBytes)
{
uint8_t i = 0;
uint8_t temp = 0, rxDec;
while (i != noOfBytes*2)
{
rxDec = asciiToDecConverter(sio2host_getchar());
if (i%2 == 0) temp = rxDec << 4;
else if (i%2 != 0) buffer[i/2] = temp + rxDec;
if (rxDec != 255) i++; }
}
uint8_t asciiToDecConverter(uint8_t input)
{
uint8_t decVal = -1;
if (input >= 48 && input <= 57) decVal = input - 48; else if (input >= 65 && input <= 70) decVal = input - 55; else if (input >= 97 && input <= 102) decVal = input - 87; return decVal;
}
What I have tried:
How can i similarly write a function to write a buffer to the uart
I am not able to understand the while loop return in the program,
Also the function getchar has a return value.
But the function to read putchar has no return value.
void sio2host_putchar(uint8_t ch)
{
sio2host_tx(&ch, 1);
}
uint8_t sio2host_getchar(void)
{
uint8_t c;
while (0 == sio2host_rx(&c, 1)) {
}
return c;
}
I have a function to convert the value from
Dectoasciiconverter(char ch);
But i am not able to figure out , how to wite a function such as
serial_write_app_config().
if anyone has an idea, kindly provide suggestions on how to write the function.
It would be great helpful
Cheers!