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.
对其可能关注的人,
我尝试使用端口 D 引脚 PD6 和 PD7进行 UART 通信,但未成功。 我已经完成了适当设置 PIN 的步骤,我想了很多。 随附了一份 txt 文档,其中包含用于为 UART 设置端口 D 的代码以及 TI Launchpad (TM4C123GH6PM)的数据表。 以下是我完成的步骤。
) 通过写入 GPIOLOCK 寄存器(PG.684)解锁引脚 PD7
// ***** 1. Pre-processor Directives Section ***** #include <stdio.h> // standard C library //This program prompts the user to enter a g (green), b (blue), or r (red) in the command UART window and responds by turning on the approporiate LED. //If an entry is wrong the user is prompted again. #define RCGCUART_UART_CLOCKING (*((volatile unsigned long *)0x400FE618))//Writing to this register to control the clocking of the UART modules (PORTD)(PG.344) #define GPIOAMSEL_GPIO_ANALOG_ENABLE_DISABLE (*((volatile unsigned long *)0x40007528))//Disabling the analog function (PG.687) #define RCGC2_GPIO_CLOCK (*((volatile unsigned long *)0x400FE108)) //Clock enable for legacy software (PG.464) Legacy register. #define RCGCGPIO_CLOCK_ENABLE (*((volatile unsigned long *)0x400FE608))//Enabling the clock to PORTD by writing to this register (PG.340) #define GPIOAFSEL_ALTFUNCTION_CONTROL (*((volatile unsigned long *)0x4007420))//Setting the pins in this register to allow pins in PORTD to be controlled by an alt function (PG.671_ #define GPIOPCTL_ALTFUNCTION_SELECT (*((volatile unsigned long *)0x4000752C))//Selecting which pins your applying the alt function to(PG.688) #define GPIODEN_DIGITAL_PIN_ENABLE (*((volatile unsigned long *)0x4000751C))//Enabling PORTD pins as digital I/O (PG.682) #define UARTCTL_UART_ENABLE_DISABLE (*((volatile unsigned long *)0x4000E030))//Disabling the UART to setup the baud rate, serial parameters, and UART2 clock source (PG.918) #define UARTIBRD_UART_BAUDRATE_INTEGER (*((volatile unsigned long *)0x4000E024))//Writing the appropriate value for the integer part of the baud rate UART2 (PG.914) #define UARTFBRD_UART_BAUDRATE_FRACTIONAL (*((volatile unsigned long *)0x4000E028))//Writing the appropriate value for the fractional part of the baud rate for UART2 (PG.915) #define UARTLCRH_SERIAL_PARAMETERS (*((volatile unsigned long *)0x4000E02C))//Setting up the serial parameter (data length, parity pits, stop bits, etc.) for UART2 (PG.916) #define UARTCC_UART_CLOCK_SOURCE (*((volatile unsigned long *)0x4000EFC8))//Configuring the UART2 clock source (PG.939) //The next define statements are for the LED_Config() function #define RCGC2_GPIO_PORTF (*((volatile unsigned long *)0x400FE108)) //PORTF clock enable (PG.464) #define GPIODIR_DIR_PORTF (*((volatile unsigned long *)0x40025400)) //Setting the bits in this register configures a GPIO pin to be an output, clearing configures it to be an input(PG.663) #define GPIODEN_DIGITAL_ENABLE_PORTF (*((volatile unsigned long *)0x4002551C)) //Setting the pins here enables their digital functions......clearing them disables the digital functions (PG.682) #define GPIO_PORTF_DATA (*((volatile unsigned long *)0x400253FC)) //Memory location of PORTF that you can write to to turn off/on LED's? //The next define statements are for the read functions accepting user input #define UARTFR_Flag_Register (*((volatile unsigned long *)0x4000E018)) //The flag register saying that FIFO is receiving/transferring data for UART2 (PG.911) #define UARTDR_FIFO_DATA_REGISTER (*((volatile unsigned long *)0x4000E000)) //This is the data register aka the interface to the FIFO's. This is were data is written to when using FIFO(PG.906 #define GPIOLOCK_LOCK_REGISTER (*((volatile unsigned long *)0x40007520)) //GPIO lock register #define GPIOCR_COMMIT_REGISTER (*((volatile unsigned long *)0x40007524)) //GPIO Commit register // ***** Subroutines Section ***** void Uart_Init(void); void LED_Config (void); char readChar (void); void printChar (char c); void printString (char *string); int main (void) { char c; //Calling the UART initialization function Uart_Init(); //Calling the LED configuration function LED_Config(); //printString("Enter \"r\",\"g\",or\"b\":\n\r"); printString("Enter \"r\",\"g\",\"w\",\"s\",or\"b\":\n\r"); while(1) { printString("Enter \"r\",\"g\",\"w\",\"s\",or\"b\":\n\r"); c = readChar(); printChar(c); printString("\n\r"); switch(c) { case 'r': GPIO_PORTF_DATA = (1<<1); //Turns on the red LED break; case 'b': GPIO_PORTF_DATA = (1<<2); //Turns on the blue LED break; case 'g': GPIO_PORTF_DATA = (1<<3);//Turns on the green LED break; case 'w': GPIO_PORTF_DATA = 0x0E;//Turns on the white LED break; case 's': GPIO_PORTF_DATA = 0x0C;//Turns on the sky blue LED break; default: GPIO_PORTF_DATA &= ~((1<<1) | (1<<2) | (1<<3)); } } } void Uart_Init(void) { GPIOLOCK_LOCK_REGISTER = 0x4C4F434B; GPIOCR_COMMIT_REGISTER = 11111111; //Enabling and providing a clock to UART module 2 in run mode. RCGCUART_UART_CLOCKING |= 0x04; //Enabling and providing a clock to GPIO PORTD in run mode. //RCGC2_GPIO_CLOCK |= (1<<3); //Enabling and providing a clock to GPIO PORTD in run mode. RCGCGPIO_CLOCK_ENABLE |= 0x08; //Setting pins PD6 and PD7 to be controlled by a peripheral mode (UART2) GPIOAFSEL_ALTFUNCTION_CONTROL |= 0xC0; //Selecting the UART perihparal mode for pins PA0 and PA1 //GPIOPCTL_ALTFUNCTION_SELECT |= (1<<24) | (1<<28); /*GPIOPCTL_ALTFUNCTION_SELECT = (1<<24); GPIOPCTL_ALTFUNCTION_SELECT = (1<<28);*/ //Selecting the UART peripheral mode for pins PD6 and PD7 GPIOPCTL_ALTFUNCTION_SELECT = (GPIOPCTL_ALTFUNCTION_SELECT&0x00FFFFFF) + 0x11000000; //Enabling the digital I/O for pins PD6 and PD7 GPIODEN_DIGITAL_PIN_ENABLE |= 0xC0; //Disabling the UARTEN pin in this register so I can set the baud rate and serial parameters UARTCTL_UART_ENABLE_DISABLE &= ~(0x01); //Writing the integer part as 104 of the baud rate to make it 9600bps UARTIBRD_UART_BAUDRATE_INTEGER = 104; //Writing the decimal part as 11 of the baud rate to make it 9600bps UARTFBRD_UART_BAUDRATE_FRACTIONAL = 11; //Setting up the serial parameter here as 8-bit, no parity, and 1 stop-bit UARTLCRH_SERIAL_PARAMETERS = (0x3<<5); //Setting up the baud clock source as "system clock" UARTCC_UART_CLOCK_SOURCE = 0x00; //Enabling the UARTEN pin this register UARTCTL_UART_ENABLE_DISABLE |= (1<<0) | (1<<8) | (1<<9); //UARTCTL_UART_ENABLE_DISABLE |= 0x00000001; //Disabling the analog function on pins D6 and D7 GPIOAMSEL_GPIO_ANALOG_ENABLE_DISABLE &= ~0xC0; } void LED_Config (void) { //Enabling the clock to PORTF RCGC2_GPIO_PORTF |= (1<<5); //Setting pins PF1, PF2, and PF3 as outputs for the LED's attached to these pins GPIODIR_DIR_PORTF = (1<<1) | (1<<2) | (1<<3); //Enabling the digital functions on the LED pins GPIODEN_DIGITAL_ENABLE_PORTF = (1<<1) | (1<<2) | (1<<3); //Turns off the LED's GPIO_PORTF_DATA &= ~((1<<1) | (1<<2) | (1<<3)); } char readChar (void) { char c; while ((UARTFR_Flag_Register & (1<<4)) != 0); c = UARTDR_FIFO_DATA_REGISTER; return c; } void printChar (char c) { while ((UARTFR_Flag_Register & (1<<5)) != 0); UARTDR_FIFO_DATA_REGISTER = c; } void printString (char *string) { while(*string) { printChar(*(string++)); } }
2) 通过向 GPIOCR 寄存器(PG)写入引脚 PD7 685)
(第3条) 为向 RCGCUART 寄存器(PG)写入 UART 模块2启用时钟 344)
4) 为向 RCGCGPIO 寄存器(PG)写入 GPIO PortD 启用时钟 340)
(第5条) 通过向 GPIOAFSEL 寄存器(PG)写入数据,允许外围设备控制引脚 PD6和 PD7 671)
(第6条) 通过向 GPIOPCTL 寄存器(PG)写入数据,选择引脚 PD6和 PD7的外围模式 688)
(第7条) 通过向 GPIODEN 寄存器(PG)写入数据,为引脚 PD6和 PD7启用数字输入/输出。 682)
(第8条) 禁用 UART 模块#2,以便我可以通过写入 UARTCTL 寄存器(PG)来设置波特率和串行参数。 (918)
(第9条) 通过写入 UARTIBRD 寄存器(PG)来设置波特率的整数部分。 914)
(第10条) 通过写入 UARFBRD 寄存器(PG。 915)
(第11条) 通过向 UART 寄存器(PG. (916)
UART 模块#2具有9600bps 波特率,8位,无奇偶校验和1个停止位
12) 通过写入 UARTCC 寄存器(PG.939)设置波特时钟源
(第13条) 通过写入 UARTCTL 寄存器(PG。 (918)
(第14条) 通过向 GPIOAMSEL 寄存器(PG.687)写入数据,禁用引脚 PD6和 PD7上的模拟功能
我想包括数据表,但无法上传。 这是标题(TIVA TM4C123GH6PM 微控制器数据表)
谢谢你,
顿纳利米
S.E.
你好,Donnalley,
我们不支持在 E2E 论坛上使用此类直接注册编码。 我建议您使用 TiaWare 来获得一个有效的示例,然后查看用于查看如何配置寄存器的 TiaWare API。
我们的声明关于:直接注册修改可在以下第4页查看: https://e2e.ti.com/support/f/908/695568/faq-faqs-for-tm4c-arm-cortex-m4f-microcontrollers
此致,
拉尔夫·雅各比