2022-08-03 02:29 AM
"I'll delete this question once someone answers it, as it is not relevant".
Why in second line did some one write ch & 0xFF? ch limits are already 0 to 255 right?
Solved! Go to Solution.
2022-08-03 06:14 AM
The copy-n-paste coder here took code that use int originally for the parameter/return and changed it to a uint8_t
Classically C libraries have returned negative values for failure around STDIO routines.
The TDR here is 16-bit wide as the U(S)ART support 9-bit values. When reading RDR and using parity, the code needs to strip the parity bit manually/
2022-08-03 05:27 AM
Maybe because function content was copy pasted from elsewhere which ch may not have been uint8_t. Anyway, compiler are not dumb, they will optimise this, no sweat.
2022-08-03 05:33 AM
You're right. The &0xFF is useless here.
hth
KnarfB
2022-08-03 06:14 AM
The copy-n-paste coder here took code that use int originally for the parameter/return and changed it to a uint8_t
Classically C libraries have returned negative values for failure around STDIO routines.
The TDR here is 16-bit wide as the U(S)ART support 9-bit values. When reading RDR and using parity, the code needs to strip the parity bit manually/
2022-08-03 06:16 PM
I'm new to C programming, development and not very confident but after few months (till today) I got used to programming and sometime still don't feel 100% confident, don't know why! But i feel that this emotion will be gone gradually.