这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 行业应用 » 汽车电子 » 【S32K3学习整理】LPUART Loop Mode 使用

共1条 1/1 1 跳转至

【S32K3学习整理】LPUART Loop Mode 使用

高工
2026-09-09 12:50:20     打赏

【简介】

我们在之前的帖子中介绍了上S32K3 的LPUART 模块的使用,查看手册LPUART 是支持Loop Moode 的可以不依赖外部PIN脚的配置来验证LPUART 的收发功能,以下是 Loop Moode 的功能介绍。

image.png

上述描述依赖的信号说明如下:

image.png

参照UART 的框图Loop Mode 使能后发送的数据对接到receive data in

image.png

image.png


本地配置LPUART1 为loop mode ,在配置工具中使能LPUART1 的回环模式即可。

image.png

使能loop mode 后生成的代码的UART1 的Loopback 的配置修改为TRUE,本地修改代码实际配置的为UART3.

image.png

中断配置中启动uart 的中断配置。

image.png

配置完成后添加如下的测试代码,验证UART 的loopback 功能。

#if defined(LPUART_UART_IP_INSTANCE_USING_3)
    static uint8_t uart3_rx_data;
#endif
static int lpuart_init(void)
{
#if defined(LPUART_UART_IP_INSTANCE_USING_1)
    static uint8_t uart1_rx_data;
    LOG_I("LPUART1 init.");
    Lpuart_Uart_Ip_Init(1,&Lpuart_Uart_Ip_xHwConfigPB_1);

    /* Enable the LPUART transmitter */
    Lpuart_Uart_Ip_SetTransmitterCmd(IP_LPUART_1,true);
    /* Enable the LPUART receiver */
    Lpuart_Uart_Ip_SetReceiverCmd(IP_LPUART_1, true);

    /* open uart rx data full event */
    Lpuart_Uart_Ip_SetIntMode(IP_LPUART_1, LPUART_UART_IP_INT_RX_DATA_REG_FULL, true);

    Lpuart_Uart_Ip_AsyncReceive(1,&uart1_rx_data,1);
#endif

#if defined(LPUART_UART_IP_INSTANCE_USING_3)
    LOG_I("LPUART3 init.");
    Lpuart_Uart_Ip_Init(3,&Lpuart_Uart_Ip_xHwConfigPB_3);

    /* Enable the LPUART transmitter */
    Lpuart_Uart_Ip_SetTransmitterCmd(IP_LPUART_3,true);
    /* Enable the LPUART receiver */
    Lpuart_Uart_Ip_SetReceiverCmd(IP_LPUART_3, true);

    /* open uart rx data full event */
    Lpuart_Uart_Ip_SetIntMode(IP_LPUART_3, LPUART_UART_IP_INT_RX_DATA_REG_FULL, true);

    Lpuart_Uart_Ip_AsyncReceive(3,&uart3_rx_data,1);
#endif
    return 1;
}


#if defined(LPUART_UART_IP_INSTANCE_USING_3)
void lpuart3_callback_handler(const Lpuart_Uart_Ip_EventType Event,const void *UserData)
{
    if(Event == LPUART_UART_IP_EVENT_RX_FULL)
    {
        /* Get date and write to ringbuffer */
        PRINTF("%c\n", uart3_rx_data);
    }
    /* Start to recive uart data */
    if(Event == LPUART_UART_IP_EVENT_END_TRANSFER)
        Lpuart_Uart_Ip_AsyncReceive(3,&uart3_rx_data,1);

    if(Event == LPUART_UART_IP_EVENT_ERROR)
        Lpuart_Uart_Ip_AsyncReceive(3,&uart3_rx_data,1);
}
#endif

unsigned int uart(char argc, char **argv)
{
    if(strcmp(argv[1],"send") == 0)
    {
        char *ptr = "hello";
        for (int i = 0; i < 5; i++)
        {
            while((IP_LPUART_3->STAT & LPUART_STAT_TC_MASK)>>LPUART_STAT_TC_SHIFT==0);
            IP_LPUART_3->DATA = ptr[i];
            vTaskDelay(1);
        }
    }
    return 0;
}

   

本地触发往uart3 写入数据“hello”,本地loopback 模式按照预期的接收到数据。

image.png

           


共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]