cancel
Showing results for 
Search instead for 
Did you mean: 

SPC560Dxx FlexCAN Transmit error

megha2
Associate
Posted on April 09, 2015 at 12:22

I am using SPC560D-DIS Discovery board for development and SPC5 studio.

I have imported test application 'SPC560Dxx OS-Less CAN Test Application for Discovery' for FlexCAN testing. In this FlexCAN0 is used in loop back mode. It is working in loop back mode. 

But after disabling loop back mode, it is not transmitting data on CANTx. The code for TX mailbox remain as 0x0C and error handler is generating. Error flags for TWRNINT, BIT0ERR, BOFFINT and ERRINT are set.

 

I used below structure to transmit data,

/* CAN TX Message structure */

txmsg.IDE = CAN_IDE_EXT;

txmsg.RTR = CAN_RTR_DATA;

txmsg.LENGTH = 8;

txmsg.data32[0] = 0x55AA55AA;

txmsg.data32[1] = 0x00FF00FF;

And initialization routine is as below,

  uint8_t mb_index = 0;

  uint8_t id = 0;

  /* Entering initialization mode. */

  canp->state = CAN_STARTING;

  /* Clock activation.*/

#if SPC5_CAN_USE_FLEXCAN0

  /* Set peripheral clock mode.*/

  if(&CAND1 == canp) {

    SPC5_FLEXCAN0_ENABLE_CLOCK();

#if !SPC5_CAN_FLEXCAN0_USE_EXT_CLK

    canp->flexcan->CR.R |= CAN_CTRL_CLK_SRC;

#endif

  }

  

  /* Enable the device.*/

  canp->flexcan->MCR.R &= ~CAN_MCR_MDIS;

  /*

   * Individual filtering per MB, disable frame self reception,

   * disable the FIFO, enable SuperVisor mode.

   */

#if SPC5_CAN_USE_FLEXCAN0

  if(&CAND1 == canp)

    canp->flexcan->MCR.R |= CAN_MCR_SUPV | CAN_MCR_MAXMB(SPC5_FLEXCAN0_MB - 1);

#endif

  canp->flexcan->CR.R |= CAN_CTRL_TSYN | CAN_CTRL_RJW(3);

  /* TX MB initialization.*/

#if SPC5_CAN_USE_FLEXCAN0

  if(&CAND1 == canp) {

    for(mb_index = 0; mb_index < (SPC5_FLEXCAN0_MB - CAN_RX_MAILBOXES);

        mb_index++) {

      canp->flexcan->BUF[mb_index + CAN_RX_MAILBOXES].CS.B.CODE = 8U;

    }

  }

#endif

  /* Unlock Message buffers.*/

  (void) canp->flexcan->TIMER.R;

  /* MCR initialization.*/

  canp->flexcan->MCR.R |= canp->config->mcr;

  /* CTRL initialization.*/

  canp->flexcan->CR.R |= canp->config->ctrl;

  /* Interrupt sources initialization.*/

  canp->flexcan->MCR.R |= CAN_MCR_WRN_EN;

  canp->flexcan->CR.R |= CAN_CTRL_BOFF_MSK | CAN_CTRL_ERR_MSK  |

                         CAN_CTRL_TWRN_MSK | CAN_CTRL_RWRN_MSK;

  /* RX MB initialization.*/

  for (id = 0; id < CAN_RX_MAILBOXES; id++) {

    canp->flexcan->BUF[id].CS.B.CODE = 0U;

    if (canp->config->RxFilter[id].scale) {

      canp->flexcan->BUF[id].CS.B.IDE = 1U;

      canp->flexcan->BUF[id].ID.R = canp->config->RxFilter[id].register1;

    }

    else {

      canp->flexcan->BUF[id].CS.B.IDE = 0U;

      canp->flexcan->BUF[id].ID.B.STD_ID = canp->config->RxFilter[id].register1;

      canp->flexcan->BUF[id].ID.B.EXT_ID = 0U;

    }

    /* RX MB initialization.*/

    canp->flexcan->BUF[id].CS.B.CODE = 4U;

  }

  canp->flexcan->RXGMASK.R = 0x0FFFFFFF;

  

    /* Enable MBs interrupts.*/

#if SPC5_CAN_USE_FLEXCAN0

  if(&CAND1 == canp) {

    if(SPC5_FLEXCAN0_MB == 32) {

      canp->flexcan->IMRL.R = 0xFFFFFFFF;

    }

    else if(SPC5_FLEXCAN0_MB == 64) {

      canp->flexcan->IMRL.R = 0xFFFFFFFF;

      canp->flexcan->IMRH.R = 0xFFFFFFFF;

    }

  }

#endif

  /* CAN BUS synchronization.*/

  canp->flexcan->MCR.B.HALT = 0;

Is any configuration is missing / wrong in this?

Also on FlexCAN Buad, I used bus clk of 48MHz, and PRESDIV=3, PSEG1=2, PSEG2=7 and PROPSEG=2. Then Sclock will be 48MHz/(3+1) = 12MHz and FlexCAN buad is 12MHz/15 = 800kbps. Is this correct?

3 REPLIES 3
Erwan YVIN
ST Employee
Posted on April 09, 2015 at 18:39

Hello Megha ,

Did you you try to configure on the Pinmap Wizard CAN0RX and CAN0TX ?

We should seen your CAN Frames by oscilloscope.

Anyway, as soon as possible, we will post an application without LOOBACK mode.

             Best Regards

                        Erwan

megha2
Associate
Posted on April 10, 2015 at 10:52

Thanks Erwan for your reply.

Yes, I have configured CANTX and CANRX from Pinmap wizard.

I have configured CANTX pin PB0 as AF1. For CANRX pin PB1, there is no option as AF1-AF3 for CAN receive. So I have configuredCANRX pin PB1 as MODE_INPUT_PULLUP. Is this configurations are correct?

I observed CANTX pin on oscilloscope. Data is coming on that pin as per attached snapshot but it is not as per desired baud. Also I have sent Tx message twice in BUF8 and BUF9 but on CANTX line I can see continuous data on oscilloscope while error interrupt is generated for BUF8 and BUF9.

I observed one more thing, when I configured just CANTX pin and not CANRX pin then data is not coming on CANTX pin.

Is there any other configuration for CANTX and CANRX?

--Megha

________________

Attachments :

TEK00000.BMP : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006qY2O&d=%2Fa%2F0X0000000bov%2FW.x9YCfbVq_C9OJwEhUNHj3W0CBk4GShQORET3Pmm4I&asPdf=false
nooshin_1382
Associate II
Posted on April 13, 2015 at 15:28

Hello Megha

I Have this like this problem in can i guess the can Clock not worked correctlly

i use this buadrate for my board please set these prameters :

Set your CAN Clock in External Clock Oscillator = 16.00 MHz

PressDive =1 , PropSeg=0 , PSEG1=5 , PSEG2=7 Baudrate =500k

i do not know what is your chip model but if your MCU have a multi Pin For CANRX you can set the CANRX Pin in other pin's with set

PSMI0_3 Register.

 

( you can find in Page 338 of Refrence manual RM0017).

Best Regards

Nazerian Vanima