cancel
Showing results for 
Search instead for 
Did you mean: 

Help with a seemingly constant RxHeader.

CANGWP
Visitor

I am working with a CAN bus over a STM32 Board. I don't think the hardware is important in my question. I have tried to use the HAL_FDCAN_GetRxMessage function to get a message from a device explorer where you can easily send a message via CAN.

I run into an error when trying to receive a message. Inside the function when DataLength from the RxHeader structure is being set the value does not actually change. None of them do actually, the RxHeader does not change tat all. I have tried to change the value manually and that did not work either. For some reason it seems to just be constant. I also looked at the calculated value which DataLength should be set to and that is also wrong. I set the length of the message to 8 Byte and the calculation ends up with the value of 5.

The calculation is like this: ((*RxAddress & FDCAN_ELEMENT_MASK_DLC) >> 16U). And like I said testing this with a supposed length of 8 it comes out to 5. I tested it with a different message and it just seems to not be working right. With a length of 1 and 2 I got a calculated size of 0. Length of 7 and 8 both got me 5.

For now my goal is doing some really basic thing with CAN as a learning project. My next step would be filtering messages with the Identifier variable from the RxHeader but that is not being set correctly, so I can not work with it.

I declare the rx header as FDCAN_RxHeaderTypeDef* pRxHeader and in the hal_fdcan.h file the header structure has DataLength defined as uint32_t.

So my two questions which I would really appreciate any help with are:
1. How can it be that the values of the RxHeader are unchangeable?
2. Why and how is the calculation of the size wrong?

0 REPLIES 0