Serial with parity
Posted: Fri Feb 07, 2014 1:33 pm
Hi,
what is the right way to handle serial data with parity e.g. 7E1?
At least the STM32 UART peripherals don't mask out the parity bit of a received character
which means that i see "garbage" at the application level working on the BaseSequentialStream device.
When i do this on linux, the application doesn't see the parity bits. They are either not provided
by the hardware uart or masked out at the driver level.
A possible solution could look like this
Thanks and cheers,
Vinz
what is the right way to handle serial data with parity e.g. 7E1?
At least the STM32 UART peripherals don't mask out the parity bit of a received character
which means that i see "garbage" at the application level working on the BaseSequentialStream device.
When i do this on linux, the application doesn't see the parity bits. They are either not provided
by the hardware uart or masked out at the driver level.
A possible solution could look like this
Code: Select all
static void serve_interrupt(SerialDriver *sdp) {
<snip>
/* Data available.*/
chSysLockFromIsr();
while (sr & USART_SR_RXNE) {
/* Error condition detection.*/
if (sr & (USART_SR_ORE | USART_SR_NE | USART_SR_FE | USART_SR_PE))
set_error(sdp, sr);
uint16_t c = u->DR;
/* Mask parity bit according to configuration. */
switch (u->CR1 & (USART_CR1_PCE | USART_CR1_M))
{
case USART_CR1_PCE:
c &= 0x7f;
break;
case USART_CR1_PCE | USART_CR1_M:
c &= 0xff;
break;
default:
break;
}
sdIncomingDataI(sdp, c);
sr = u->SR;
}
chSysUnlockFromIsr();
<snip>
}
Thanks and cheers,
Vinz