CAN driver is very general term. There are many CAN stacks with different functionality. I can provide you simple MCAN example, which is created for MPC5777C, but it is also possible to use it with MPC5777M. You should check GPIO settings and clocking, but the module is the same. Please look at the following URL:
Hi Martin Kovar ,Thank you, I checked the sample code given for MPC 5777C ,and Almost I tried initialization of M_CAN module except the two steps for M_CAN_Tx pin and M_CAN_Rx Pin initialization. I checked the MPC5777C sample code
SIU.PCR.R = 0x0E0C; /* MCAN0TX, push/pull, max slew rate */
SIU.PCR.R = 0x0D03; /* MCAN0RX, weak pull device disabled */
It is clearly given for the MPC 5777C ,But for MPC 5777M
As per the header file <MPC5777M.h> There are MSCR_IO[512 and MSCR_MUX registers are defined. I have got
one document for MPC5777M sending CAN FD messages , where I got the following.
So I am confused the configure the M_CAN_Tx and Rx Pin. Can you Please help me how to configure Tx and Rx Pins ?
it seems that the example you found is created in different IDE (maybe Green Hills) and it uses different header file.
So in your case you have use following construction:
SIUL2.MSCR_IO.R = value; /*set all required settings for MCAN1TX*/
SIUL2.MSCR_IO.R = value; /*set all required settings for MCAN1RX*/
SIUL.2.MSCR_MUX.SSS = 0x2 /*Connect MCAN1RX to PA*/
I know it is little bit complicated and I hope this will help you.
If you have any other questions, please feel free to write me back.
Hi Martin Kovar@ As per the sample code you provided ,I have written the code for initializing M_CAN_1 for MPC5777M.
for sending CAN messages
M_CAN_1.CCCR.B.INIT = 0x1; // set to initialization mode
while(M_CAN_1.CCCR.B.INIT == 0x0); // wait till previous written value has been accepted.
M_CAN_1.CCCR.B.CCE = 0x1; // unlock protected registers for configuration
// while(M_CAN_1.CCCR.B.CCE == 0x0); // wait till previous written value has been accepted.
M_CAN_1.CCCR.B.CMR = 0x0; // Request CAN Mode
M_CAN_1.CCCR.B.CME = 0x0; // Enable CAN Mode
M_CAN_1.TSCC.R = 0x00000000; // Time Stamp Counter
M_CAN_1.TOCC.R = 0x00000000; // Time out counter
M_CAN_1.IE.R = 0xFFFFFFFF; // Enable all interrupts.
M_CAN_1.ILS.R = 0xFFFFFFFF; // Interrupt Assigns to one of the two interrupt lines.
M_CAN_1.ILE.R = 0x00000003; // Enable two interrupt lines.
M_CAN_1.BTP.R = 0x00011E77; // Set time quanta for 0.5Mbps SYNC=1, TSEG1=30+1, TSEG2=7+1, SJW=7+1
M_CAN_1.GFC.R = 0x00111111; // Reject Non Matching Frames
M_CAN_1.SIDFC.R = 0x00020000; // Configuring Two Standard ID filters and its offset address.
M_CAN_1.TXBC.R = 0x00200300; // Setting up 2 Tx Buffers, Transmit Buffer Offset Address
M_CAN_1.RXF0C.R = 0x80020100; // Setting up 5 Rx FIFO 0 with overwrite new messages when fifo full and its offset address.
M_CAN_1.RXF1C.R = 0x00020200; // Setting up 5 Rx FIFO 1 with discard new messages when fifo full and its offset address
M_CAN_1.RXESC.R = 0x00000000; // 8 data bytes for Message FIFO 1 / 8 data bytes for Message FIFO 0
M_CAN_1.TXESC.R = 0x00000000; // 8 data bytes for Tx Buffer.
M_CAN_1.CCCR.B.CCE = 0x0; // disable CCE to prevent configuration changes
M_CAN_1.CCCR.B.INIT = 0x0; // Return to normal operation
while(M_CAN_1.CCCR.B.INIT == 0x1); // lock protected registers for configuration
//while((M_CAN_1.CCCR.R & 0x1) == 1);
SIUL2.MSCR_IO.R = 0x32000001; // Very Strong Drive,Push-Pull output enable MCAN1TX Pin, PA
SIUL2.MSCR_IO.R = 0x00080002; // Enable input buffer for MCAN1RX
SIUL2.MSCR_MUX.B.SSS = 0x2; // Connect MCAN1RX to PA
I Flashed the same code into the board, And I tried to debug ,when it encounters the M_CAN_1.CCCR.B.CCE = 0x1; instruction ,It is not taking.I dont why it is not taking ,Can you please help me how to resolve the issue.
try to move CAN TX/RX pin setting into initialization, means before clearing INIT bit at the end. Clearing this bit the module tries to synchronize to the bus, but probably cannot as pins are not set still.
You should open an Excel sheet attached to the RM to see I/O table.
Open the RM and press CTRL+SHIFT+A, in attachment window open an Excel sheet and select IO Signal Table tab.
The MCAN2 TX/RX signals can be located at PA and PA pins so the setting could be
SIUL2.MSCR_IO.R = 0x32000001; // Very Strong Drive,Push-Pull output enable MCAN2 TX Pin, PA
SIUL2.MSCR_IO.B.IBE = 0x1; // Enable input buffer for MCAN2 RX
SIUL2.MSCR_MUX[759-512].B.SSS = 0x2; // Connect MCAN2 RX to PA
Hi Petr Stancik, Thank you for your reply, I Did not get any attachment with RM,So I am unable to locate it ,Currently I am using S32 IDE Power Pc V1.1 and MPC 57xx MB with MPC5777M in Ubuntu 14.04 ,
One thing I want to share with you is ,Currently I am written CAN_driver for the above hardware code as per the sample code provided for MPC5777C provided in the Examples provided by NXP. So I have seen the author is you only.
Currently I am working Error Handling .How we can do error handle in transmitting messages and receiving messages. I am not sure ?