Parity bit
Posted: Wed Apr 08, 2026 4:31 am
Hi
Tuss4470 IC uses SPI to communicate with the Master.
Data format: (Reading the register)
msb = 1 r/w bit + 6 regi-addr bits + parity bit
lsb = 0x00
Odd parity bit should be calculated.
The open source project uses the next:
byte tuss4470Parity(byte* spi16Val)
{
return parity16(BitShiftCombine(spi16Val[0], spi16Val[1]));
}
unsigned int BitShiftCombine(unsigned char x_high, unsigned char x_low) {
return (x_high << 8) | x_low; // Combine high and low bytes
}
byte parity16(unsigned int val) {
byte ones = 0;
for (uint8_t i = 0; i < 16; i++) {
if ((val >> i) & 1) {
ones++;
}
}
return (ones + 1) % 2; // Odd parity calculation
}
Is it possible to calculate the parity bit for msb only (as the lsb = 0x00)?
Is it better to calculate the parity bit for integer (msb << 8) + lsb ?
Thanks
Tuss4470 IC uses SPI to communicate with the Master.
Data format: (Reading the register)
msb = 1 r/w bit + 6 regi-addr bits + parity bit
lsb = 0x00
Odd parity bit should be calculated.
The open source project uses the next:
byte tuss4470Parity(byte* spi16Val)
{
return parity16(BitShiftCombine(spi16Val[0], spi16Val[1]));
}
unsigned int BitShiftCombine(unsigned char x_high, unsigned char x_low) {
return (x_high << 8) | x_low; // Combine high and low bytes
}
byte parity16(unsigned int val) {
byte ones = 0;
for (uint8_t i = 0; i < 16; i++) {
if ((val >> i) & 1) {
ones++;
}
}
return (ones + 1) % 2; // Odd parity calculation
}
Is it possible to calculate the parity bit for msb only (as the lsb = 0x00)?
Is it better to calculate the parity bit for integer (msb << 8) + lsb ?
Thanks