cancel
Showing results for 
Search instead for 
Did you mean: 

How to read CAN BUS with STM32F091RC + MCP2551 transreceiver?

JBond.1
Senior

Hi I am trying to read car CAN BUS with STM32F091RC + MCP2551 transreceiver. All I am getting is empty header and data. I guess my setup is incorrect, anyone can advice how to setup?

This is my setup:

0690X00000BuZ6jQAF.png

	CAN_TxHeaderTypeDef   TxHeader;
	CAN_RxHeaderTypeDef   RxHeader;
	uint8_t               TxData[8];
	uint8_t               RxData[8];
	uint32_t              TxMailbox;
 
	HAL_CAN_Start(&hcan);
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
		/* Get RX message */
		if (HAL_CAN_GetRxMessage(&hcan, CAN_RX_FIFO0, &RxHeader, RxData) != HAL_OK)
		{
			/* Reception Error */
			Error_Handler();
		}
		
		if (
			RxData[0] != 0 ||
			RxData[1] != 0 ||
			RxData[2] != 0 ||
			RxData[3] != 0 ||
			RxData[4] != 0 ||
			RxData[5] != 0 ||
			RxData[6] != 0 ||
			RxData[7] != 0 ||
			RxHeader.DLC != 0 ||
			RxHeader.ExtId != 0 ||
			RxHeader.FilterMatchIndex != 0 ||
			RxHeader.IDE != 0 ||
			RxHeader.RTR != 0 ||
			RxHeader.StdId != 0 ||
			RxHeader.Timestamp != 0
		)
		{
			BSP_LED_On(LED2);
		}
  }

1 ACCEPTED SOLUTION

Accepted Solutions

>>Any help?

Unfortunately multiple degrees of separation in terms of chips, tools, and libraries.

Suspect you'll need to search/grep the library source to understand specifically what is not liked in your parameters, presumably clocks, quanta, or other combination of thing that the library determines to be internally inconsistent.

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

View solution in original post

6 REPLIES 6
JBond.1
Senior

Any help? I am reading can and getting all zeros when connected to car CAN bus. Why could I get zeroes?0690X00000Buc42QAB.png

I have connected transreceviver to PB8 and PB9.

JBond.1
Senior

My code available here:

https://github.com/JuMalIO/CAN

any help?

JBond.1
Senior

#define HAL_CAN_ERROR_PARAM          (0x00200000U) /*!< Parameter error

As I understand I am getting this error. What does this error mean and how to fix it?

>>Any help?

Unfortunately multiple degrees of separation in terms of chips, tools, and libraries.

Suspect you'll need to search/grep the library source to understand specifically what is not liked in your parameters, presumably clocks, quanta, or other combination of thing that the library determines to be internally inconsistent.

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

It started working!

I have calculated correct quantas by this video:

https://www.youtube.com/watch?v=rpE5UvQDcy4&list=PLERTijJOmYrApVZqiI6gtA8hr1_6QS-cs&index=14

www.bittiming.can-wiki.info

Does power source matter? Can each CAN node be on different power source? Also different power source for transceiver?

Power source does not matter?

This file is not available on GitHub. Do you still have the files available?