Has anyone been able to configure for 7 data bits odd parity?
7 data bits, odd parity is required for operation with some existing equipment.
After reading through the RM and reading some answers on this site I thought I could use IO_IOCTL_SERIAL_SET_DATA_BITS to set for 8-bit mode (for 7 data bits and 1 parity bit) and IO_IOCTL_SERIAL_SET_PARITY to set parity to IO_SERIAL_PARITY_ODD. But - when trying to communicate with a port set like this, a PC terminal program shows garbage characters.
Stepping through the MQX code shows that in _kuart_polled_ioctl() - setting ODD parity also sets 9-bit mode: sci_ptr->C1 |= UART_C1_M_MASK;
The IO_IOCTL_SERIAL_SET_PARITY case from _kuart_polled_ioctl():
case IO_IOCTL_SERIAL_SET_PARITY:
switch (*param_ptr) {
case IO_SERIAL_PARITY_NONE:
/* disable parity only if enabled (once) */
if (sci_ptr->C1 & UART_C1_PE_MASK)
{
sci_ptr->C1 &= (~ (UART_C1_PE_MASK | UART_C1_PT_MASK));
/* disable parity bit */
if (sci_ptr->C4 & UART_C4_M10_MASK)
{
sci_ptr->C4 &= (~ UART_C4_M10_MASK);
}
else
{
sci_ptr->C1 &= (~ UART_C1_M_MASK);
}
}
break;
case IO_SERIAL_PARITY_ODD:
/* can't enable parity in 2 stop bits mode */
if (IO_SERIAL_STOP_BITS_1 != (io_info_ptr->FLAGS & IO_SERIAL_STOP_BITS_1))
{
return MQX_INVALID_CONFIGURATION;
}
/* if parity already enabled, just set the requested one */
if (sci_ptr->C1 & UART_C1_PE_MASK)
{
sci_ptr->C1 |= UART_C1_PT_MASK;
}
else
{
/* enable odd parity */
sci_ptr->C1 |= (UART_C1_PE_MASK | UART_C1_PT_MASK);
/* enable parity bit */
if (sci_ptr->C1 & UART_C1_M_MASK)
{
sci_ptr->C4 |= UART_C4_M10_MASK;
}
else
{
sci_ptr->C4 &= (~ UART_C4_M10_MASK);
sci_ptr->C1 |= UART_C1_M_MASK;
}
}
break;
case IO_SERIAL_PARITY_EVEN:
/* can't enable parity in 2 stop bits mode */
if (IO_SERIAL_STOP_BITS_1 != (io_info_ptr->FLAGS & IO_SERIAL_STOP_BITS_1))
{
return MQX_INVALID_CONFIGURATION;
}
/* if parity already enabled, just set the requested one */
if (sci_ptr->C1 & UART_C1_PE_MASK)
{
sci_ptr->C1 &= (~ UART_C1_PT_MASK);
}
else
{
/* enable even parity */
sci_ptr->C1 |= UART_C1_PE_MASK;
sci_ptr->C1 &= (~ UART_C1_PT_MASK);
/* enable parity bit */
if (sci_ptr->C1 & UART_C1_M_MASK)
{
sci_ptr->C4 |= UART_C4_M10_MASK;
}
else
{
sci_ptr->C4 &= (~ UART_C4_M10_MASK);
sci_ptr->C1 |= UART_C1_M_MASK;
}
}
break;
default:
return MQX_INVALID_PARAMETER;
}
break;
/* Message was edited by: Martin Kojtal */
Use C++ highlighter ( https://community.freescale.com/docs/DOC-94815). Thank you, c0170
Solved! Go to Solution.
Hello Allen Johnson-Weltzin,
have you check what configurations does your kinetis support?
I checked code and RM. Both seem to support 8 and 9 bit data bits plus parity. Not 7 data bits and parity. (RM - 51.4.4 Data format (non ISO-7816) from Kinetis k60).
Regards,
c0170
Hello Allen Johnson-Weltzin,
have you check what configurations does your kinetis support?
I checked code and RM. Both seem to support 8 and 9 bit data bits plus parity. Not 7 data bits and parity. (RM - 51.4.4 Data format (non ISO-7816) from Kinetis k60).
Regards,
c0170
Thanks for the help, Martin.
What I wound up doing is, when 7-even or 7-odd is needed, set for 8-bit mode and then manually set the most significant bit of the character being transmitted. For characters being received in 7-even or 7-odd I simply clear the most significant bit.
Also, thanks for the tip on code formatting in posts.
Regards,
Allen