这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 行业应用 » 汽车电子 » 【S32K3XX】Uart模块使用

共2条 1/1 1 跳转至

【S32K3XX】Uart模块使用

高工
2025-08-03 09:25:51     打赏

【简介】

我们在之前的帖子介绍过S32K1系列的MCU的UART 的使用(https://forum.eepw.com.cn/thread/393077/1),查看S32K3 的UART 的框图,IP 在设计上和S32K1 看上去是一致的。

image.png

我么继续使用S32DS来创建一个uart 工程来验证uart 输出功能。

【工程创建】

S32DS 下创建一个APP 程序选择对应的芯片型号jiproject 名称即可

image.png

根据个人配置选择SDK版本及使用的lib 类型,这样就创建完了工程

image.png

【时钟配置】

创建好工程后我们来配置时钟,Core 我们配置为使用内部FIRC 时钟源

image.png

本次试验使用UART6 的串口对应时钟配置如下

image.png


【PIN MUX 配置】

image.png

【UART 参数配置】

image.png


配置完成后生成初始化代码

image.png

初始化代码生成后,添加如下代码打印“hello world\r\n” 验证串口输出功能。

/* Including necessary configuration files. */
#include "Clock_Ip.h"
#include "Lpuart_Uart_Ip.h"
#include "Siul2_Port_Ip.h"

/* User includes */
/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/
int main(void)
{
/* Initialize the clock driver */
Clock_Ip_Init(Clock_Ip_aClockConfig);

/* Initialize all pins using the Port driver */
Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals);

Lpuart_Uart_Ip_Init(6,&Lpuart_Uart_Ip_xHwConfigPB_6);

/* Enable the LPUART transmitter */
Lpuart_Uart_Ip_SetTransmitterCmd(IP_LPUART_6,true);
/* Enable the LPUART receiver */
Lpuart_Uart_Ip_SetReceiverCmd(IP_LPUART_6, true);
char * ptr = "hello world\r\n";

for (int i = 0; i < 13; i++)
{
while((IP_LPUART_6->STAT & LPUART_STAT_TC_MASK)>>LPUART_STAT_TC_SHIFT==0);
IP_LPUART_6->DATA = *ptr;
ptr++;
}

return 0;
}


下载运行后串口已经按照预期的打印输出“hello world”

image.png







专家
2025-08-03 20:52:23     打赏
2楼

感谢分享


共2条 1/1 1 跳转至

回复

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