I have a problem about the baud rate of linflexd_uart in MPC5746R.
I set the baud rate at 9600 but i can't get the 9600 baud rate information in Oscilloscope.
I didn't know what's problem with this. Can you help me ?
I want to send the date by MPC5746R and receive the date by the computer.
This is my code about uart.
int main(void)
{
/* Write your local variable definition here */
#define BUF_LEN 1U
uint8_t test_mode[BUF_LEN];
uint8_t rxBuff[BUF_LEN + 1];
uint16_t RX_ok = 0x23U;
/* Store configuration into structure */
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
/* Change clock settings */
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
/* Initialize Pin Settings */
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
/* Initialize Uart */
LINFLEXD_UART_DRV_Init(INST_LINFLEXD_UART1, &linflexd_uart1_State, &linflexd_uart1_InitConfig0);
LINFLEXD_UART_DRV_Init(INST_LINFLEXD_UART2, &linflexd_uart2_State, &linflexd_uart2_InitConfig0);
LINFLEXD_UART_DRV_SetBaudRate(INST_LINFLEXD_UART1,9600);
LINFLEXD_UART_DRV_SetBaudRate(INST_LINFLEXD_UART2,9600);
while(1) {
// LINFLEXD_UART_DRV_ReceiveDataBlocking(INST_LINFLEXD_UART1, (uint8_t*)rxBuff, BUF_LEN, 300U);
// test_mode[0]=rxBuff[0]+1;
test_mode[0]=0x61;
// LINFLEXD_UART_DRV_SendDataBlocking(INST_LINFLEXD_UART2,(uint8_t*)test_mode, BUF_LEN,300U);
LINFLEXD_UART_DRV_SendData(INST_LINFLEXD_UART2, (uint8_t*)test_mode, BUF_LEN);
// if ( rxBuff[0] == 1)
// {
// RX_ok = 1;
// }
}
My rose =0 , LINIBRR = 0x068 (Hex) = 104 d ,LIN_clk = 16Mhz.
baud rate = 16M/(16*104) = 9615 bit/s.
the width of date is 16.8us but 9600 baud rate is 104us.
Hi,
could you share your project to reproduce the issue?
Thanks,
Lukas
Hello!
I investigated the issue and indeed there seems to be a confusion in the clock configuration.
According to the reference manual:
LINFLEXD clock source can be changed through Device Configuration records, which are write-once and not configurable through the SDK. Nevertheless, the SDK only considers one of the two options, which apparently is not the correct one on your side.
In your case, the LIN peripheral clock must be SYS_CLK.
As a workaround to get the desired baudrate you need to have the same frequency configured for SYS_CLK and LINFLEX instances (either change LIN clock source to PLL or change sys_clk source to IRCOSC):
or
(in the latter case you'll get a warning, as LIN peripheral clock is supposed to be less than 80MHz).
Another solution (a bit more complicated) would be to write the appropriate DCF entry to switch to the other LINFLEX clocking option (please check section 57.4.7.8 in the reference manual).
Hope this helps!
Regards,
Vlad