Hi
I am using CANBUS on F2800137.
I need to send consecutive CANBUS packet frame packet using the same object ID. I am NOT using interrupt.
I am currently using CAN_O_TXRQ_21 to detect if I can send another packet or not but does not seems to wait when busy (function below always return 0) and still try to transfer another packet immediately after the first packet. In this case, I am missing some packets. (see code below)
My question, is what is the most effective way to detect if I can transmit another frame or not as soon as possible?
// 0: ok, ready to transmit
// 1: busy, need to wait
int32_t IS_CAN_TX_BUSY(uint32_t objID)
{
if((HWREG_BP(CAN_MODULE + CAN_O_TXRQ_21) & (1u<<objID)) == 0)
{
canbus_not_busy++;
return 0;
}
else
{
canbus_busy++;
return 1;
}
}
int32_t FLEXCAN_WriteTxMb(uint32_t objID, const can_frame_t *txFrame)
{
CAN_setupMessageObject(CAN_MODULE, objID, txFrame->u32Id, CAN_MSG_FRAME_EXT, CAN_MSG_OBJ_TYPE_TX, 0u, 0u, txFrame->lenght );
CAN_sendMessage(CAN_MODULE, objID, txFrame->lenght, txFrame->data);
msg_count++;
}
main()
{
While()
{
if(IS_CAN_TX_BUSY(CAN_TX_MSG_OBJ_ID) == 0) // check if we can send a new packet
{
FLEXCAN_WriteTxMb(CAN_TX_MSG_OBJ_ID, &txXfer);
}
}
}