Hello,
We are using MCP2517 with ESP32. When we are trying to receive a message from FIFO, only the last couple bytes of the RX message were received. As we check the MCP251XFD_ReceiveMessageFromFIFO function,
You are creating a 4+4+4+64 Byte buffer in line 766, which is assigned to the packed MCP251XFD_CAN_RX_Message struct.
First 4 Bytes -> MCP251XFD_CAN_RX_Message_Identifier
Second 4 Bytes -> MCP251XFD_CAN_RX_Message_Control
Third 4 Bytes -> Timestamp
Rest 64 Bytes is allocated for the RX payload. We are not using timestamp data so our BytesToGet is (20-4) 16 Bytes. (DLC8) MCP251XFD_ReceiveMessageObjectFromFIFO function writes the Message Identifier, Control and Payload successfully.
In Line 796, you are assigning pBuff to address of &Buffer[12], which is not correct because if the timestamp is available, it starts from index 8 or data starts from index 8 otherwise. In the next section, if timestamp ptr is not null you are increasing the address.
We changed line 796 as, uint8_t *pBuff = &tempBuffer[sizeof(MCP251XFD_CAN_RX_Message_Identifier) + sizeof(MCP251XFD_CAN_RX_Message_Control)]; // Next bytes of the Buffer is for payload
Which asigns pBuff ptr to &tempBuffer[8]
Other issue was, in line 812
You are copying pBuff++ = pData++; which should be pData++ = pBuff++;
Because of pData asigned to address of messageGet->PayloadData[0].
After that change, we can successfully receive CAN2.0 and CAN FD frames. I can also open a pull request if you can check that I am not mistaken.
Thanks.
Hello, We are using MCP2517 with ESP32. When we are trying to receive a message from FIFO, only the last couple bytes of the RX message were received. As we check the MCP251XFD_ReceiveMessageFromFIFO function, You are creating a 4+4+4+64 Byte buffer in line 766, which is assigned to the packed MCP251XFD_CAN_RX_Message struct. First 4 Bytes -> MCP251XFD_CAN_RX_Message_Identifier Second 4 Bytes -> MCP251XFD_CAN_RX_Message_Control Third 4 Bytes -> Timestamp Rest 64 Bytes is allocated for the RX payload. We are not using timestamp data so our BytesToGet is (20-4) 16 Bytes. (DLC8) MCP251XFD_ReceiveMessageObjectFromFIFO function writes the Message Identifier, Control and Payload successfully. In Line 796, you are assigning pBuff to address of &Buffer[12], which is not correct because if the timestamp is available, it starts from index 8 or data starts from index 8 otherwise. In the next section, if timestamp ptr is not null you are increasing the address. We changed line 796 as,
uint8_t *pBuff = &tempBuffer[sizeof(MCP251XFD_CAN_RX_Message_Identifier) + sizeof(MCP251XFD_CAN_RX_Message_Control)]; // Next bytes of the Buffer is for payload
Which asigns pBuff ptr to &tempBuffer[8] Other issue was, in line 812 You are copying pBuff++ = pData++; which should be pData++ = pBuff++; Because of pData asigned to address of messageGet->PayloadData[0]. After that change, we can successfully receive CAN2.0 and CAN FD frames. I can also open a pull request if you can check that I am not mistaken. Thanks.https://github.com/Emandhal/MCP251XFD/blob/91bd8863ff3839e9b2dc78af8f874f0074c2c84e/MCP251XFD.c#L757-L817