MPC5746R FlexCAN

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

MPC5746R FlexCAN

3,068 Views
qiaodeng
Contributor II

Hi ,

    I am initiating FlexCAN of MPC5746R.  As the manual said, I negate  CAN_MCR[MDIS]  to enable this module as 

the first step, but after this step, the program seems to run fly, it enters some kind of interrupt handler IVOR4, as the figure shows below:

170764_170764.pngpastedImage_1.png

It would be highly appreciated if you can provide successful  CAN init code for MPC5746R.

 

Qiao

Labels (1)
0 Kudos
Reply
15 Replies

2,472 Views
martin_kovar
NXP Employee
NXP Employee

Hi Qiao,

please see file in the attachment.

If you have any other questions, please feel free to write me back.

Regards,

Martin

0 Kudos
Reply

2,472 Views
qiaodeng
Contributor II

Hi Martin,

    Thanks for your reply. I am debugging using your code. I found at the end of initiation, the FRZACK and NOTRDY bit will turn to 0, but soon return to 1. I add a delay at the end of initiation, then the program can never be out of the circulation :    while(1 == CAN_1.MCR.B.FRZACK) {};

pastedImage_1.png

It makes me confused.

0 Kudos
Reply

2,472 Views
martin_kovar
NXP Employee
NXP Employee

Hi Qiao,

I tested the CAN init function and the behavior is following:

1) You must not have opened FlexCAN registers in debugger window

2) You must not stepping the code CAN init function. I tried in Lauterbach debugger and when I was stepping the code, it got stuck in last while loop. When I was not stepping the function, it worked correct.

Regards,

Martin

0 Kudos
Reply

2,472 Views
qiaodeng
Contributor II

Hi Martin,

   Thanks for your patient explanation. I tested again, and didn't open any register or step the function.

   To check if the FlexCAN is in normal mode after the initiation, I give the value of NOTRDY bit to a GPIO, but the           output of GPIO is still 5V.

pastedImage_1.png

It seems that after the Init function, the FlexCAN goes back to freeze mode again, so it still can not work correct.

Regards

Qiao

0 Kudos
Reply

2,472 Views
martin_kovar
NXP Employee
NXP Employee

Hi Qiao,

I tested the code I sent you once again and the behavior was the same as you described (I do not know why, because I had tested it many times before and it worked correct). So I copy the code to IDE once again, build it and load to microcontroller once again and now it works correct. I tried with Lauterbach and also with Multilink Universal FX debug probe. Also there was no problem when I was stepping the code (really strange).

The only difference I found were two breakpoints place in the code.

Please see attachment, there is the example which I tried last and which worked correct.

Regards,

Martin

0 Kudos
Reply

2,472 Views
qiaodeng
Contributor II

Hi Martin,

 Now this project can work correct. I guess maybe it's the difference of the IDE? I can not even create a project named Z4_2 like the one you give me . Which version of S32 Studio are you using? Any update package need to be installed? I am using S32 Design Studio for Power v1.1 .

 Really appreciate for your help!

Regards,

Qiao 

0 Kudos
Reply

2,472 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

it was older project and it was created in S32DS version 1.0, but it does not explain the behavior on my side (but it is good that it works now ;-)).

For S32DS version 1.1, there is an update 1 you can install.

https://community.nxp.com/docs/DOC-333045 

You are welcome.

Regards,

Martin

0 Kudos
Reply

2,472 Views
qiaodeng
Contributor II

Hi Martin,

Finally I found the difference, in the debugger configuration of your project, the device name is MPC5745R :

pastedImage_1.png

I changed the device name to MPC5745R in my project, it can also work correct. Maybe it's a bug of the compiler?

Regards,

Qiao

0 Kudos
Reply

2,472 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

I think the is not the root cause, because I used Lauterbach debugger and it is independent to S32 Design Studio. Important point is that it works now. Thanks for the cooperation.

Regards,

Martin

0 Kudos
Reply

2,472 Views
qiaodeng
Contributor II

Hi Martin,

 Really sorry to bother you again. Now the problem is that although the FlexCAN is initiated successfully, I can't transmit a message. I tried self reception mode and normal mode, after I write 0xC to the CS.CODE to activate the MB,  it didn't complete a transmission. The MB code is always 0xC,according to the manual it should returns to the INACTIVE state automatically .  Here is my transmission code :

void Transmit_Message()
{
CAN_0.MB[6].CS.B.CODE = 0x8; //MB TX inactive
CAN_0.MB[6].CS.B.IDE = 0; //extended bit disable
CAN_0.MB[6].ID.R = (0x555<<18); //set message STD ID
CAN_0.MB[6].DATA.W[1] = 0x90ABCDEF; //data1 set
CAN_0.MB[6].DATA.W[0] = 0x12345678; //data0 set
CAN_0.MB[6].CS.B.DLC = 8; //message length 8 bytes
CAN_0.MB[6].CS.B.RTR = 0; //remote frame disable
CAN_0.MB[6].CS.B.CODE = 0xC; //MB once transmit data
}

Regards,

Qiao

0 Kudos
Reply

2,472 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

could you please share your SIUL2 settings? It is possible, you have incorrectly configured GPIO pins. 

Do you use NXP EVB, or your own design board? Have you correctly connected CAN transceiver? 

Regards,

Martin

0 Kudos
Reply

2,472 Views
qiaodeng
Contributor II

Hi Martin,

I am using  MCAN2 of  MPC57xx EVB .Here is my SIUL2 code:

void Port_Init(void){
SIUL2.MSCR0_255[92].R = 0x32000008; /* Pad PF12: Source signal is CAN0_TX */
SIUL2.MSCR0_255[93].R = 0x00380000; /* Pad PF13: Enable pad for input - CAN0_RX */
SIUL2.MSCR512_995[700].R = 0x00000004;/* CAN0_RX: connected to pad PF13 */
}

The schematic of MSCAN2 is as follows, I have connected J32, J33,J23

pastedImage_1.png

0 Kudos
Reply

2,472 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

I found one error in your configuration.

Instead of SIUL2.MSCR512_995[700].R, you have to use SIUL2.MSCR512_995[188].R, because definition in header file is following:

#define SIUL2_MSCR700        SIUL2.MSCR512_995[188].R  

Regards,

Martin

0 Kudos
Reply

2,472 Views
qiaodeng
Contributor II

Hi Martin,

    I have corrected the SIUL2 error. Now FlexCAN transmits a message successfully , then it returns to freeze mode. Here is the Error Status Register I read from S32:

pastedImage_1.png

The attachment is my CAN code. Do you have any sample code of MPC5746R FlexCAN including sending and receiving message? It would be very helpful to speed up my work.

Regards,

Qiao

0 Kudos
Reply

2,472 Views
shanescott
Contributor III

Hi Qiao,

I had the same problem.  I believe it may have to do with using the FlexCAN while in debug mode.  Adding the following code allowed RX function to work for me:

CAN_0.CTRL2.B.ECRWRE = 0x01u; //enable MECR register updates
CAN_0.MECR.B.ECRWRDIS = 0x00u; //enable writes to the MECR register
CAN_0.MECR.B.NCEFAFRZ = 0x00u; //keep normal operation if memory error is detected
CAN_0.MECR.B.ECRWRDIS = 0x01u; //disable writes to the MECR register

Shane

0 Kudos
Reply