2021-06-12 04:46 AM
Hey everyone here is my situation:
I'm facing some issues during a transmission of a specific Can-FD message. I'am using a STM32G484 in combination with a TCAN332D Can phy on a self developed hardware. I used Cube MX to generate code for CAN-FD communication. My second node in the network is a PCAN View which sends messages to my board and receives messages as well.
Here is my code to initialize the FDCAN part of my code:
void CANFD_init(FDCAN_HandleTypeDef *hfdcan, uint8_t Device_U8)
{
switch(Device_U8)
{
case 1:
hfdcan->Instance = FDCAN1;
break;
case 2:
hfdcan->Instance = FDCAN2;
break;
default:
break;
}
hfdcan->Init.FrameFormat = FDCAN_FRAME_FD_BRS;
hfdcan->Init.Mode = FDCAN_MODE_NORMAL;
hfdcan->Init.AutoRetransmission = ENABLE;
hfdcan->Init.TransmitPause = ENABLE;
hfdcan->Init.ProtocolException = DISABLE;
/* Use this configuration for:
* CAN clock: 20Mhz
* Nom. Baud rate: 500 kBit/s */
hfdcan->Init.NominalPrescaler = 1;
CANFD_setupCanNominalTimings(hfdcan, 7, 16, 16, 16);
/* Use this configuration for:
* CAN clock: 20Mhz
* Nom. data rate: 500 kBit/s */
hfdcan->Init.DataPrescaler = 1;
CANFD_setupCanDataTimings(hfdcan, 7, 16, 16, 16);
hfdcan->Init.StdFiltersNbr = 2;
hfdcan->Init.ExtFiltersNbr = 0;
hfdcan->Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
// hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
if (HAL_FDCAN_Init(hfdcan) != HAL_OK)
{
Error();
}
}
Part of Transmitting:
void CANFD_transmitMessage(FDCAN_HandleTypeDef *hfdcan, uint32_t identifier, uint32_t length, uint8_t *pData){
FDCAN_TxHeaderTypeDef loc_TxHeader;
/* Build Message*/
loc_TxHeader.Identifier = identifier;
loc_TxHeader.IdType = FDCAN_STANDARD_ID;
loc_TxHeader.TxFrameType = FDCAN_DATA_FRAME;
loc_TxHeader.DataLength = length;
loc_TxHeader.ErrorStateIndicator = FDCAN_ESI_PASSIVE;
loc_TxHeader.BitRateSwitch = FDCAN_BRS_ON;
loc_TxHeader.FDFormat = FDCAN_FD_CAN;
loc_TxHeader.TxEventFifoControl = FDCAN_STORE_TX_EVENTS;
loc_TxHeader.MessageMarker = 1;
if (HAL_FDCAN_AddMessageToTxFifoQ(hfdcan, &loc_TxHeader, pData) != HAL_OK)
{
Error();
}
}
Now to my problem:
If I try to send a message to PCAN-View with the data:
pData[20] = [0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
i have no problems at all and I receive the message successfully, but if I try to send another payload like:
pData[20] = [0x00, 0xf0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
the message won't ack from my receiver. This error is reproducible and I've tried many combinations of data to transmit, but it seems like the pattern 0xf0 followed by 0xff in my payload at every point causing this issue. This seems really weird to me and im not able to explain it. I tried similar combinations which causing the errors too, so i give you a look:
0xf0, 0xff
0xf0, 0xfe
0xf0, 0xfd
0xf0, 0xfc
0xf0, 0xfb
0xf0, 0xfa
0xf0, 0xf9
0xf0, 0xf8
0xe0, 0xff
Generally I have no issues with bit timings or other can fd parameters, the error occurs just with the listed byte combinations which follow each other in my payload (maybe more, but these are the recognized ones). I've tried to decode and scope my can signal, but I don't found any bit-stuff issues which causing this error. Trying multiple combinations seems really randomly but I've been trying to reproduce this error with other patterns and suddenly the error doesn't occurs. The error doesn't occurs when the first byte is set to at least 0xd0 and the second is decrement to at least 0xf7. With values below d and 7 I'm facing no problems. Of course the bit stream has changed with increment to 8 or e but I've never see a bit stuff error on my scope causing by 6 consecutive 0's oder 1's. Also I debugged the corresponding HAL-Code up to the point where my payload is written to the RAM.
2021-06-12 04:48 AM
Her the scope when everything goes well:
pData = [0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,]
Now when the error occurs.
pData = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0xF0, 0xFF, 0xFF]The data length has not changed, its just the payload which has changed.