cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Communication not working between STM32F4-Discovery board and stm32f091cct6 microcontroller.

Pjang.1
Associate II

I am using two different STM23 microcontrollers using 2 MCP2551 in between. However, the CAN Communication is not working between STM32F4-Discovery board and stm32f091cct6 microcontroller. 

For the testing purpose, I have check the CAN communication between two STM32F4 discovery boards where it works fine.

After searching lots of debug issue solution like - APB1 peripheral clock frequency matching (42MHz in my case), baud rate for CAN match in both MCUs (500kbps), Common ground to both boards.

I have started doubt if we CAN communicate in between Two different F4 and F0 family MCU board or not?

1 ACCEPTED SOLUTION

Accepted Solutions
Jack Peacock_2
Senior III

The CAN bus interface is independent of whatever processor is being used. However the bit timing must be very close in order to decode the bus signal levels. Two development boards with the same external HSE oscillator and identical bit timing configuration will have an excellent chance of working together. Adding a different board, different HSE oscillator (hint if you used the HSI you have just built in a significant error factor in bit timing, check the datasheets for HSI tolerances). and you better work out the exact bit timing settings before assuming it's a hardware problem.

All too often the CAN fail to connect comes from one of two sources: bit timings aren't compatible, or timing drift caused by using an RC oscillator (HSI); or there isn't a minimum of two nodes on a real twisted pair bus with terminating resistors at each end. I suggest you show your bit timing calculations here for both nodes, along with how the HSE is configured for each node. If you are using the HSI then you already have the answer to your issue.

And as always show the error and status registers for the two nodes. There is a wealth of troubleshooting information in those readings...that's why they are exposed.

 Jack Peacock

View solution in original post

5 REPLIES 5
Ozone
Lead

> I have started doubt if we CAN communicate in between Two different F4 and F0 family MCU board or not?

Are you joking ?

> For the testing purpose, I have check the CAN communication between two STM32F4 discovery boards where it works fine.

On which level ?

Did you include the CAN transceivers ?

Did you check the bus levels are according to CAN standard ?

Monitor the bus with s acope or logic analyser, check the baudrate is correct.

On the node trying to send, do the error counters go up ?

Jack Peacock_2
Senior III

The CAN bus interface is independent of whatever processor is being used. However the bit timing must be very close in order to decode the bus signal levels. Two development boards with the same external HSE oscillator and identical bit timing configuration will have an excellent chance of working together. Adding a different board, different HSE oscillator (hint if you used the HSI you have just built in a significant error factor in bit timing, check the datasheets for HSI tolerances). and you better work out the exact bit timing settings before assuming it's a hardware problem.

All too often the CAN fail to connect comes from one of two sources: bit timings aren't compatible, or timing drift caused by using an RC oscillator (HSI); or there isn't a minimum of two nodes on a real twisted pair bus with terminating resistors at each end. I suggest you show your bit timing calculations here for both nodes, along with how the HSE is configured for each node. If you are using the HSI then you already have the answer to your issue.

And as always show the error and status registers for the two nodes. There is a wealth of troubleshooting information in those readings...that's why they are exposed.

 Jack Peacock

Are you joking ? - No Ozone, I am not joking... I have seen lots of example but the examples are mostly between identical boards. And according to my understanding.. CAN Communication should be independent of the boards.. however It is not working here.. So there might be something that I missed the point.

> For the testing purpose, I have check the CAN communication between two STM32F4 discovery boards where it works fine.

On which level ? - Yes.. I have sent the data from one board to another and Reception on Second STM32F4 is based on Rx0 Interrupt.. when some data is received.. in interrupt loop same data is displayed on the UART...

Also on Transmission from first board, I am using Tx Interrupt.. so on successful transmission, an LED gives the indication.

in whole setup.. as i mentioned in my question, two  MCP2551 are used.

Did you check the bus levels are according to CAN standard ? - I clearly not understood.. however, it seems you are talking about CAN Initialization Function.. Yes I have verified that.

On the node trying to send, do the error counters go up ? - I will check this..

My reception loop looks like this below code and tranmission is done by "HAL_CAN_AddTxMessage(&hcan1, &TxHeader, pvar, &TxMailbox);"

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
		uint32_t Timeout = 1000;
		char RxData[10];
		HAL_CAN_GetRxMessage(&hcan, CAN_RX_FIFO0, &RxHeader, RxData);
		HAL_UART_Transmit(&huart3, &RxData, strlen(RxData), Timeout);
		HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_15);
}

Hi @Jack Peacock_2  .. Thanks for reply... Yes I am using HSI for both of the board..

CAN really expects you to be using crystals to hit timing accuracy expectations.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..