MSCAN Driver not working

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

MSCAN Driver not working

Jump to solution
2,693 Views
PedroCastro
Contributor III

Hi everyone,

I have a FRDM-KEA128 and I have some troubles testing the MSCAN drive of the Processor Expert. First of all, I am not using the transceiver that comes within the board. I am testing with a MCP2551, because it is available for my final project and I have already tested it. I connected it to the pins PTC7 and PTC6 to the Tx and RX to my transceiver and of course the on board transceiver is not powered. To see the CAN messages I have a PEAK-USB CAN sniffer. After many attempts, I was not successful in seeing any messages being transmitted by the KEA128 and I keep getting the same synchronization error. The core clock is 40MHz and the bus clock is 20MHz to set the baud rate.
I would be glad to have some tips of what am I doing wrong

the code was extracted in the Driver's Help:

PE_low_level_init();

  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */

  /* For example: for(;;) { } */

     MyCANPtr = CAN1_Init(NULL);                                     /* Initialization of CAN1 component */

     Frame.MessageID = 0x123U;                                       /* Set Tx ID value - standard */

     Frame.FrameType = LDD_CAN_DATA_FRAME;                           /* Specyfying type of Tx frame - Data frame */

     Frame.Length = sizeof(OutData);                                 /* Set number of bytes in data frame - 4B */

     Frame.Data = OutData;                                           /* Set pointer to OutData buffer */

     DataFrameTxFlg = FALSE;                                         /* Initialization of DataFrameTxFlg */

     Error = CAN1_SendFrame(MyCANPtr 1U, &Frame);                   /* Sends the data frame over buffer 0 */

     while (!DataFrameTxFlg) { }                                      /* Wait until data frame is transmitted */

0 Kudos
1 Solution
1,465 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Pedro,

The CAN communication do not need SPI.

And about the frdm-kea128, do you have the schematic ?

If you have , could you please send me , i don't know why , i have not find it on the website .

And for the TRK-KEA128 board, for some version , connected the STB bit of can transfer module PC3391 or MC3391

to GPIOB 16 of kea128 chip, for Just as MC33901 datasheet said: STB is the input pin to control the device mode. When STB is high or floating, the device is in Standby mode. When STB is low, the device is set in Normal mode.

SO please check your board SCH, if this pin is connected to MCU,  please configure it to 0 .

You can also check this thread : Problem in Interfacing TRK-KEA128 MCU in the CAN BUS

I also create one project on KDSv3.2 refer to this thread , it can work well , it can run to the interrupt

CAN1_OnFreeTxBuffer

pastedImage_2.png

and CAN1_OnFullRxBuffer

pastedImage_3.png

The project please check the  attachment .

Hope it helps


Have a great day,
Alice

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
13 Replies
1,465 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Pedro,

Please check the initialize code whether it enable the CAN TX interrupt , if not ,

please add the code :

pastedImage_0.png

If still can not work , please tell me which IDE and which version do you use ,and use the oscilloscope to check

whether it have signal on can PIN .

Hope it helps


Have a great day,
Alice

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,465 Views
PedroCastro
Contributor III

Hello Alice,

first of all thanks for your reply and in fact there was not this line in the initialization code. However, I still cannot make it work. I got an ERR_PARAM_INDEX error in CAN1_Send function and the transmit buffer is the buffer 1.

...

BufferMask = (LDD_CAN_TBufferMask)(0x01UL << BufferIdx); /* Calculate bitmask of the requested message buffer */

if ((BufferMask & DeviceDataPrv->TxBufferMask) == 0U) { /* Is used buffer defined of BufferIdx for transmit? */

    return ERR_PARAM_INDEX;            /* If no then error */

  }

...

Besides it may be useful to know that in the PE_ISR(CAN1_TxInterrupt) the condition below is never satisfied and it never enters the if statement:

...

TxBufferMask = (LDD_CAN_TBufferMask)(DeviceDataPrv->TxBuffersPendingMask & MSCAN_PDD_GetTxMessageBufferFlagMask(MSCAN_BASE_PTR)); /* Calculate Tx buffer complete interrupt mask */

  if (TxBufferMask != 0U) {

    MSCAN_PDD_DisableTxMessageBufferInterruptMask(MSCAN_BASE_PTR, TxBufferMask); /* Disable Tx empty interrupt */

    DeviceDataPrv->TxBuffersPendingMask &= (LDD_CAN_TBufferMask)~(TxBufferMask); /* Clear used Tx buffer mask */

    for (MBIndex=0x00U; MBIndex<DeviceDataPrv->BuffersNumber; MBIndex++) {

      if ((TxBufferMask & BufferMask) != 0U) {

        CAN1_OnFreeTxBuffer(DeviceDataPrv->UserData, DeviceDataPrv->HwToTxBuffersIdxPtr[MBIndex]); /* Invoke user event */

      }

      BufferMask = (LDD_CAN_TBufferMask)(BufferMask << 0x01U);

    }

  }

...

I am using KDS v3.2.0 and the MSCAN driver of Processor expert

0 Kudos
1,465 Views
PedroCastro
Contributor III

Another point I would like to report is that the function PE_ISR(CAN1_TxInterrupt) is always called even when I an just trying to receive messages.
I also have problems to receive CAN messages for you to know also
thanks in advance

0 Kudos
1,465 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Pedro

If your project without secret , you can send it to me ,

then please tell how to reproduce your error step by step , i will check on my side what 's the problem.

And does it can send , while can not receive ?

BR

Alice

0 Kudos
1,465 Views
PedroCastro
Contributor III

Hey Alice,

The project is just an example I am trying to run. It does not send nor receive any messages.
The hardware configuration is as follows: I have a PEAK-USB CAN Sniffer connected to the CAN high and low to an MCP2551 transceiver which is in fast mode where its RS pin is in ground. I am using pins PTC7 and PTC6 as Tx and Rx respectively. I also tried to use a termination resistor and it did not work either.

As for receiving or transmitting, the event to set the buffer as free is never called and the program get stuck in the while loop. debugging the code I notice that the SYNCH bit is indicating that the MSCAN is not synchronized to the bus.
I hope all the information helps you to solve my problem

https://community.freescale.com/docs/DOC-331131

0 Kudos
1,465 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Pedro,
I have checked your code, except have not enable the Tx interrupt ,there is seems no error.

Could you please use oscilloscope check whether the CAN_H and CAN_L have signal.

And recommend you first use the FRDM-KEA128 board test , not change the can transceiver .

BR

Alice

0 Kudos
1,465 Views
PedroCastro
Contributor III

Hi Alice,

the TX interrupt you mentioned is the function you told me to insert in CAN1.c? I have included it, but it may have disappered when you generated the code.
In order to use the transceiver whithin the FRDM-KEA128 do I have to do some setup using SPI or just power it externally?

Regards,
Pedro

0 Kudos
1,465 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Pedro,

- After you add the enable Tx interrupt code to the CAN initialize function , please

enable the "don't write generated component modules" of CAN module :

pastedImage_0.png

- About the frdm-kea128 board ,why you said need setup SPI ?

BR

Alice

0 Kudos
1,465 Views
PedroCastro
Contributor III

Concerning the CAN/LIN transceiver within frdm-kea128, does it need a SPI configuration to run a certain CAN mode or does it just wait for information to send or receive?

http://cache.nxp.com/files/analog/doc/data_sheet/MC33903-MC33904-MC33905.pdf?pspll=1

0 Kudos
1,466 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Pedro,

The CAN communication do not need SPI.

And about the frdm-kea128, do you have the schematic ?

If you have , could you please send me , i don't know why , i have not find it on the website .

And for the TRK-KEA128 board, for some version , connected the STB bit of can transfer module PC3391 or MC3391

to GPIOB 16 of kea128 chip, for Just as MC33901 datasheet said: STB is the input pin to control the device mode. When STB is high or floating, the device is in Standby mode. When STB is low, the device is set in Normal mode.

SO please check your board SCH, if this pin is connected to MCU,  please configure it to 0 .

You can also check this thread : Problem in Interfacing TRK-KEA128 MCU in the CAN BUS

I also create one project on KDSv3.2 refer to this thread , it can work well , it can run to the interrupt

CAN1_OnFreeTxBuffer

pastedImage_2.png

and CAN1_OnFullRxBuffer

pastedImage_3.png

The project please check the  attachment .

Hope it helps


Have a great day,
Alice

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,465 Views
PedroCastro
Contributor III

Hi Alice,

it finnaly worked using the TRK-KEA and setting the right parameters for 48MHz and not 40MHz and changing the time segment 1 to fit the baudrate to the desired value. Thanks for all your support and your help

Have a great dayPedro

0 Kudos
1,465 Views
PedroCastro
Contributor III

Hi Alice,

could you send me the project you made for KDS please?

Thanks

0 Kudos
1,465 Views
PedroCastro
Contributor III

Alice,

I did it but still unsuccessful. While I do the debug, the program keeps entering the function PE_ISR(CAN1_TxInterrupt) and the variable TxBufferMask is always zero at the if statement and thus it never enters the condition. Another point I noticed is that after CAN1_SendFrame function, the CAN sniffer points two error messages: BUS Error and Frame Error.

Regards,

Pedro

0 Kudos