UART stuff doesn't work for some reason.
authorMatt Mullins <mmullins@mmlx.us>
Sun, 23 Dec 2012 07:43:21 +0000 (23:43 -0800)
committerMatt Mullins <mmullins@mmlx.us>
Sun, 23 Dec 2012 18:17:32 +0000 (10:17 -0800)
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
main.c
main.h

index 2912762..367f480 100644 (file)
@@ -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 (file)
--- 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 (file)
--- a/main.h
+++ b/main.h
@@ -2,5 +2,6 @@
 #define __led_blink_H__
 
 extern void main_isr();
+extern void uart0_isr();
 
 #endif