Manjunath K M

KEA128 CAN driver problem

Discussion created by Manjunath K M on Mar 27, 2017

Hello,

I am working on CAN driver for KEA128 microcontroller. I have referred some of the sample code and prepared CAN driver.
But I am not able make it work. I am not able to see pulses on the TX pin of the controller on the uC.

Below is CLK code to obtain 48MHZ:
ICS_C1 = (1 << ICS_C1_IREFSTEN_SHIFT)
| ICS_C1_CLKS(0)
| (1 << ICS_C1_IRCLKEN_SHIFT);
while (!(ICS_S & ICS_S_LOCK_MASK)); // wait for FLL to lock
SIM_CLKDIV = SIM_CLKDIV_OUTDIV1(0)
| (1 << SIM_CLKDIV_OUTDIV2_SHIFT)
| (0 << SIM_CLKDIV_OUTDIV3_SHIFT);
ICS_C2 = ICS_C2_BDIV(0);

Below is the CAN Init code:
void Can_Init(uint8 Baudrate)
{
/* Enter to Initial mode. */
MSCAN_CANCTL0 = INITMODE_CAN0;

while(REG_CANCTL1_INITAK_CAN0 == INITMODE_BIT_CAN0)
{
/* Wait for init acknowledge */
}
/* Set the Control Register. */
REG_CANCTL1_CAN0 = CANCTL1_CAN0;

/* Set the Control Register. */
REG_CANBTR1_CAN0 = CANBTR1_CAN0;

if(Baudrate == CAN_BAUDRATE_500K)
{
/* Set the Control Register. */
REG_CANBTR0_CAN0 = CANBTR0_CAN_500K;
Can_BaudRate_Status = CAN_BAUDRATE_500K;
}
else if(Baudrate == CAN_BAUDRATE_250K)
{
/* Set the Control Register. */
REG_CANBTR0_CAN0 = CANBTR0_CAN_250K;
Can_BaudRate_Status = CAN_BAUDRATE_250K;
}
else
{
/* No Actions Required */
}
/* Set the Acceptance filter register. */
REG_CANIDAC_CAN0 = ACC_FILTER_CAN0;

/* Set the Message Object Acceptance Code. */
REG_CANIDAR0_CAN0 = ID_CODE0_CAN0;
REG_CANIDAR1_CAN0 = ID_CODE1_CAN0;
REG_CANIDAR2_CAN0 = ID_CODE2_CAN0;
REG_CANIDAR3_CAN0 = ID_CODE3_CAN0;
REG_CANIDAR4_CAN0 = ID_CODE4_CAN0;
REG_CANIDAR5_CAN0 = ID_CODE5_CAN0;
REG_CANIDAR6_CAN0 = ID_CODE6_CAN0;
REG_CANIDAR7_CAN0 = ID_CODE7_CAN0;
/* Set the Identifier mask register */
REG_CANIDMR0_CAN0 = ID_MASK0_CAN0;
REG_CANIDMR1_CAN0 = ID_MASK1_CAN0;
REG_CANIDMR2_CAN0 = ID_MASK2_CAN0;
REG_CANIDMR3_CAN0 = ID_MASK3_CAN0;
REG_CANIDMR4_CAN0 = ID_MASK4_CAN0;
REG_CANIDMR5_CAN0 = ID_MASK5_CAN0;
REG_CANIDMR6_CAN0 = ID_MASK6_CAN0;
REG_CANIDMR7_CAN0 = ID_MASK7_CAN0;
//MSCAN_CANCTL0 |=(0x40);
/* Exit to Initial mode. */
REG_CANCTL0_CAN0 &= NORMALMODE_CAN0;

while(MSCAN_CANCTL1 & 0x01)
{
/* Wait for init exit. */
}
/* Set the Control mode register. */
REG_CANCTL0_CAN0 = CANCTL0_CAN0;

/* Set the interrupt TX and RX register. */
#if (ERROR_INDICATION_CAN0 == CAN_TRUE)
REG_CANRIER_CAN0 = RXFIE_CAN0|OVRIE_CAN0|TSTATE0_CAN0|TSTATE1_CAN0|RSTATE0_CAN0|RSTATE1_CAN0|
CSCIE_CAN0|WUPIE_CAN0;
#else
REG_CANRIER_CAN0 = RXFIE_CAN0;
#endif
REG_CANTIER_CAN0 = TXEIE_DISABLE_CAN0;

}
void MSCAN_ModuleEn(void)
{
/*Enable MSCAN Module*/
SIM_PINSEL1 &= (uint32_t)~(uint32_t)(SIM_PINSEL1_MSCANPS_MASK);/* SIM_PINSEL1: MSCANPS=0 */
SIM_SCGC |=(uint32_t)(SIM_SCGC_MSCAN_MASK);/* SIM_SCGC: MSCAN=1 */
/* NVIC_ICER: CLRENA31=0,CLRENA30=0,CLRENA29=0,CLRENA28=0,CLRENA27=0,CLRENA26=0,CLRENA25=0,CLRENA24=0,CLRENA23=0,CLRENA22=0,CLRENA21=0,CLRENA20=0,CLRENA19=0,CLRENA18=0,CLRENA17=0,CLRENA16=0,CLRENA15=0,CLRENA14=0,CLRENA13=0,CLRENA12=0,CLRENA11=0,CLRENA10=0,CLRENA9=0,CLRENA8=0,CLRENA7=0,CLRENA6=0,CLRENA5=0,CLRENA4=0,CLRENA3=0,CLRENA2=0,CLRENA1=0,CLRENA0=0 */

//NVIC->ICER[0] = 0x00U;
/* NVIC_IPR7: PRI_31=1,PRI_30=1 */
NVIC_SetPriority(MSCAN_RX_IRQn, 1);
NVIC_SetPriority(MSCAN_TX_IRQn, 1);

/* NVIC_ISER: SETENA31=1,SETENA30=1,SETENA29=0,SETENA28=0,SETENA27=0,SETENA26=0,SETENA25=0,SETENA24=0,SETENA23=0,SETENA22=0,SETENA21=0,SETENA20=0,SETENA19=0,SETENA18=0,SETENA17=0,SETENA16=0,SETENA15=0,SETENA14=0,SETENA13=0,SETENA12=0,SETENA11=0,SETENA10=0,SETENA9=0,SETENA8=0,SETENA7=0,SETENA6=0,SETENA5=0,SETENA4=0,SETENA3=0,SETENA2=0,SETENA1=0,SETENA0=0 */
NVIC_EnableIRQ(MSCAN_RX_IRQn);
NVIC_EnableIRQ(MSCAN_TX_IRQn);
// __asm("CPSIE i");
}

Here is my MAIN function:
Clk_Init();
MSCAN_ModuleEn();
Can_Init(CAN_BAUDRATE_500K);
while(1)
{
Can_Transmit(0x18123456, 8, (uint8_t *)"ABCDEFGH", CAN_EXTENDED);
}

..

I have attached Source files also along with.

Can somebody help me to find out where the problem is?

Thanks and regards,
Manjunath

Original Attachment has been moved to: CAN_impl.zip

Outcomes