TM4C is connected to my PC via USB. My aim is to light the leds of PF3-0, by pressing some keys on the keyboard such as x,y (using interrupts). I'm using the TexaSDisplay for serial communication. The code is below, and it is not working correctly. UART0 interrupts are not created.
I wasn't able find much info about, how to arm and clear the UART0 interrupt (all i can find is periodic and edge interrupt tutorials). I guess this is the root of the problem. Ofcourse I may have done other mistakes.Could you please help me? Thank you.
#include <tm4c123gh6pm.h> void EnableInterrupts(void); // Enable interrupts void WaitForInterrupt(void); // low power mode //------------UART_Init------------ // Initialize the UART for 115,200 baud rate (assuming 50 MHz UART clock), // 8 bit word length, no parity bits, one stop bit, FIFOs enabled // Input: none // Output: none void UART_Init(void){ SYSCTL_RCGC1_R |= SYSCTL_RCGC1_UART0; // activate UART0 SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOA; // activate port A UART0_CTL_R &= ~UART_CTL_UARTEN; // disable UART UART0_IBRD_R = 27; // IBRD = int(50,000,000 / (16 * 115,200)) = int(27.1267) UART0_FBRD_R = 8; // FBRD = int(0.1267 * 64 + 0.5) = 8 // 8 bit word length (no parity bits, one stop bit, FIFOs) UART0_LCRH_R = (UART_LCRH_WLEN_8|UART_LCRH_FEN); UART0_CTL_R |= UART_CTL_UARTEN; // enable UART GPIO_PORTA_AFSEL_R |= 0x03; // enable alt funct on PA1-0 GPIO_PORTA_DEN_R |= 0x03; // enable digital I/O on PA1-0 // configure PA1-0 as UART GPIO_PORTA_PCTL_R = (GPIO_PORTA_PCTL_R&0xFFFFFF00)+0x00000011; GPIO_PORTA_AMSEL_R &= ~0x03; // disable analog functionality on PA //setting up UART0 for interrupt NVIC_PRI1_R = 0x00004000; //set UART interrupt priority to 2 (set bits are between 13-15) NVIC_EN0_R = 0x00000020; //set bit 5 EnableInterrupts(); //global enable }
//enable the PF3-1 leds void PortF_Init(void) { volatile unsigned long delay; SYSCTL_RCGC2_R |= 0x00000020; // 1) F clock delay = SYSCTL_RCGC2_R; // delay GPIO_PORTF_CR_R |= 0x0E; // allow changes to PF3-1 GPIO_PORTF_AMSEL_R &= 0x00; // 3) disable analog function GPIO_PORTF_PCTL_R &= 0x00000000; // 4) GPIO clear bit PCTL GPIO_PORTF_DIR_R |= 0x0E; // 5.2) PF3-1 output GPIO_PORTF_AFSEL_R &= 0x00; // 6) no alternate function GPIO_PORTF_DEN_R |= 0x0E; // 7) enable digital pins PF3-PF1 } //------------UART_InChar------------ // Wait for new serial port input // Input: none // Output: ASCII code for key typed unsigned char UART_InChar(void){ while((UART0_FR_R&UART_FR_RXFE) != 0); return((unsigned char)(UART0_DR_R&0xFF)); } //------------UART_OutChar------------ // Output 8-bit to serial port // Input: letter is an 8-bit ASCII character to be transferred // Output: none void UART_OutChar(unsigned char data) { while((UART0_FR_R&UART_FR_TXFF) != 0); UART0_DR_R = data; } //UART interrupt handler, probably clear flag is missing void UART0_Handler(void) { unsigned char input=UART_InChar(); if(input=='x') { GPIO_PORTF_DATA_R |= 0x02; }else if(input=='y') { GPIO_PORTF_DATA_R |= 0x04; } }
//the main program int main(void) { UART_Init(); PortF_Init(); while(1) { WaitForInterrupt(); } }