here we were developing CAN2 rx, tx code in evk mimxrt1050, so we have query that what is use of CAN_STBY? how to configure?
here we configure FlexCAN2 pin and STB pin below:
//** PIN configuration flex can2 on mxrt1050
void BOARD_InitPins(void) {
CLOCK_EnableClock(kCLOCK_Iomuxc);
/* GPIO configuration of CAN_STB_PIN on GPIO_AD_B0_05 */
gpio_pin_config_t CAN_STB_PIN_config = {
.direction = kGPIO_DigitalOutput,
.outputLogic = 0U,
.interruptMode = kGPIO_NoIntmode
};
/* Initialize GPIO functionality on GPIO_AD_B0_05 */
GPIO_PinInit(GPIO1, 1U, &CAN_STB_PIN_config);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_05_GPIO1_IO05, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_12_LPUART1_TXD, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_13_LPUART1_RXD, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_14_FLEXCAN2_TX, 1U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_15_FLEXCAN2_RX, 1U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B0_12_LPUART1_TXD, 0x10B0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B0_13_LPUART1_RXD, 0x10B0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B0_14_FLEXCAN2_TX, 0x10B0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B0_15_FLEXCAN2_RX, 0x10B0U);
}
here the CAN2 init function below:
static void CAN2_init(void) {
FLEXCAN_Init(CAN2_PERIPHERAL, &CAN2_config, CAN2_CLOCK_SOURCE);
/* Message buffer 9 initialization */
FLEXCAN_SetRxMbConfig(CAN2_PERIPHERAL, 9, &CAN2_rx_mb_config_0, true);
/* Message buffer 10 initialization */
FLEXCAN_SetTxMbConfig(CAN2_PERIPHERAL, 10, true);
FLEXCAN_SetRxIndividualMask(CAN2_PERIPHERAL, 9, FLEXCAN_RX_MB_STD_MASK(0x1AA, 0, 0));
}
also we set below parameter for CAN INIT anf MB configuration:
const flexcan_config_t CAN2_config = {
.wakeupSrc = kFLEXCAN_WakeupSrcUnfiltered,
.bitRate = 1000000UL,
.maxMbNum = 16U,
.enableLoopBack = false,
.enableTimerSync = true,
.enableSelfWakeup = false,
.enableIndividMask = false,
.disableSelfReception = false,
.enableListenOnlyMode = false,
.enableSupervisorMode = false,
.timingConfig = {
.preDivider = 2,
.propSeg = 1,
.phaseSeg1 = 3,
.phaseSeg2 = 2,
.rJumpwidth = 1
}
};
/* Message buffer 0 configuration structure */
const flexcan_rx_mb_config_t CAN2_rx_mb_config_0 = {
.id = FLEXCAN_ID_STD(0x1AA),
.format = kFLEXCAN_FrameFormatStandard,
.type = kFLEXCAN_FrameTypeData
};
also we use interrupt feature, code is below:
FLEXCAN_EnableMbInterrupts(CAN2_PERIPHERAL,9);
/* Enable interrupt CAN1_IRQn request in the NVIC. */
EnableIRQ(CAN2_IRQn);
also write a ISR function below:
void CAN2_FLEXCAN_IRQHANDLER(void)
{
/* If new data arrived, check Mb Status Flag */
if (0U != FLEXCAN_GetMbStatusFlags(CAN2_PERIPHERAL, 9))
{
/* Clear Mb Status Flag */
FLEXCAN_ClearMbStatusFlags(CAN2_PERIPHERAL, 9);
/* Read Message From Mb */
FLEXCAN_ReadRxMb(CAN2_PERIPHERAL, 9, &rxFrame);
rxComplete = true;
}
/* ISR exit barrier */
SDK_ISR_EXIT_BARRIER;
}
issue that our TX ,RX function not receive
same code on custom board mxrt1051 its working , we have use same code only change the pin configuration .