This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
大家好、
我正在尝试通过 PD0和 PD1上的 UART1发送数据、但 Tx 引脚未发送数据。 我是否遗漏了什么。 我已经修改了 UART_loopback 示例代码中的代码
//***************************************************************************** // // uart_echo.c - Example for reading data from and writing data to the UART in // an interrupt driven fashion. // // Copyright (c) 2011-2017 Texas Instruments Incorporated. All rights reserved. // Software License Agreement // // Texas Instruments (TI) is supplying this software for use solely and // exclusively on TI's microcontroller products. The software is owned by // TI and/or its suppliers, and is protected under applicable copyright // laws. You may not combine this software with "viral" open-source // software in order to form a larger program. // // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL // DAMAGES, FOR ANY REASON WHATSOEVER. // // This is part of revision 2.1.4.178 of the DK-TM4C123G Firmware Package. // //***************************************************************************** // LED anode is tied to 3.3V and cathode to 1k resistor and finally to PB1 #include <stdint.h> #include <stdbool.h> #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "driverlib/debug.h" #include "driverlib/fpu.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "driverlib/rom.h" #include "grlib/grlib.h" #include "drivers/cfal96x64x16.h" #ifdef DEBUG void __error__(char *pcFilename, uint32_t ui32Line) { } #endif int main(void) { ROM_FPULazyStackingEnable(); ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // Set the clocking to run directly from the crystal. //Init UART0 SysCtlDelay(10); //Init UART1 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // Enable the peripherals used by UART 1 SysCtlDelay(10000); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); SysCtlDelay(10000); ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); // Set GPIO B0 and B1 as UART pins SysCtlDelay(10000); ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |UART_CONFIG_PAR_NONE)); // Configure the UART0 for 9600, 8-N-1 operation SysCtlDelay(10000); while(1) { ROM_UARTCharPut(UART1_BASE,'1'); SysCtlDelay(1000000); } }
找到问题。 出于某种原因、必须明确配置各个引脚 PB0和 PB1、使其作为 TX 和 RX 工作。 必须添加三行代码
#include "driverlib/pin_map.h"
GPIOPinConfigure (GPIO_PB0_U1RX);
GPIOPinConfigure (GPIO_PB1_U1TX);