在线时间103 小时
UID3332856
注册时间2016-11-28
NXP金币251
TA的每日心情 | 擦汗 2024-11-7 09:48 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]初来乍到
金牌会员
 
- 积分
- 1188
- 最后登录
- 2025-2-8
|
本帖最后由 北方. 于 2020-9-23 11:59 编辑
1. 本次使用的过程中,发现串口的使用驱动LUART可以连接,但是使用调试串口就无法显示内容
串口驱动使用
#include "fsl_lpuart.h"
调试串口使用,
#include "fsl_debug_console.h"
其实,只是重写了串口1,UART0,但是有可能被占用了,所有有冲突。就是使用起来有些不方便,不影响后面的工作,
2、贴出一个使用串口的代码,运行后可以正确显示
3. 代码如下,- #include "board.h"
- #include "fsl_lpuart.h"
- #include "clock_config.h"
- #include "pin_mux.h"
- /*******************************************************************************
- * Definitions
- ******************************************************************************/
- #define DEMO_LPUART LPUART0
- #define DEMO_LPUART_CLKSRC BOARD_DEBUG_UART_CLKSRC
- #define DEMO_LPUART_CLK_FREQ CLOCK_GetFreq(BOARD_DEBUG_UART_CLKSRC)
- /*******************************************************************************
- * Prototypes
- ******************************************************************************/
- /*******************************************************************************
- * Variables
- ******************************************************************************/
- uint8_t txbuff[] = "Lpuart polling example\r\nBoard will send back received characters\r\n";
- uint8_t rxbuff[20] = {0};
- /*******************************************************************************
- * Code
- ******************************************************************************/
- /*!
- * @brief Main function
- */
- int main(void)
- {
- uint8_t ch;
- lpuart_config_t config;
- BOARD_InitPins();
- BOARD_BootClockRUN();
- CLOCK_SetLpuart0Clock(0x1U);
- /*
- * config.baudRate_Bps = 115200U;
- * config.parityMode = kLPUART_ParityDisabled;
- * config.stopBitCount = kLPUART_OneStopBit;
- * config.txFifoWatermark = 0;
- * config.rxFifoWatermark = 0;
- * config.enableTx = false;
- * config.enableRx = false;
- */
- LPUART_GetDefaultConfig(&config);
- config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
- config.enableTx = true;
- config.enableRx = true;
- LPUART_Init(DEMO_LPUART, &config, DEMO_LPUART_CLK_FREQ);
- LPUART_WriteBlocking(DEMO_LPUART, txbuff, sizeof(txbuff) - 1);
- while (1)
- {
- LPUART_ReadBlocking(DEMO_LPUART, &ch, 1);
- LPUART_WriteBlocking(DEMO_LPUART, &ch, 1);
- }
- }
复制代码
简析,这个首先定义数据然后就显示出具体的串口配置,直接调用串口块写入,使用轮询的方式写入。
|
|