cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Bus Error – Transmit and Reception Not Working – STM8AF5268

Naresh1
Associate

 

CAN Bus Error and Reception Not Working – STM8AF5268

Hi,

I am working with STM8AF5268 and implementing CAN communication using the STM8S/A Standard Peripheral Library.


Hardware Setup

  • MCU: STM8AF5268

  • CAN Transceiver: SN65HVD1050

  • CAN Analyzer: Waveshare USB-CAN-FD

  • Baud rate: 100 kbps

Termination

  • 120Ω across CANH and CANL at STM8 side

  • USB-CAN-FD termination enabled

  • Measured ≈ 60Ω across CANH–CANL

SN65HVD1050 VCC = 5V (verified).
Common ground connected between STM8 board and analyzer.


Clock Configuration

 

 
CLK_DeInit(); CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); CLK_PeripheralClockConfig(CLK_PERIPHERAL_CAN, ENABLE);

 

 

CAN Initialization

 

 
CAN_Init( CAN_MasterCtrl_AllDisabled, CAN_Mode_Normal, CAN_SynJumpWidth_1TimeQuantum, CAN_BitSeg1_11TimeQuantum, CAN_BitSeg2_4TimeQuantum, 10 // Prescaler );

 

 

CAN Transmit Code

 

 
uint8_t test_data[8] = {0x22,0x33,0x44,0x55,0x56,0x66,0x77,0x66}; CAN_Transmit( 0x321, CAN_Id_Standard, CAN_RTR_Data, 8, test_data );
 

Problems

:keycap_1: Transmission Issue

  • When attempting transmission, the CAN controller enters Bus Error / Bus-Off state.

  • No frame appears on the USB-CAN-FD

:keycap_2: Reception Issue

  • When sending frames from the USB-CAN-FD tool at 100 kbps, the STM8 does not receive any frames.

  • RX interrupt is not triggered.

  • I am using STM8S/A Standard Peripheral Library for CAN and interrupt handling (stm8s_it.c with proper vector configuration).

Questions

  1. What are the common reasons for Bus-Off during transmission on STM8AF52xx?

  2. Is there anything specific required in STM8AF52xx CAN initialization before transmitting?

  3. Could incorrect bit timing configuration cause immediate bus errors?

  4. Are there any specific hardware-level checks for STM8AF52xx CAN (TX/RX pin configuration, alternate function setup, transceiver standby pin handling, etc.)?

  5. please share there is any sample code /example code and suggestions 

If anyone has experience with STM8AF52xx CAN, please guide me

thank you (i attach the file for reference)stm2.jpeg

1 ACCEPTED SOLUTION

Accepted Solutions
mƎALLEm
ST Employee

Hello @Naresh1 and welcome to the ST community,

First I'm not STM8 product expert but I can help with CAN communication subject.

Second, Bus-off state mainly occurs with a hardware issue: wiring issues or an issue with your transceiver.

Or bitrate issue config i.e. bitrate mismatch.

- Check is the S pin of your transceiver: is it connected to the GND?

mALLEm_1-1770975843527.png

- Check also the power supply of your transceiver on its pins directly.

- Check all your wiring with a continuity test with your device powered off.

- Check your bitrate it should be exactly the same for all the nodes (no approximative bitrate values).

- Try the Loopback mode to confirm whether it is a hardware issue. If Loopback mode works it's a hardware issue or a bitrate mismatch issue.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
mƎALLEm
ST Employee

Hello @Naresh1 and welcome to the ST community,

First I'm not STM8 product expert but I can help with CAN communication subject.

Second, Bus-off state mainly occurs with a hardware issue: wiring issues or an issue with your transceiver.

Or bitrate issue config i.e. bitrate mismatch.

- Check is the S pin of your transceiver: is it connected to the GND?

mALLEm_1-1770975843527.png

- Check also the power supply of your transceiver on its pins directly.

- Check all your wiring with a continuity test with your device powered off.

- Check your bitrate it should be exactly the same for all the nodes (no approximative bitrate values).

- Try the Loopback mode to confirm whether it is a hardware issue. If Loopback mode works it's a hardware issue or a bitrate mismatch issue.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I have successfully received the CAN messages. The issue was identified as a hardware-related problem rather than a software fault.
Additionally, I would like to share an observation for future STM8S projects. The interrupt vector table for STM8S is located within the project directory under:
stm8s_stdperiph_template → STVD
This structure can make it difficult to locate, especially for developers who are new to STM8. It may be beneficial to document this more clearly or reorganize the project layout to improve accessibility.