2024-09-24 08:44 AM
I'm working with an existing CAN network on which I want to read a msg, modify it slightly and rebroadcast.
I'm running into an issue where the code seems to crash/freeze if I broadcast the new message too close to the original one thats on the network.
Inside HAL_CAN_RxFifo0MsgPendingCallback() I listen for the msg I want to modify and do a HAL_CAN_AddTxMessage() call as soon as it arrives with the updated msg data. This seems to be working fine.
I then want to repeat identical msg just before the next time the original msg is broadcast on the network which is on a 30ms interval. I use HAL_GetTick() to track when the last msg was received inside HAL_CAN_RxFifo0MsgPendingCallback() and then in the main while(1) loop again I use HAL_GetTick() to count down the ms to just before the next msg is expected to be and do a HAL_CAN_AddTxMessage() with the custom data. This seems to be working fine unless I get within 4ms of the original msg at which point everything hangs. I'd like to get as close as possible to the original msg.
Any suggestion how I can accomplish this or a better way of doing it? I cannot modify the original CAN network, I can only read and broadcast messages.
2024-09-24 08:49 AM
Hello @pulsar and welcome to the community,
Need to share your code to understand what you are intending to do.
2024-09-24 09:18 AM
So this code is very crude...
void HAL_CAN_RxFifo0MsgPendingCallback_(CAN_HandleTypeDef *hcan_)
{
HAL_CAN_GetRxMessage(&hcan, CAN_RX_FIFO0, &RxHeader, (uint8_t*)RxData);
if(RxHeader.StdId == 0x250)
{
RxData[0] = 0;
HAL_CAN_AddTxMessage(&hcan, &TxHeader, (uint8_t*)RxData, &TxMailbox);
last_received_tick = HAL_GetTick();
process_msg = 1;
}
}
while (1)
{
if (process_msg && (HAL_GetTick() - last_received_tick) >= 27) {
HAL_CAN_AddTxMessage(&hcan, &TxHeader, (uint8_t*)our_msg, &TxMailbox);
process_msg = 0;
}
}
2024-09-24 09:30 AM
Sorry I didn't understand this statement:
@pulsar wrote:
This seems to be working fine unless I get within 4ms of the original msg at which point everything hangs. I'd like to get as close as possible to the original msg.
I think better to put a sketch or figure of what your program is intended to work and what the problem is ...
2024-09-24 09:39 AM
I'm listing to an existing network for a specific msg id which is broadcast on 30ms interval. When that message is detected/received, I want to right away broadcast my own msg that's on the same id. Then I want to repeat this custom message broadcast before the next original version is broadcast on the network, as late as possible before its next 30ms cycle.