Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Teensy 4.1 serial port polarity invert?

  1. #1
    Junior Member
    Join Date
    Oct 2020
    Location
    Tucson, AZ, USA
    Posts
    3

    Teensy 4.1 serial port polarity invert?

    Hi.

    I am working on a system with the Teensy 4.1, and I was wondering if the INVERT function is supported as it is on the 3.X series. The Web page on serial ports seems to indicate that it is not, or maybe it's done in a different way.

    I can build in an inverter for my hardware if need be, but it's obviously better to use the internal inverter if there is one.

    Thanks!

    John

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,889
    The simple answer is it should be there:
    We do have it defined in the header file:
    Code:
    #define SERIAL_7E1 0x02
    #define SERIAL_7O1 0x03
    #define SERIAL_8N1 0x00
    #define SERIAL_8E1 0x06
    #define SERIAL_8O1 0x07
    #define SERIAL_7E1_RXINV 0x12
    #define SERIAL_7O1_RXINV 0x13
    #define SERIAL_8N1_RXINV 0x10
    #define SERIAL_8E1_RXINV 0x16
    #define SERIAL_8O1_RXINV 0x17
    #define SERIAL_7E1_TXINV 0x22
    #define SERIAL_7O1_TXINV 0x23
    #define SERIAL_8N1_TXINV 0x20
    #define SERIAL_8E1_TXINV 0x26
    #define SERIAL_8O1_TXINV 0x27
    #define SERIAL_7E1_RXINV_TXINV 0x32
    #define SERIAL_7O1_RXINV_TXINV 0x33
    #define SERIAL_8N1_RXINV_TXINV 0x30
    #define SERIAL_8E1_RXINV_TXINV 0x36
    #define SERIAL_8O1_RXINV_TXINV 0x37
    #ifdef SERIAL_9BIT_SUPPORT
    #define SERIAL_9N1 0x84
    #define SERIAL_9E1 0x8E
    #define SERIAL_9O1 0x8F
    #define SERIAL_9N1_RXINV 0x94
    #define SERIAL_9E1_RXINV 0x9E
    #define SERIAL_9O1_RXINV 0x9F
    #define SERIAL_9N1_TXINV 0xA4
    #define SERIAL_9E1_TXINV 0xAE
    #define SERIAL_9O1_TXINV 0xAF
    #define SERIAL_9N1_RXINV_TXINV 0xB4
    #define SERIAL_9E1_RXINV_TXINV 0xBE
    #define SERIAL_9O1_RXINV_TXINV 0xBF
    #endif
    // We have 1/2 bit stop setting
    #define SERIAL_2STOP_BITS 0x100
    #define SERIAL_8E2 (SERIAL_8E1 | SERIAL_2STOP_BITS)
    #define SERIAL_8O2 (SERIAL_8O1 | SERIAL_2STOP_BITS)
    #define SERIAL_8E2_RXINV (SERIAL_8E1_RXINV | SERIAL_2STOP_BITS)
    #define SERIAL_8O2_RXINV (SERIAL_8O1_RXINV | SERIAL_2STOP_BITS)
    #define SERIAL_8E2_TXINV (SERIAL_8E1_TXINV | SERIAL_2STOP_BITS)
    #define SERIAL_8O2_TXINV (SERIAL_8O1_TXINV | SERIAL_2STOP_BITS)
    #define SERIAL_8E2_RXINV_TXINV (SERIAL_8E1_RXINV_TXINV | SERIAL_2STOP_BITS)
    #define SERIAL_8O2_RXINV_TXINV (SERIAL_8O1_RXINV_TXINV | SERIAL_2STOP_BITS)
    #define SERIAL_8N2 (SERIAL_8N1 | SERIAL_2STOP_BITS)
    #define SERIAL_8N2_RXINV (SERIAL_8N1_RXINV | SERIAL_2STOP_BITS)
    #define SERIAL_8N2_TXINV (SERIAL_8N1_TXINV | SERIAL_2STOP_BITS)
    #define SERIAL_8N2_RXINV_TXINV (SERIAL_8N1_RXINV_TXINV | SERIAL_2STOP_BITS)
    // bit0: parity, 0=even, 1=odd
    // bit1: parity, 0=disable, 1=enable
    // bit2: mode, 1=9bit, 0=8bit
    // bit3: mode10: 1=10bit, 0=8bit
    // bit4: rxinv, 0=normal, 1=inverted
    // bit5: txinv, 0=normal, 1=inverted
    // bit6: unused
    // bit7: actual data goes into 9th bit
    It has been awhile since I played with it... So you might give it a try.

    Which reminds me, I still have some Pull Requests to check on

  3. #3
    Junior Member
    Join Date
    Oct 2020
    Location
    Tucson, AZ, USA
    Posts
    3
    Thanks! I noticed that the hardware supports it. I'll give it a try.

    John

  4. #4
    Member JaredReabow's Avatar
    Join Date
    May 2020
    Location
    oxford , UK
    Posts
    74
    mind telling a noob what inverting the serial port does?

  5. #5
    Senior Member
    Join Date
    Jul 2020
    Posts
    913
    It inverts the logic. LOW<->HIGH. Standard serial uses HIGH for 'space', LOW for 'mark', and idles HIGH.

  6. #6
    Junior Member
    Join Date
    Oct 2020
    Location
    Tucson, AZ, USA
    Posts
    3
    Yes, as Mark says. In my case, I am dealing with some custom fiber-optic transmitter/receivers that invert the signal, and I wondered if I have to continue with that or if I could invert the signal inside the chip so that I could maybe use a standard fiber optic transmitter on one end and keep the inverting one on the other end. I've got a teensy 4.1 on order, so we soon shall see!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •