LIN bus

 s this possible do LIN  with NRF5340 (uart) hardware and software wise

  • Here are a couple of replies I made which include using PWM for Tx:

    how-to-get-more-than-2-uart-s

    pwm-sequence-from-hal-to-nrfx

    Here's a 2-byte 10-bit frame; any number of bits can be used simply by changing the table:

    // Example using grouped, note uses pin channels 0 and 2 not 0 and 1
    nrf_pwm_values_grouped_t halfDuplexUartMsg[] = {
      //   Index   Normal pin 0        Inverted pin 2
      //   =====   =================== ==============
      { /* 0:0  */ 0x8000|(BIT_LOW),   (BIT_LOW),  }, // Start bit
      { /* 0:1  */ 0x8000|(STX_BIT_0), (STX_BIT_0) },
      { /* 0:2  */ 0x8000|(STX_BIT_1), (STX_BIT_1) },
      { /* 0:3  */ 0x8000|(STX_BIT_2), (STX_BIT_2) },
      { /* 0:4  */ 0x8000|(STX_BIT_3), (STX_BIT_3) },
      { /* 0:5  */ 0x8000|(STX_BIT_4), (STX_BIT_4) },
      { /* 0:6  */ 0x8000|(STX_BIT_5), (STX_BIT_5) },
      { /* 0:7  */ 0x8000|(STX_BIT_6), (STX_BIT_6) },
      { /* 0:8  */ 0x8000|(STX_BIT_7), (STX_BIT_7) },
      { /* 0:9  */ 0x8000|(BIT_HIGH),  (BIT_HIGH), }, // Stop bit 1
    
      { /* 1:0  */ 0x8000|(BIT_LOW),   (BIT_LOW),  }, // Start bit
      { /* 1:1  */ 0x8000|(ETX_BIT_0), (ETX_BIT_0) },
      { /* 1:2  */ 0x8000|(ETX_BIT_1), (ETX_BIT_1) },
      { /* 1:3  */ 0x8000|(ETX_BIT_2), (ETX_BIT_2) },
      { /* 1:4  */ 0x8000|(ETX_BIT_3), (ETX_BIT_3) },
      { /* 1:5  */ 0x8000|(ETX_BIT_4), (ETX_BIT_4) },
      { /* 1:6  */ 0x8000|(ETX_BIT_5), (ETX_BIT_5) },
      { /* 1:7  */ 0x8000|(ETX_BIT_6), (ETX_BIT_6) },
      { /* 1:8  */ 0x8000|(ETX_BIT_7), (ETX_BIT_7) },
      { /* 1:9  */ 0x8000|(BIT_HIGH),  (BIT_HIGH), }, // Stop bit 1
    };
    

    Sample encoding, normal or Manchester:

    #define BIT_LOW               0           // Normal encoding
    #define BIT_HIGH    (COUNTER_TOP)         // Normal encoding
    //#define BIT_LOW   ((2*COUNTER_TOP)/3)   // Manchester encoding 2/3 bit
    //#define BIT_HIGH  (COUNTER_TOP/3)       // Manchester encoding 1/3 bit
    #define PWM_NEG (PIN_FEATHER_D6)          // Low level outside transmission
    #define PWM_POS (PIN_FEATHER_D9)          // High level outside transmission
    #define STX_BYTE 0x02 // Example start character: STX (^B)
    #define ETX_BYTE 0x03 // Example start character: ETX (^C)
    
    // Example STX byte in little-endian format
    #define STX_BIT_0 (((STX_BYTE>>0) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define STX_BIT_1 (((STX_BYTE>>1) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define STX_BIT_2 (((STX_BYTE>>2) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define STX_BIT_3 (((STX_BYTE>>3) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define STX_BIT_4 (((STX_BYTE>>4) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define STX_BIT_5 (((STX_BYTE>>5) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define STX_BIT_6 (((STX_BYTE>>6) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define STX_BIT_7 (((STX_BYTE>>7) & 0x01) ? BIT_HIGH : BIT_LOW)
    // Example ETX byte in little-endian format
    #define ETX_BIT_0 (((ETX_BYTE>>0) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define ETX_BIT_1 (((ETX_BYTE>>1) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define ETX_BIT_2 (((ETX_BYTE>>2) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define ETX_BIT_3 (((ETX_BYTE>>3) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define ETX_BIT_4 (((ETX_BYTE>>4) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define ETX_BIT_5 (((ETX_BYTE>>5) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define ETX_BIT_6 (((ETX_BYTE>>6) & 0x01) ? BIT_HIGH : BIT_LOW)
    #define ETX_BIT_7 (((ETX_BYTE>>7) & 0x01) ? BIT_HIGH : BIT_LOW)
    

Related