AnsweredAssumed Answered

Does MQX 4.0 support configuring a UART for 7 data bits, odd parity?

Question asked by gorakk on Jul 5, 2013
Latest reply on Jul 8, 2013 by gorakk

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

Outcomes