LIN bus - USART flags and errors

please see reference like electric imp uart flags

Can you explain more please - why are you directing us to that resource?

Sorry for the short post.

the reason for my request is that I am using a transceiver to convert LINBUS protocol to serial, the problem is that the protocol has break signal that is 13 bit, witch creates a framing error, but the serial library in particle , doesn’t have a way to detect that condition, I am trying the electric imp and seems to handle that condition better.

Thanks for any guidance.

Or how can I detect the 13 bit on the particle?

@BDub - any thoughts on this?

Since the STM32F2XX supports LIN mode on the USART interface, we could provide an API to enable this, and set 13 bit break generation or 10/11 bit break detection. That should give you a more reliable way to detect LIN breaks than polling for framing errors. Would that work for your situation? Are you currently polling for a framing error and then throwing away the last byte received or something else?

Here’s some LIN description from the STM32F2XX STD Peripheral Driver library:

===============================================================================
                                LIN mode functions
 ===============================================================================

  This subsection provides a set of functions allowing to manage the USART LIN
  Mode communication.

  In LIN mode, 8-bit data format with 1 stop bit is required in accordance with
  the LIN standard.

  Only this LIN Feature is supported by the USART IP:
    - LIN Master Synchronous Break send capability and LIN slave break detection
      capability :  13-bit break generation and 10/11 bit break detection


  USART LIN Master transmitter communication is possible through the following procedure:
     1. Program the Baud rate, Word length = 8bits, Stop bits = 1bit, Parity,
        Mode transmitter or Mode receiver and hardware flow control values using
        the USART_Init() function.
     2. Enable the USART using the USART_Cmd() function.
     3. Enable the LIN mode using the USART_LINCmd() function.
     4. Send the break character using USART_SendBreak() function.

  USART LIN Master receiver communication is possible through the following procedure:
     1. Program the Baud rate, Word length = 8bits, Stop bits = 1bit, Parity,
        Mode transmitter or Mode receiver and hardware flow control values using
        the USART_Init() function.
     2. Enable the USART using the USART_Cmd() function.
     3. Configures the break detection length using the USART_LINBreakDetectLengthConfig()
        function.
     4. Enable the LIN mode using the USART_LINCmd() function.


@note In LIN mode, the following bits must be kept cleared:
        - CLKEN in the USART_CR2 register,
        - STOP[1:0], SCEN, HDSEL and IREN in the USART_CR3 register.

@endverbatim
  * @{
  */

/**
  * @brief  Sets the USART LIN Break detection length.
  * @param  USARTx: where x can be 1, 2, 3, 4, 5 or 6 to select the USART or
  *         UART peripheral.
  * @param  USART_LINBreakDetectLength: specifies the LIN break detection length.
  *          This parameter can be one of the following values:
  *            @arg USART_LINBreakDetectLength_10b: 10-bit break detection
  *            @arg USART_LINBreakDetectLength_11b: 11-bit break detection
  * @retval None
  */
void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength)
{
  /* Check the parameters */
  assert_param(IS_USART_ALL_PERIPH(USARTx));
  assert_param(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength));

  USARTx->CR2 &= (uint16_t)~((uint16_t)USART_CR2_LBDL);
  USARTx->CR2 |= USART_LINBreakDetectLength;
}

/**
  * @brief  Enables or disables the USART's LIN mode.
  * @param  USARTx: where x can be 1, 2, 3, 4, 5 or 6 to select the USART or
  *         UART peripheral.
  * @param  NewState: new state of the USART LIN mode.
  *          This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_USART_ALL_PERIPH(USARTx));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    /* Enable the LIN mode by setting the LINEN bit in the CR2 register */
    USARTx->CR2 |= USART_CR2_LINEN;
  }
  else
  {
    /* Disable the LIN mode by clearing the LINEN bit in the CR2 register */
    USARTx->CR2 &= (uint16_t)~((uint16_t)USART_CR2_LINEN);
  }
}

/**
  * @brief  Transmits break characters.
  * @param  USARTx: where x can be 1, 2, 3, 4, 5 or 6 to select the USART or
  *         UART peripheral.
  * @retval None
  */
void USART_SendBreak(USART_TypeDef* USARTx)
{
  /* Check the parameters */
  assert_param(IS_USART_ALL_PERIPH(USARTx));

  /* Send break characters */
  USARTx->CR1 |= USART_CR1_SBK;
}
1 Like

WOW , much better, I wasn’t able to do it on the photon, was too much to do in little time and the processor cannot keep up, thats why I tried the framing error on the imp, not optimal solution but worked better that the serial library on the Photon, but using a pure LIN library would be the way of doing it.

Thanks Bdub, mdma

Have you implemented a LIN library yet? Here is the proposed LIN interface:

No timeline on when this will be implemented. Please feel free to discuss and add comments to the Github issue.

No I haven’t, No much experience on developing a library, I will try to help.

Thanks