LPC546 MCAN Buadrate update

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

LPC546 MCAN Buadrate update

836件の閲覧回数
emb02
Contributor IV

I am working on LPC546 for CAN Protocol

I am setting baudrate using config tools but I want to update required baudrate without using config tools but using setbaudratefunction.. 

When I am trying to use setbaudratefunction and updating baudrate communication happen only on baudrate which was previously set in config tools.

Please guide me.

Thank you.

ラベル(1)
タグ(3)
0 件の賞賛
返信
1 返信

793件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

In the SDK example, there is _mcan_interrupt_transfer example, I copy the code here. As you know that the LPC54628 support CAN-FD feature, the baudrate for the control bits transfer and data bits transfer in the same CAN packet is different. The following code initialize baud rate for both the control bits and data bits in MCAN_Init().

MCAN_GetDefaultConfig(&mcanConfig);
#if (defined(USE_CANFD) && USE_CANFD)
/* Enable Bit Rate Switch to make baudRateD make sense.*/
mcanConfig.enableCanfdSwitch = true;
#endif

#if (defined(USE_IMPROVED_TIMING_CONFIG) && USE_IMPROVED_TIMING_CONFIG)
mcan_timing_config_t timing_config;
memset(&timing_config, 0, sizeof(timing_config));
#if (defined(USE_CANFD) && USE_CANFD)
if (MCAN_FDCalculateImprovedTimingValues(mcanConfig.baudRateA, mcanConfig.baudRateD, MCAN_CLK_FREQ, &timing_config))
{
/* Update the improved timing configuration*/
memcpy(&(mcanConfig.timingConfig), &timing_config, sizeof(mcan_timing_config_t));
}
else
{
PRINTF("No found Improved Timing Configuration. Just used default configuration\r\n\r\n");
}
#else
if (MCAN_CalculateImprovedTimingValues(mcanConfig.baudRateA, MCAN_CLK_FREQ, &timing_config))
{
/* Update the improved timing configuration*/
memcpy(&(mcanConfig.timingConfig), &timing_config, sizeof(mcan_timing_config_t));
}
else
{
PRINTF("No found Improved Timing Configuration. Just used default configuration\r\n\r\n");
}
#endif
#endif

MCAN_Init(EXAMPLE_MCAN, &mcanConfig, MCAN_CLK_FREQ);

 

After above initialization, you can use the function to set up the baudrate for the control bits, but you have to know the seg1, seg2, pls refer to section 35.8.4 Nominal bit timing and prescaler register in UM10912.pdf.

static void MCAN_SetBaudRate(CAN_Type *base,
uint32_t sourceClock_Hz,
uint32_t baudRateA_Bps,
mcan_timing_config_t timingConfig)

 

you can use the function to set up the baudrate for the data bits transfer, but you have to know the seg1, seg2, pls refer to section 35.8.1 Data bit timing and prescaler register in UM10912.pdf.

static void MCAN_SetBaudRateFD(CAN_Type *base,
uint32_t sourceClock_Hz,
uint32_t baudRateD_Bps,
mcan_timing_config_t timingConfig)

 

Hope it can help you

BR

XiangJun Rong

 

0 件の賞賛
返信