AnsweredAssumed Answered

LPC54608 Can1 Configuration

Question asked by fatih ozen on Jul 31, 2018
Latest reply on Aug 1, 2018 by Victor Jimenez

Hello, 

 

I want to see datas on PIO0_0 and PIO0_1 via canbus. I arranged pin settings as follows.

Then I got confused lil bit. I referenced mcan loopback example in sdk2.0.2. This code works the same system with nxp evaluation board. in sdk's example can0 is used but I'm using can1.

 

Could anybody help me to configure it correctly ?

 

uint32_t port0_pin1_config = (/* Pin is configured as CAN1_TD */
IOCON_PIO_FUNC1 |
IOCON_PIO_MODE_PULLUP |
IOCON_PIO_INV_DI |
IOCON_PIO_DIGITAL_EN |
IOCON_PIO_INPFILT_OFF |
IOCON_PIO_SLEW_STANDARD |
IOCON_PIO_OPENDRAIN_DI);
IOCON_PinMuxSet(IOCON, 0U, 1U, port0_pin1_config);

 

const uint32_t port0_pin0_config = (/* Pin is configured as CAN1_RD */
IOCON_PIO_FUNC1 |
IOCON_PIO_MODE_PULLUP |
IOCON_PIO_INV_DI |
IOCON_PIO_DIGITAL_EN |
IOCON_PIO_INPFILT_OFF |
IOCON_PIO_SLEW_STANDARD |
IOCON_PIO_OPENDRAIN_DI);
IOCON_PinMuxSet(IOCON, 0U, 0U, port0_pin0_config);

 

 

 

 

 


void CAN1_IRQ1_IRQHandler(void)
{
MCAN_ClearStatusFlag(CAN1, CAN_IR_RF1N_MASK);
MCAN_ReadRxFifo(CAN1, 1, &rxFrame);
rxComplete = true;
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}

 

void CAN_getmsg(void)
{
for(int a=0;a<8;a++) {rcv_data[a] = *(rxFrame.data + a);}

MSG[1] = ((rcv_data[3] << 8) | rcv_data[2]);
MSG[2] = ((rcv_data[5] << 8) | rcv_data[4]);
MSG[3] = ((rcv_data[7] << 8) | rcv_data[6]);

Can_get_ID = rxFrame.id>>18U;
PRINTF("GET_ID: %x", Can_get_ID);
PRINTF(" DATA: ");
{PRINTF(" %d %d",rcv_data[0],rcv_data[1]);}
for(int a=1;a<4;a++)
{PRINTF(" %d",MSG[a]);}

}

 


int main(void)
{

CLOCK_SetClkDiv(kCLOCK_DivCan1Clk, 22U, true); // 180 / 22 = 8,2 mhz. 

BOARD_InitPins();
BOARD_BootClock180M(); // I copied it from another thread. it is working.

 

MCAN_GetDefaultConfig(&mcanConfig);
MCAN_Init(CAN1, &mcanConfig, CLOCK_GetFreq(kCLOCK_MCAN1));

 

MCAN_SetMsgRAMBase(CAN1, 0x20010000U);
uint32_t *p=(uint32_t *)(0x20010000U);
memset(p, 0, 0x20U + 0x10U);

 

rxFilter.address = 0x0;
rxFilter.idFormat = kMCAN_FrameIDStandard;
rxFilter.listSize = 1U;
rxFilter.nmFrame = kMCAN_reject1;
rxFilter.remFrame = kMCAN_rejectFrame;
MCAN_SetFilterConfig(CAN1, &rxFilter);

 

stdFilter.sfec = kMCAN_storeinFifo1;
stdFilter.sft = kMCAN_dual;
stdFilter.sfid1 = 0x000U;
stdFilter.sfid2 = 0x002U;
MCAN_SetSTDFilterElement(CAN1, &rxFilter, &stdFilter, 0);

 

rxFifo1.address = 0x10U;
rxFifo1.elementSize = 1U;
rxFifo1.watermark = 0;
rxFifo1.opmode = kMCAN_FifoBlocking;
rxFifo1.datafieldSize = kMCAN_8ByteDatafield;
MCAN_SetRxFifo1Config(CAN1, &rxFifo1);

 

MCAN_EnableInterrupts(CAN1, 0, CAN_IE_RF1NE_MASK);
EnableIRQ(CAN1_IRQ1_IRQn);

 

MCAN_EnterNormalMode(CAN1);

 

while (1)
{
CAN_getmsg();
}
}

Outcomes