This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Configuration of the 52840 UART peripheral for 7 bit transmission.

I am attempting to use the UART peripheral with a UART device which communicates via 1 start, 7 data, 1 even parity and 1 stop bits.

Is there any? way to configure  or fake the UART peripheral to shift 7 bits of data per transaction?

It doesn't appear that there is. It looks like the peripheral is going to shift out a byte of data at a time....

Kind Regards.

Parents
  • You would have to work in 8-bit no parity mode, then spoof the 8th bit as the required even parity for every single byte before transmitting the buffer. That can be done with a 128-byte lookup table which has a mask of the 8th parity bit which would be or'd with the data byte, so very fast.

    static const uint8_t EvenParityTable[128] =
        {0x00,     // 00   0000 0000  0
         0x80,     // 01   0000 0001  1
         0x80,     // 02   0000 0010  1
         0x00,     // 03   0000 0011  0
         0x80,     // 04   0000 0100  1
         0x00,     // 05   0000 0101  0
         0x00,     // 06   0000 0110  0
         0x80,     // 07   0000 0111  1
         ...
         
    TxChar must lie in range 0x00:0x7F (7-bits)
    
       TxChar |= EvenParityTable[TxChar];

  • I can see how this would work on the TX.

    Would it work on the RX?

    I could always just go null out the 8'th bit (the read in parity)....

    I wonder if the RX'ed stop would be messed.

    Edit. Now that I think about it. It would work. I just need to zero out the read in parity bit.

    Greatly! appreciated.

Reply Children
  • .. test the Rx parity bit first, using the same table:

    static const uint8_t EvenParityTable[128] =
        {0x00,     // 00   0000 0000  0
         0x80,     // 01   0000 0001  1
         0x80,     // 02   0000 0010  1
         0x00,     // 03   0000 0011  0
         0x80,     // 04   0000 0100  1
         0x00,     // 05   0000 0101  0
         0x00,     // 06   0000 0110  0
         0x80,     // 07   0000 0111  1
         0x80,     // 08   0000 1000  1
         0x00,     // 09   0000 1001  0
         0x00,     // 0A   0000 1010  0
         0x80,     // 0B   0000 1011  1
         0x00,     // 0C   0000 1100  0
         0x80,     // 0D   0000 1101  1
         0x80,     // 0E   0000 1110  1
         0x00,     // 0F   0000 1111  0
         ... etc
    TxChar must lie in range 0x00:0x7F (7-bits)
    
       // Send bytes
       TxChar |= EvenParityTable[TxChar];
       
       // Receive bytes
       RxChar = RawChar & 0x7F;
       // Check if parity different
       if ((RawChar & 0x80) ^ EvenParityTable[RxChar])
       {
          panic, parity failed
       }

Related