From e52ff2bad3e022055598cca755ff467b1c6fcb5d Mon Sep 17 00:00:00 2001 From: Sanyog Date: Thu, 7 Nov 2024 13:17:34 +0530 Subject: [PATCH] Initialize PORTB for UART1 with 9600 baud rate --- main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/main.c b/main.c index d964b87..6259aae 100644 --- a/main.c +++ b/main.c @@ -19,4 +19,23 @@ void GPIO_PORT_F_init(void) } +void GPIO_PORT_B_init(void) +{ + SYSCTL_RCGCGPIO_R |= 0x02; // ENABLE CLOCK FOR GPIOB + SYSCTL_RCGCUART_R |= 0x02; // ENABLE CLOCK FOR UART1 + + GPIO_PORTB_DEN_R |= 0x03; // DIGITAL ENABLE FOR PB0 AND PB1 + GPIO_PORTB_AFSEL_R |= 0x03; // ENABLE ALTERNATE FUNCTION ON PB0,PB1 + + GPIO_PORTB_PCTL_R = (GPIO_PORTB_PCTL_R & 0xFFFFFF00) | 0x00000011; // Set PB0, PB1 for UART + + UART1_CTL_R &= ~0x01; // DISABLE UART1 DURING SETUP + UART1_IBRD_R = 104; // Set integer part of baud rate (for 9600 baud at 16 MHz clock) + UART1_FBRD_R = 11; // Set fractional part of baud rate + UART1_LCRH_R = 0x62; // 8-bit, odd parity, 1 stop bit + UART1_CC_R = 0x00; // Use system clock + + UART1_CTL_R |= 0x301; // Enable UART1, RX, and TX + +}