Thanks.
One of my other main clarification is I need to communicate between CAN A and CAN B flexcan peripherals. I'm setting pins required for the transceiver on my target board which has MPC5777c controller.
My clock configuration is 25MHZ and per clck configuration is 100MHZ . My desired baud rate is 500k baud.
Can I use the same configuration used in MPC 5777c example.
static void FlexCAN_A_Init(void)
{
uint32_t i = 0;
/* enable the FlexCAN module, reset and freeze */
CAN_A.MCR.R = (0
| CAN_MCR_FRZ /* enabled to enter Freeze mode */
| CAN_MCR_HALT /* enter freeze mode if FRZ bit is set */
| CAN_MCR_SOFTRST /* soft reset */
| CAN_MCR_SRXDIS /* self reception enabled */
| CAN_MCR_BCC /* individual Rx masking and queue */
| 0x0000003F);
/* wait until soft reset completes */
while(1 == CAN_A.MCR.B.SOFTRST) {};
/* double check that we are actually in freeze mode */
while(0 == CAN_A.MCR.B.FRZACK) {};
while(0 == CAN_A.MCR.B.NOTRDY) {};
CAN_A.CR.R = 0x04E40004; /* CAN bus: 40 MHz clksrc, 500K bps with 16 tq */
/* PRESDIV+1 = Fclksrc/Ftq = 40 MHz/8MHz = 5 */
/* so PRESDIV = 4 */
/* PSEG2 = Phase_Seg2 - 1 = 5 - 1 = 4 */
/* PSEG1 = PSEG2 = 4 */
/* PROPSEG= Prop_Seg - 1 = 5 - 1 = 4 */
/* RJW = Resync Jump Width - 1 = 4 - 1 = 1 */
/* SMP = 0: use 1 bit per CAN sample */
/* CLKSRC=0 (unchanged): Fcanclk= Fxtal= 40 MHz*/
// code to disable ECC reporting at all
CAN_A.CTRL2.B.ECRWRE = 1; // enable editing of MECR
CAN_A.MECR.B.ECRWRDIS = 0; // enable writes to MECR
CAN_A.MECR.R = 0x00000100; // disable ECC error ISR and disable ECC at all , keep normal operation
CAN_A.CTRL2.B.ECRWRE = 0; // lock the MECR again
/* Make first 32 message buffers inactive by writing their control fields
to "not active". They will be left inactive until we're ready for communication. */
for(i=0;i<64;i++)
{
CAN_A.BUF[i].CS.R = 0;
}
/* set mask registers - all ID bits must match */
for(i=0;i<64;i++)
{
CAN_A.RXIMR[i].R = 0x1FFFFFFF;
}
/* configure CNTX_A and CNRX_A pin functions on PCR83 and PCR84 */
SIU.PCR[83].R = 0x060C; /* CNTXA, push/pull, max slew rate */
SIU.PCR[84].R = 0x0503; /* CNRXA, weak pull device disabled */
/* Finally clear the HALT flag in MCR to enable the FlexCAN
* to synchronize with the CAN bus and allow
* participation in communication. */
CAN_A.MCR.B.HALT = 0;
/* wait until FlexCAN ready */
while(1 == CAN_A.MCR.B.FRZACK) {}
while(1 == CAN_A.MCR.B.NOTRDY) {}
}
/*******************************************************************************
Function Name : FlexCAN_B_Init
Engineer : PetrS
Date : Jul-22-2016
Parameters : NONE
Modifies : NONE
Returns : NONE
Notes : FlexCAN_B initialization
Issues : NONE
*******************************************************************************/
static void FlexCAN_B_Init(void)
{
uint32_t i = 0;
/* enable the FlexCAN module, reset and freeze */
CAN_B.MCR.R = (0
| CAN_MCR_FRZ /* enabled to enter Freeze mode */
| CAN_MCR_HALT /* enter freeze mode if FRZ bit is set */
| CAN_MCR_SOFTRST /* soft reset */
| CAN_MCR_SRXDIS /* self reception enabled */
| CAN_MCR_BCC /* individual Rx masking and queue */
| 0x0000003F);
/* wait until soft reset completes */
while(1 == CAN_B.MCR.B.SOFTRST) {};
/* double check that we are actually in freeze mode */
while(0 == CAN_B.MCR.B.FRZACK) {};
while(0 == CAN_B.MCR.B.NOTRDY) {};
CAN_B.CR.R = 0x04E40004; /* CAN bus: 40 MHz clksrc, 500K bps with 16 tq */
/* PRESDIV+1 = Fclksrc/Ftq = 40 MHz/8MHz = 5 */
/* so PRESDIV = 4 */
/* PSEG2 = Phase_Seg2 - 1 = 5 - 1 = 4 */
/* PSEG1 = PSEG2 = 4 */
/* PROPSEG= Prop_Seg - 1 = 5 - 1 = 4 */
/* RJW = Resync Jump Width - 1 = 4 - 1 = 1 */
/* SMP = 0: use 1 bit per CAN sample */
/* CLKSRC=0 (unchanged): Fcanclk= Fxtal= 40 MHz*/
// code to disable ECC reporting at all
CAN_B.CTRL2.B.ECRWRE = 1; // enable editing of MECR
CAN_B.MECR.B.ECRWRDIS = 0; // enable writes to MECR
CAN_B.MECR.R = 0x00000100; // disable ECC error ISR and disable ECC at all , keep normal operation
CAN_B.CTRL2.B.ECRWRE = 0; // lock the MECR again
/* Make first 32 message buffers inactive by writing their control fields
* to "not active". They will be left
* inactive until we're ready for communication. */
for(i=0;i<64;i++)
{
CAN_B.BUF[i].CS.R = 0;
}
/* set mask registers - all ID bits must match */
for(i=0;i<64;i++)
{
CAN_B.RXIMR[i].R = 0x1FFFFFFF;
}
/* configure CNTX_B and CNRX_B pin functions on PCR85 and PCR86 */
SIU.PCR[85].R = 0x060C; /* CNTXA, push/pull, max slew rate */
SIU.PCR[86].R = 0x0503; /* CNRXA, weak pull device disabled */
/* Finally clear the HALT flag in MCR to enable the FlexCAN
* to synchronize with the CAN bus and allow
* participation in communication. */
CAN_B.MCR.B.HALT = 0;
/* wait until FlexCAN ready */
while(1 == CAN_B.MCR.B.FRZACK) {}
while(1 == CAN_B.MCR.B.NOTRDY) {}
}
I tried with above configuration.
also I tried to change config as below
void FlexCAN_A_Init(void)
{
uint32_t i = 0;
//SIU.GPDO[148].R |= 0;
/* enable the FlexCAN module, reset and freeze */
CAN_A.MCR.R = (0
| CAN_MCR_FRZ /* enabled to enter Freeze mode */
| CAN_MCR_HALT /* enter freeze mode if FRZ bit is set */
| CAN_MCR_SOFTRST /* soft reset */
| CAN_MCR_SRXDIS /* self reception enabled */
| CAN_MCR_BCC /* individual Rx masking and queue */
| 0x0000003F);
/* wait until soft reset completes */
while(1 == CAN_A.MCR.B.SOFTRST) {};
/* double check that we are actually in freeze mode */
while(0 == CAN_A.MCR.B.FRZACK) {};
while(0 == CAN_A.MCR.B.NOTRDY) {};
/* CAN bus: 25 MHz clksrc, 300K bps with 16 tq */
/* PRESDIV+1 = Fclksrc/Ftq = 25 MHz/4.8MHz = 5 */
/* so PRESDIV = 4 */
/* PSEG2 = Phase_Seg2 - 1 = 5 - 1 = 4 */
/* PSEG1 = PSEG2 = 4 */
/* PROPSEG= Prop_Seg - 1 = 5 - 1 = 4 */
/* RJW = Resync Jump Width - 1 = 4 - 1 = 1 */
/* SMP = 0: use 1 bit per CAN sample */
/* CLKSRC=0 (unchanged): Fcanclk= Fxtal= 25 MHz*/
//CAN_A.CTRL1.R = 0x04E40004;
// CAN_A.CTRL1.B.PRESDIV = 4;
// CAN_A.CTRL1.B.PSEG2 = 4;
// CAN_A.CTRL1.B.PSEG1 = 4;
// CAN_A.CTRL1.B.RJW = 1;
// CAN_A.CTRL1.B.CLKSRC = 0;
// CAN_A.CTRL1.B.LPB = 0;
// CAN_A.CTRL1.B.SMP = 0;
// CAN_A.CTRL1.B.LOM = 0;
// CAN_A.CTRL1.B.PROPSEG = 4;
CAN_A.CTRL1.B.PRESDIV = 2;
CAN_A.CTRL1.B.PSEG2 = 1;
CAN_A.CTRL1.B.PSEG1 = 1;
CAN_A.CTRL1.B.RJW = 1;
CAN_A.CTRL1.B.CLKSRC = 0;
CAN_A.CTRL1.B.LPB = 0;
CAN_A.CTRL1.B.SMP = 0;
CAN_A.CTRL1.B.LOM = 0;
CAN_A.CTRL1.B.PROPSEG = 1;
// code to disable ECC reporting at all
CAN_A.CTRL2.B.ECRWRE = 1; // enable editing of MECR
CAN_A.MECR.B.ECRWRDIS = 0; // enable writes to MECR
CAN_A.MECR.R = 0x00000100; // disable ECC error ISR and disable ECC at all , keep normal operation
CAN_A.CTRL2.B.ECRWRE = 0; // lock the MECR again
/* Make first 32 message buffers inactive by writing their control fields
to "not active". They will be left inactive until we're ready for communication. */
for(i=0;i<64;i++)
{
CAN_A.MB[i].CS.R = 0;
}
/* set mask registers - all ID bits must match */
for(i=0;i<64;i++)
{
CAN_A.RXIMR[i].R = 0x1FFFFFFF;
}
/* Finally clear the HALT flag in MCR to enable the FlexCAN
* to synchronize with the CAN bus and allow
* participation in communication. */
CAN_A.MCR.B.HALT = 0;
/* wait until FlexCAN ready */
while(1 == CAN_A.MCR.B.FRZACK) {}
while(1 == CAN_A.MCR.B.NOTRDY) {}
}
could some one guide me I'm getting stuck here while(1 == CAN_A.MCR.B.FRZACK) {}.
Regards,
Vignesh