【MSPM0L1306 LaunchPad】printf打印输出
[复制链接]
本帖最后由 TL-LED 于 2023-10-12 18:36 编辑
这篇来测试下串口,使用函数printf 打印输出。
一、硬件部分
开发板仿真器自带串口,直接与MCU串口0连接
1.1、XDS110仿真器串口端口
1.2、仿真器与MCU连接
1.3、串口选择选择
二、程序部分
2.1、uart.c
#include "ti_msp_dl_config.h"
#include "uart/uart.h"
static const DL_UART_Extend_ClockConfig gUART_0ClockConfig = {
.clockSel = DL_UART_EXTEND_CLOCK_BUSCLK,
.divideRatio = DL_UART_EXTEND_CLOCK_DIVIDE_RATIO_1
};
static const DL_UART_Extend_Config gUART_0Config = {
.mode = DL_UART_EXTEND_MODE_NORMAL,
.direction = DL_UART_EXTEND_DIRECTION_TX_RX,
.flowControl = DL_UART_EXTEND_FLOW_CONTROL_NONE,
.parity = DL_UART_EXTEND_PARITY_NONE,
.wordLength = DL_UART_EXTEND_WORD_LENGTH_8_BITS,
.stopBits = DL_UART_EXTEND_STOP_BITS_ONE
};
void init_uart(uint32_t bps)
{
DL_UART_Extend_enablePower(UART_0_INST);
DL_GPIO_initPeripheralOutputFunction(GPIO_UART_0_IOMUX_TX, GPIO_UART_0_IOMUX_TX_FUNC);
DL_GPIO_initPeripheralInputFunction(GPIO_UART_0_IOMUX_RX, GPIO_UART_0_IOMUX_RX_FUNC);
DL_UART_Extend_setClockConfig(UART_0_INST, (DL_UART_Extend_ClockConfig *) &gUART_0ClockConfig);
DL_UART_Extend_init(UART_0_INST, (DL_UART_Extend_Config *) &gUART_0Config);
DL_UART_Extend_setOversampling(UART_0_INST, DL_UART_OVERSAMPLING_RATE_16X);
DL_UART_Extend_setBaudRateDivisor(UART_0_INST, CPUCLK_FREQ/(16*bps), CPUCLK_FREQ/(16*bps)%64);
/* Configure FIFOs */
// DL_UART_Extend_enableFIFOs(UART_0_INST);
// DL_UART_Extend_setRXFIFOThreshold(UART_0_INST, DL_UART_RX_FIFO_LEVEL_1_2_FULL);
// DL_UART_Extend_setTXFIFOThreshold(UART_0_INST, DL_UART_TX_FIFO_LEVEL_1_2_EMPTY);
// DL_UART_Extend_enableManchesterEncoding(UART_0_INST);
DL_UART_Extend_enable(UART_0_INST);
}
void uart_senddat(uint8_t dat)
{
DL_UART_Extend_transmitDataBlocking(UART_0_INST, dat);
}
int fputc(int ch, FILE *f)
{
uart_senddat((uint8_t)ch);
return ch;
}
2.2、uart.h
#ifndef _UART_H
#define _UART_H
#include <ti/driverlib/driverlib.h>
#include "stdio.h"
/* Defines for UART_0 */
#define UART_0_INST UART0
#define UART_0_INST_IRQHandler UART0_IRQHandler
#define UART_0_INST_INT_IRQN UART0_INT_IRQn
#define GPIO_UART_0_RX_PORT GPIOA
#define GPIO_UART_0_TX_PORT GPIOA
#define GPIO_UART_0_RX_PIN DL_GPIO_PIN_9
#define GPIO_UART_0_TX_PIN DL_GPIO_PIN_8
#define GPIO_UART_0_IOMUX_RX (IOMUX_PINCM10)
#define GPIO_UART_0_IOMUX_TX (IOMUX_PINCM9)
#define GPIO_UART_0_IOMUX_RX_FUNC IOMUX_PINCM10_PF_UART0_RX
#define GPIO_UART_0_IOMUX_TX_FUNC IOMUX_PINCM9_PF_UART0_TX
#define UART_0_BAUD_RATE (9600)
#define UART_0_IBRD_32_MHZ_9600_BAUD (208)
#define UART_0_FBRD_32_MHZ_9600_BAUD (21)
void init_uart(uint32_t bps);
void uart_senddat(uint8_t dat);
#endif
2.3、main.c
#include "ti_msp_dl_config.h"
#include "led/led.h"
#include "systick/systick.h"
#include "uart/uart.h"
int main(void)
{
SYSCFG_DL_init();
init_systick();
init_led();
init_uart(115200);
while (1)
{
led2_r_on();
delay_cycles(32000*100);
led2_r_off();
delay_cycles(32000*100);
printf("https://bbs.eeworld.com.cn/ \r\n");
}
}
三、程序运行
烧写程序,复位开发板,串口输出
|