Tool/software: TI-RTOS
dear All:
I want to use Even or Odd Parity when use UART emulator example in sensor controller ,but i don't find any config settings in GUI and source code,do someone can tell me how to set,thanks !
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI-RTOS
dear All:
I want to use Even or Odd Parity when use UART emulator example in sensor controller ,but i don't find any config settings in GUI and source code,do someone can tell me how to set,thanks !
Hello Jinlong,
You will have to use 7 bits +1 parity bit to form a unsigned char that you send with the standard framework.
https://en.wikipedia.org/wiki/Parity_bit
Here is an idea I made on the fly on how to add an even parity bit. I have not tested this and I have not considered UART transmission endianess (LSB/MSB), I leave that for you to figure out.
const unsigned char oneBits[] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4}; unsigned char appendEvenParity(unsigned char x) { unsigned char nuOfOnes; unsigned char result; // Count ones in 7-bit data (remove MSb) nuOfOnes = oneBits[x&0x0f]; nuOfOnes += oneBits[((x>>4)&0x07)]; // left-shift the 7 Least significant bits and add 0 parity bit. result = x << 1; if(nuOfOnes%2) { // add parity bit (1) as there are odd number of ones in x. result |= 0x01; } return results; }