I am making the step up from 8 bit to 32 bit and it is hell.
I decided to sit down for an hour or two each day for the rest of the summer and try to learn how to do something different. Today I decided to do a bit of UART. I went through the data sheet steps on how to set up the UART but I am having problems. I am using the TM4C123GXL launch pad with ti's ccs. The problem with my code is It doesn't seem to transmit. It only receives, I know that as the LEDs go off but I am not receiving any characters back I have spent a few hours trying to realize why and I am still clueless. I would be grateful for any help that is offered.
#include <stdio.h>
#include <stdint.h>
#include "inc/tm4c123gh6pm.h"
void printChar(char);
char readChar(void);
int main(void){
//UART 2 = RX PD6 TX PD7
//Run Mode Clock Gating to UART 2
SYSCTL_RCGC1_R |= (1<<2);
//Clock gating to GPIO
SYSCTL_RCGC2_R |= (1<<3);
//Enable and provide clock in run mode to UART module 2
SYSCTL_RCGCUART_R |= (1<<2);
//GPIO Enable clock to Port D
SYSCTL_RCGCGPIO_R |= (1<<3);
//Disable UART2
UART2_CTL_R &= ~(1<<0);
//Set Baud-Rate Divisor
//(Integer Part)
UART2_IBRD_R = 0x8;
//Decimal part
UART2_FBRD_R = 0x2C;
//Set UART 2 parameters
UART2_LCRH_R |= ((1<<6)|(1<<5)|(1<<4)); //Word Length 8 bits 1 stop
//Enable UART2
UART2_CTL_R |= (1<<0)|(1<<8)|(1<<9);
//GPIO Enable Alternate Function (UART)
GPIO_PORTD_AFSEL_R |= (1<<6)|(1<<7);
//GPIO Enable Digital
GPIO_PORTD_DEN_R |= (1<<6)|(1<<7);
//GPIO Port Mux Enable UART2 Peripherial for PD6 PD7
GPIO_PORTD_PCTL_R |= (1<<24)|(1<<28);
//Disable Analog
GPIO_PORTD_AMSEL_R &= ~((1<<6)|(1<<7));
// Configure LED pins
SYSCTL_RCGCGPIO_R |= (1<<5); // enable clock on PortF
GPIO_PORTF_DIR_R = (1<<1)|(1<<2)|(1<<3); // make LED pins (PF1, PF2, and PF3) outputs
GPIO_PORTF_DEN_R = (1<<1)|(1<<2)|(1<<3); // enable digital function on LED pins
GPIO_PORTF_DATA_R = ((1<<1)|(1<<2)|(1<<3));
readChar();
printChar('G');
return 0;
}
char readChar(void)
{
char c;
while((UART2_FR_R & (1<<4)) != 0);
c = UART2_DR_R;
if(c=='A'){
GPIO_PORTF_DATA_R &= ~((1<<1)|(1<<2)|(1<<3));
}
return c;
}
void printChar(char c)
{
while((UART2_FR_R & (1<<5)) != 0);
UART2_DR_R = c;
}