‎2022-12-05 04:48 AM
Hello,
I have read hall_CAN.c instructions and did everything that is stated there. In CubeIDE I have set Prescaler to 24 and both Quantas to 4 times. My Baud Rate is 250000 bit/s.
I am using two same boards (Nucleo 746ZG) with CAN bus transciver MPC2551. After setting up everything board didn't want to send any can message. After some trouble shooting I have managed to find a bug in HAL library. Now I can send messages but I cannot receive them. I have logic analizer so I can check this data. I think there is a problem in inicialization since I cannot get any message in FIFO callback. Everytime I check there is 0 messages pending.
I cannot figure this out so hopefully someone smarter can help resolve this issue.
Thanks!
Solved! Go to Solution.
‎2022-12-08 05:57 AM
But OK sure! I will chage parameters just for you (╯°□°)╯︵ ┻�?┻
CAN_FilterTypeDef canfilterconfig;
canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
canfilterconfig.FilterBank = 18;
canfilterconfig.FilterFIFOAssignment = CAN_RX_FIFO0;
canfilterconfig.FilterIdHigh = 0;
canfilterconfig.FilterIdLow = 0x466<<5;
canfilterconfig.FilterMaskIdHigh = 0;
canfilterconfig.FilterMaskIdLow = 0x466<<5;
canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
canfilterconfig.SlaveStartFilterBank = 20;
HAL_CAN_ConfigFilter(&hcan1, &canfilterconfig);
This here are known good TESTED parameters... And I tested them myself in CubeIDE 1.9.
I have problem in 1.10.1... SOooooooooooooo
And what do you know!! Still dosen't work (in IDE 1.10.1).
Sometimes it is faster to write to existing UART or / and go thro code in debug mode than setup GPIO outputs etc. Or sometimes you can't access the GPIO pins since you are working on remote setup.
Sorry...
┬──┬ ノ( ゜-゜ノ)
Answer: for CAN BUS use CubeIDE 1.9.0., If newer updates won't work or fix the issue.
Hopefully I helped somebody!
‎2022-12-08 04:53 AM
I have used this YouTube video to do exactly the same. No difference in clocks etc.. Instead CAN I have CAN1 since the board I am using is a bit different.
the Video: https://www.youtube.com/watch?v=JfWlIY0zAIc
As I said before I can send messages but nucleo dose not read them or put them into FIFO. Data is comming in since pin PD0 is getting changes in signal (checked with HAL GPIO ReadPin). It's just that HAL library can't read and write this data into FIFO (ether 0 or 1) buffer.
I am using CAN BUS in Loopback mode and data passing is correct. This can be seen in screenshot from Data analyzer attached below.
Leads from Logic analyzer are attached DIRECTLY onto pins that are goin into nucleo's socket.
From output you can see what is the problem I am facing.
CODE:
sprintf(msg, "FIFO 0: %d FIFO 1: %d signal present on RX??: %d\r\n", HAL_CAN_GetRxFifoFillLevel(&hcan1, CAN_RX_FIFO0), HAL_CAN_GetRxFifoFillLevel(&hcan1, CAN_RX_FIFO1), HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_0));
HAL_UART_Transmit(&huart3, (uint64_t*)msg, strlen(msg), HAL_MAX_DELAY);
Output from console (ONLY when sending data! When there is no data sent RX is 1 or HIGH):
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 1
FIFO 0: 0 FIFO 1: 0 signal present on RX??: 0
Also here is code for my CAN1 init and it's filter.
static void MX_CAN1_Init(void)
{
/* USER CODE BEGIN CAN1_Init 0 */
/* USER CODE END CAN1_Init 0 */
/* USER CODE BEGIN CAN1_Init 1 */
/* USER CODE END CAN1_Init 1 */
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 10;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_11TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_4TQ;
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = DISABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CAN1_Init 2 */
CAN_FilterTypeDef canfilterconfig;
canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
canfilterconfig.FilterBank = 27;
canfilterconfig.FilterFIFOAssignment = CAN_RX_FIFO0;
canfilterconfig.FilterIdHigh = 0;
canfilterconfig.FilterIdLow = 0x466<<5;
canfilterconfig.FilterMaskIdHigh = 0;
canfilterconfig.FilterMaskIdLow = 0x466<<5;
canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
canfilterconfig.SlaveStartFilterBank = 0;
HAL_CAN_ConfigFilter(&hcan1, &canfilterconfig);
/* USER CODE END CAN1_Init 2 */
}
Before anyone points out "oh you have ID wrong" here is the header for TX message:
TxHeader.DLC = 8; // data length
TxHeader.IDE = CAN_ID_STD;
TxHeader.RTR = CAN_RTR_DATA;
TxHeader.StdId = 0x466; // ID <---- CHANGE FOR EVERY DEVICE!
Now I'm going to install older version of CubeIDE since this must be some sort of a bug in HAL library. I tried to set up ETH and LWIP before without luck... Now I can't set up CAN....
‎2022-12-08 05:24 AM
You have done a configuration for a bxCAN Slave Filter ;)
canfilterconfig.SlaveStartFilterBank = 0;
This line defines all filterbanks abov this value (here it is 0) will linked to the bxCAN Slave.
And you do a configuration of the
canfilterconfig.FilterBank = 27;
So your messages will go to the non configurated bxCAN Slave.
Change this both values to usefull numbers.
An other idea:
It will be easier for testing, to activate the Rx Interrupt and toggle an LED.
So you see it works very fast without reading the message it self
‎2022-12-08 05:57 AM
But OK sure! I will chage parameters just for you (╯°□°)╯︵ ┻�?┻
CAN_FilterTypeDef canfilterconfig;
canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
canfilterconfig.FilterBank = 18;
canfilterconfig.FilterFIFOAssignment = CAN_RX_FIFO0;
canfilterconfig.FilterIdHigh = 0;
canfilterconfig.FilterIdLow = 0x466<<5;
canfilterconfig.FilterMaskIdHigh = 0;
canfilterconfig.FilterMaskIdLow = 0x466<<5;
canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
canfilterconfig.SlaveStartFilterBank = 20;
HAL_CAN_ConfigFilter(&hcan1, &canfilterconfig);
This here are known good TESTED parameters... And I tested them myself in CubeIDE 1.9.
I have problem in 1.10.1... SOooooooooooooo
And what do you know!! Still dosen't work (in IDE 1.10.1).
Sometimes it is faster to write to existing UART or / and go thro code in debug mode than setup GPIO outputs etc. Or sometimes you can't access the GPIO pins since you are working on remote setup.
Sorry...
┬──┬ ノ( ゜-゜ノ)
Answer: for CAN BUS use CubeIDE 1.9.0., If newer updates won't work or fix the issue.
Hopefully I helped somebody!
‎2022-12-08 06:19 AM
Sorry I wouldn't hit you with my previous comment.
You wrote that you use a Nucleo. So it is very easy to toggle a LED. This was my idea.
In your previous code was definitly the mistake with the filterbanks.
So I gave you this hint.
There are no direct dependencies to a special CubeIDE version. Maybe to the version of the underlying CubeMX code generator or to the HAL.
But I worked with the previous three puplic versions of them (inside the CubeIDE) on success and uses the bxCAN on a NUCLEO-F439ZI. So it must be inside the code.
I have searched a while on my own code. The given ideas are only as hints no "superset of to do".
Some more ideas:
can you send from both Nucleos (with different CAN Ids)?
Do you have a CAN sniffing tool to see a valid CAN message? The message is only valid if an second device add the ACK bit.
Maybe it is better to have an open filter. This means the filter is configured as mask-typ with a mask = 0x0
‎2022-12-08 06:32 AM
No it is fine :grinning_face_with_sweat: . I tried to make CAN BUS work for at least 2 weeks now, so you can see my frustration LOL. Sure your idea is fine... a lot of times i use built in LEDs. They are great "I am ALIVE!" indicator. But sometimes you just can't get to the board and face check the LEDs.
Now I was running in Loopback mode since I wanted to eliminate all other factors.
I am using logic analyzier which can be used to check CAN packets.
But of coruse you knew that since I wrote this things a few comments above ;) .
But for sure I will use open filter! Since final device must be compatible with others and be plug&play.
this was just for test sake.
‎2022-12-08 06:59 AM
Are you interested at work together?
I'm at creation a CAN communication stack which is adjustable via the CubeIDE.
If you want take a look at:
‎2022-12-08 11:09 PM
Well since I want to communicate via automotive CAN BUS in my private time and your project does exactly that I am IN! Hit me up on private and we can have a chat there!