cancel
Showing results for 
Search instead for 
Did you mean: 

FlexCAN not work

lizheng887
Associate II
Posted on October 10, 2015 at 09:57

Hi,

I am testing SPC560P50L5 with spc5_studio, the built-in example for FlexCAN is loopback test. When I disable loopback and enable supervisor mode, there is nothing on the CAN_TXD pin. I do not know the problem, and I need your help.

Is there any good examples(FlexCAN) for me?

thanks.
3 REPLIES 3
Erwan YVIN
ST Employee
Posted on October 12, 2015 at 17:52

 Hello Michael ,

the built-in example is using the Loopback mode.

if you are not using this loopback mode. 

Configure correctly your pin (Cf reference Manual)

and you have to take care about TX Mailbox , RX Mailbox and your RX ID.

Best regards

                   Erwan

lizheng887
Associate II
Posted on October 13, 2015 at 09:55

Hi Erwan,

I configured the Flex_CAN0 PIN: TXD(B[0]) and RXD(B[1]), Supervisor mode. MB 8~31 are set to be TX mailbox.

But after I set the code field 0xc for transmission once, I read the code field back is still 0xc, and noting on the TXD pin.

I need your further help, thanks.

The transmission function is as below:

canmsg_t can_lld_transmit(CANDriver *canp,

                      canmbx_t mailbox,

                      const CANTxFrame *ctfp) {

  CAN_TxMailBox_TypeDef *tmbp = NULL;

  uint8_t mbid = 0;

  /*check if mailbox is non empty */

  if (!can_lld_is_tx_empty(canp,mailbox)){

 return CAN_MSG_WAIT;

  }

  irqIsrDisable();

  /* Pointer to a free transmission mailbox.*/

  if (mailbox == CAN_ANY_MAILBOX) {

#if SPC5_CAN_USE_FLEXCAN0

    if(&CAND1 == canp) {

      for (mbid = 0; mbid < CAN_TX_MAILBOXES; mbid++) {

        if ((canp->flexcan->BUF[mbid + CAN_RX_MAILBOXES].CS.B.CODE & 8U) == 1) {

          tmbp = (CAN_TxMailBox_TypeDef *)&canp->flexcan->BUF[mbid + CAN_RX_MAILBOXES];

          break;

        }

      }

    }

#endif

  }

  else {

    tmbp = (CAN_TxMailBox_TypeDef *)&canp->flexcan->BUF[mailbox + CAN_RX_MAILBOXES -1];

  }

  /* Preparing the message.*/

  if (ctfp->IDE) {

    tmbp->CS.B.IDE = 1U;

    tmbp->CS.B.RTR = 0U;

    tmbp->ID.R = ctfp->EID;

  }

  else {

    tmbp->CS.B.IDE = 0U;

    tmbp->CS.B.RTR = 0U;

    tmbp->ID.R = ctfp->SID << 18;

  }

  tmbp->CS.B.LENGTH = ctfp->LENGTH;

  tmbp->DATA[0] = ctfp->data32[0];

  tmbp->DATA[1] = ctfp->data32[1];

  tmbp->CS.B.SRR = 1;

  tmbp->CS.B.CODE = 0x0C;

  

  irqIsrEnable();

  

  return CAN_MSG_OK;

}

Erwan YVIN
ST Employee
Posted on October 15, 2015 at 17:20

Hello Michael ,

Could you send me your Test application ?

Could you confirm me your SPC5Studio version ?

you should be on 3.7.0 version.

            Best Regards

                        Erwan