This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F2800137: F2800137 CANBUS consecutive transmit ready flag

Part Number: TMS320F2800137

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);

 }

}

}

  •  Hi Ahugron,

    Monitor bit TxOk in register CAN_ES.  Ensure first that the transmitted frame has be correctly sent and acknowledged before sending out another frame.  If transmission is error-free then TxOk will be set.

    Regards,

    Joseph

  • Hi Joseph,

    Thanks for the help. It seems that by checking after a transmitted frame the txOK, it seems ok. I do have times to times some frame error. (scope). Anyway, the transceiver is still retrying and this is good.

    But frequently, the device stops transmitting completely.  I do call the CAN_SendMessage function, nothing is sent to the bus. CAN_getStatus(CANA_BASE) is returning 0xE7. (register view shows 0xF8). No really sure why there are different. BOff, EWarn, EPass, RxOK are set.

    How do I clear these flags to start communicating again.

    Thanks,

    Arnaud

  • Hi Joseph,

    Thanks for the help. It seems that by checking after a transmitted frame the txOK, it seems ok. I do have times to times some frame error. (scope). Anyway, the transceiver is still retrying and this is good.

    But frequently, the device stops transmitting completely.  I do call the CAN_SendMessage function, nothing is sent to the bus. CAN_getStatus(CANA_BASE) is returning 0xE7. (register view shows 0xF8). No really sure why there are different. BOff, EWarn, EPass, RxOK are set.

    Why are these flags set and How do I clear these flags to start communicating again.

    Thanks,

    Arnaud

  • Hi Arnaud,

    Seems that there are errors happening in the bus.  Do you have a waveform capture of the frame and does it show any distortions?  Whenever you see BOff being set, that is an indication that multiple errors have occurred and that caused the CAN to turn the bus off on the transmitting node.  You need first to isolate what is causing the errors.

    As long as you are enabling auto bus off recovery (ABO) bit, CAN protocol will attempt to reinitialize the module if your application clears the init bit.  See the sequence for auto-bus on in the technical reference manual for more information.

    Regards,

    Joseph