FlexCAN message transmit issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FlexCAN message transmit issue

2,458 Views
dsytj88
Contributor II

hi

I encounted one problem for CAN message transmitting,in the case that the sending message number is large,the message can't transmit successfully.

I do it like this:

configure one mailbox and then transmit the message using these two functions:

  FLEXCAN_DRV_ConfigTxMb(instance, mailbox, &dataInfo, messageId);
  FLEXCAN_DRV_Send(instance, mailbox, &dataInfo, messageId, data);

since the transmiting message number is more than 100,so I have to re-use the mailbox. I found some transmiting will be failure if one mailbox is used a second time,even there is some time gap to re-use the same mailbox.

in order to avoid the failure of re-use same mailbox,which falg can indicate the transmiting finished? then I can use this flag for checking before using the same mailbox again.

thank you.

0 Kudos
Reply
5 Replies

2,314 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

you can use below function

FLEXCAN_DRV_GetTransferStatus(instance, mailbox)

It returns STATUS_SUCCESS if transmission is finished for given MB otherwise you get STATUS_BUSY.

BR, Petr

0 Kudos
Reply

2,314 Views
dsytj88
Contributor II

hi

if using this function,FLEXCAN_DRV_GetTransferStatus(),it's usually blocked the coding.

is there any method to avoid that?

thank you

0 Kudos
Reply

2,314 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

if not using within while loop I see no reason why this function should block the code.

Another option could be installing the Callback function and use FLEXCAN_EVENT_TX_COMPLETE event to indicate message was successfully transmitted.

void flexcan0_Callback(uint8_t instance, flexcan_event_type_t eventType, uint32_t mb_num,
flexcan_state_t *flexcanState)
{
   (void)flexcanState;
   (void)instance;

   switch(eventType)
   {
    case FLEXCAN_EVENT_RX_COMPLETE:
   
       break;
    case FLEXCAN_EVENT_RXFIFO_COMPLETE:

       break;
    case FLEXCAN_EVENT_TX_COMPLETE:

       break;
    default:
       break;
   }
}

/* Install callback function */
FLEXCAN_DRV_InstallEventCallback(INST_CANCOM1, flexcan0_Callback, NULL);

BR, Petr

0 Kudos
Reply

2,314 Views
dsytj88
Contributor II

hi

the message sending function is not called in while loop, it's called by freeRTOS.

but I checked the status,usually the status is busy and coding is blocked there for a long time,especially in the condition that high MCU load and a large number of messages transfering in CAN bus.

which reasons could cause the mailbox in busy status? is it possible that the message is trying to transmit  continuously after transmitting failure? 

thank you

br

yu

0 Kudos
Reply

2,314 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

maybe a message is not transmitted successfully without error and so driver interrupt is not called and driver's MB status is not changed. If error is detected during transmission the message is re-transmitted again.

You can check ECR/ESR1 registers for errors. Also chack flag status in IFLAGx registers and if interrupt is enabled for the MB in IMASKx register.

BR, Petr

0 Kudos
Reply