From 04d7919884005ced207e874c6589c189dee8c249 Mon Sep 17 00:00:00 2001 From: Matt Mullins Date: Sat, 22 Dec 2012 23:43:21 -0800 Subject: [PATCH] UART stuff doesn't work for some reason. I think I've done what I need to do, but it doesn't look like the interrupt is firing at all. Plan for tomorrow: merge it with the GPIO and SysTick code from the led_blink, which should let me get status info, since I can't read hardware registers from the debugger. --- isr_table.c | 2 +- main.c | 29 +++++++++++++++++++++++++++++ main.h | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/isr_table.c b/isr_table.c index 2912762..367f480 100644 --- a/isr_table.c +++ b/isr_table.c @@ -25,7 +25,7 @@ void (*reset_vectors[])() = { infinite_loop_isr, infinite_loop_isr, infinite_loop_isr, - infinite_loop_isr, + uart0_isr, infinite_loop_isr, infinite_loop_isr, infinite_loop_isr, diff --git a/main.c b/main.c index c118300..807e879 100644 --- a/main.c +++ b/main.c @@ -34,6 +34,27 @@ void main_isr() { (2 << SYSCTL_RCC2_SYSDIV2_S); SYSCTL_RCC2_R = rcc2; + // Enable UART and GPIO Port A clocks + SYSCTL_RCGCUART_R = 0x1; + SYSCTL_RCGCGPIO_R |= 0x1; + + // Choose UART for PA[1:0], and set PA1 to source current + GPIO_PORTA_AFSEL_R = 0x03; + GPIO_PORTA_DR2R_R = 0x03; + GPIO_PORTA_PCTL_R = 0x11; + + // Set 115200bps + UART0_IBRD_R = 43; + UART0_FBRD_R = 26; + UART0_LCRH_R = UART_LCRH_WLEN_8; + + // Enable interrupts + UART0_IM_R |= UART_IM_RXIM; + NVIC_EN0_R = NVIC_EN0_INT5; + + // Go! + UART0_CTL_R |= UART_CTL_UARTEN; + // infinite loop for (;;) { asm("wfi"); @@ -47,3 +68,11 @@ void spin(int cycles) { asm(""); } } + +__attribute__((isr)) +void uart0_isr() { + // Receive data, increment by 1 and send it back through the UART + int data = UART0_DR_R & 0xFF; + data = (data + 1) & 0xFF; + UART0_DR_R = data; +} diff --git a/main.h b/main.h index 24c4feb..63863fa 100644 --- a/main.h +++ b/main.h @@ -2,5 +2,6 @@ #define __led_blink_H__ extern void main_isr(); +extern void uart0_isr(); #endif -- 2.11.0