Skip to main content
Graduate II
March 24, 2024
Solved

STM32F303 and L9616 CAN transceiver

  • March 24, 2024
  • 5 replies
  • 6759 views

I have a STM32F303 connected to a L9616 as displayed below. 

enhering_0-1711296523818.png

enhering_1-1711296567728.png

The pullup resistor R3 is not present any more. Please ignore it. 
Vdd is 3.3V but, as can be seen, I have set Vs to 5V, believing that was necessary to make the CAN BUS work.

With an oscilloscope channel connected between CAN_BUS_H and GND I can see a Tx pulse train, but STM32 HAL reports state 2 and error 43 (0x2B) after transmission. If I understood well, this means 0x20 + 0x10 + 0x1 which leads me to believe that the following three errors are occurring:

#define HAL_CAN_ERROR_EWG (0x00000001U) /*!< Protocol Error Warning */
#define HAL_CAN_ERROR_FOR (0x00000010U) /*!< Form error */
#define HAL_CAN_ERROR_ACK (0x00000020U) /*!< Acknowledgment error

Besides that reported error, the most annoying fact is that I tried many ways to fire the Rx Callbacks on another node with similar configurations, without success. 

When investigating the problem I measured, on the reception node, CAN_TX at 3.3V and CAN_RX at 5V. I believe this 5V at CAN RX is, somehow, blinding STM32 from the Rx transceiver signal. 

Can you help me with some information? Or could you please share a proved working connection diagram between STM32 and L9616 with me? 

Best regards,

Hering

    This topic has been closed for replies.
    Best answer by mƎALLEm

    Hello,

    I don't see an issue in the schematics but I have some questions:

    • How you did connect ASC pin? (the status of JP1).
    • Did you fit JP2 jumper to connect the termination resistor to the bus?
    • Is there another node connected to the bus that interacts with your node? If not, you have to connect another node having the same CAN bitrate.
    • What is the clock source you are using HSE with an external crystal or HSI?
    • Could you please provide your CAN bitrate configuration? CAN prescaler, BS1 and BS2? If you can share your code.

    Besides that, I see another issue with the transceiver L9616 which is a 5V transceiver.

    According to its datasheet VTXO min is 0.7 x Vs. In your case Vs = 5V -> So VTXO min = 0.7 x 5 = 3.5V that needs to be seen from the STM32. In your case, the latter is supplied by 3.3V and the GPIOs cannot deliver more than VDD = 3.3V. So it's out of spec of the transceiver. You need to supply your transceiver with maximum 4.71V (3.3/0.7) to be in the transceiver's spec.

    SofLit_0-1711299774998.png

     

    5 replies

    mƎALLEmAnswer
    Technical Moderator
    March 24, 2024

    Hello,

    I don't see an issue in the schematics but I have some questions:

    • How you did connect ASC pin? (the status of JP1).
    • Did you fit JP2 jumper to connect the termination resistor to the bus?
    • Is there another node connected to the bus that interacts with your node? If not, you have to connect another node having the same CAN bitrate.
    • What is the clock source you are using HSE with an external crystal or HSI?
    • Could you please provide your CAN bitrate configuration? CAN prescaler, BS1 and BS2? If you can share your code.

    Besides that, I see another issue with the transceiver L9616 which is a 5V transceiver.

    According to its datasheet VTXO min is 0.7 x Vs. In your case Vs = 5V -> So VTXO min = 0.7 x 5 = 3.5V that needs to be seen from the STM32. In your case, the latter is supplied by 3.3V and the GPIOs cannot deliver more than VDD = 3.3V. So it's out of spec of the transceiver. You need to supply your transceiver with maximum 4.71V (3.3/0.7) to be in the transceiver's spec.

    SofLit_0-1711299774998.png

     

    enheringAuthor
    Graduate II
    March 24, 2024

    Thanks a lot for your answer, @mƎALLEm 
    I provide answers for your questions below.

    • How you did connect ASC pin? (the status of JP1).

    Currently it is floating. I tried both JP1 possibilities with an external jumper, but saw no noticeable differences in the pulse train on the oscilloscope screen, so I disregarded it. Should I set it in the high bandwidth option (GND)?

    • Did you fit JP2 jumper to connect the termination resistor to the bus?

    The jumper is fitted, but the resistor is not connected. I have placed two 120 ohm resistors in the bus endings instead. The bus is a vertical PCB which connects the modules.

    MUVeCMarch2024.jpg 

    • Is there another node connected to the bus that interacts with your node? If not, you have to connect another node having the same CAN bitrate.

    Yes, there is. Same settings.

    • What is the clock source you are using HSE with an external crystal or HSI?

    External crystal, 16MHz.

    • Could you please provide your CAN bitrate configuration? CAN prescaler, BS1 and BS2? If you can share your code.

    Sure:
    hcan.Instance = CAN;
    hcan.Init.Prescaler = 2;
    hcan.Init.Mode = CAN_MODE_NORMAL;
    hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
    hcan.Init.TimeSeg1 = CAN_BS1_5TQ;
    hcan.Init.TimeSeg2 = CAN_BS2_5TQ;
    hcan.Init.TimeTriggeredMode = DISABLE;
    hcan.Init.AutoBusOff = ENABLE;
    hcan.Init.AutoWakeUp = ENABLE;
    hcan.Init.AutoRetransmission = DISABLE;
    hcan.Init.ReceiveFifoLocked = DISABLE;
    hcan.Init.TransmitFifoPriority = DISABLE;

    Again, thank you for your help.

    Technical Moderator
    March 25, 2024

    Hello again,

    I tried to simulate your config and found that you have a non-common CAN bitrate: 

    SofLit_0-1711352048178.png

    This is your system clock config:

    SofLit_1-1711352121001.png

    Could you please confirm?

    Regarding MCP2561 has STBY pin which consists of putting the transceiver in standby mode. In that case you couldn't transmit/receive any CAN frame. There is an internal pull up resistor connected to that pin (by default standby mode activated). So you need to at least pull STBY pin to the ground.

    Technical Moderator
    March 24, 2024

    Thank you for these information.

    Could you please share your system clock config?

    By this statement: "With an oscilloscope channel connected between CAN_BUS_H and GND I can see a Tx pulse train" : do you mean that you are seeing CAN frame transmitted by STM32 or from another node?

    What about CAN_BUS_L? Are you seeing an expected signal?

    Regarding ASC pin and according to L9616 datasheet, the pin is pulled down to GND through an internal resistor:

    SofLit_0-1711311194595.png

    I think no need to connect it for the moment. In this configuration you are in High speed config > 250kb/s

    SofLit_1-1711311359881.png

    Regarding your last question about a transceiver replacement and since your HW is already fixed, I would suggest MCP2561 which is pin to pin compatible with L9616 (unfortunately there is no replacement from ST):

    SofLit_3-1711311732595.png

    According to its datasheet this transceiver fit exactly your needs. Power supply = 5V and VIH min = 2V < 3.3V

    SofLit_2-1711311694584.png

     

     

     

     

     

     

    enheringAuthor
    Graduate II
    March 24, 2024

    Thank you, @mƎALLEm  and @AScha.3  for your answers.
     
    This is my system clock configuration:
      RCC_OscInitTypeDef RCC_OscInitStruct = {0};
      RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
      RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

      RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
      RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
      RCC_OscInitStruct.HSIState = RCC_HSI_ON;
      RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
      RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
      |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
      RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;
      RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;
      RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
      RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV8;

      PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2|RCC_PERIPHCLK_TIM1
    |RCC_PERIPHCLK_TIM8;
      PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
      PeriphClkInit.Tim1ClockSelection = RCC_TIM1CLK_HCLK;
      PeriphClkInit.Tim8ClockSelection = RCC_TIM8CLK_HCLK;
      HAL_RCC_EnableCSS();

    >> By this statement: "With an oscilloscope channel connected between CAN_BUS_H and GND I can see a Tx pulse train" : do you mean that you are seeing CAN frame transmitted by STM32 or from another node?

    I can see the CAN frame transmitted from another, similar node. It is another module from the system, based on same MCU and same transceiver, with same settings.

    >> What about CAN_BUS_L? Are you seeing an expected signal?
    Yes. It can be seen on both H and L lines.

    About the transceiver replacement, would also sn65hvd230 be a good replacement? It is also package and pin compatible with L9616.

    Thanks again for your kind answers.


    Technical Moderator
    March 25, 2024

    sn65hvd230 is a 3.3V transceiver, since your HW is fixed and your transceiver power supply is 5V. I suggested MCP2561. If your HW is not fixed you can use sn65hvd230.

    enheringAuthor
    Graduate II
    March 25, 2024

    Hello, @mƎALLEm. I'm writing to tell you that I have just ordered a few MCP2561. Thanks a lot for your suggestion.

    enheringAuthor
    Graduate II
    March 31, 2024

    Hello @mƎALLEm,

    Substituting the L9616 for the MCP2561 solved the reception problem. The 8 byte sequence sent by one module is received correctly by the other module. Also, the transmission and reception callbacks are being fired, which is much much better than what I had before. Thanks a lot for helping with that!
    But the module that is sending the message is reporting error 4129, or 0x1021, or:

    #define HAL_CAN_ERROR_EWG (0x00000001U) /*!< Protocol Error Warning */
    #define HAL_CAN_ERROR_ACK (0x00000020U) /*!< Acknowledgment error */
    #define HAL_CAN_ERROR_TX_TERR0 (0x00001000U) /*!< TxMailbox 1 transmit failure due to transmit error */

    I'm going to verify the bitrate and set it to a standard value to see if the error stops.

    Thanks again for your kind help.

    Technical Moderator
    April 1, 2024

    Hello,

    Thank you for the feedback.

    I'm closing this thread as the transceiver issue has been solved. Now the issue is something else . You can open a new thread for this.