Hello, so basically I was using UART0 on pins A0,A1 for monitoring my data with serial monitor, and I then initialized UART1 on pins PC4, PC5 to send data to A6 module and it worked fine.
for some reasons I need another UART so I initialized UART2 on pins PD6, PD7. The thing is my uC seems receiving information but not sending so I unlocked the port, it started sending data but it takes really long time like 2 mins to send the data, I don't understand the reason behind this.
These are the important chunks of my code
int main(void){
int i,j;unsigned char b,N; char character; char end_c[2]={0x1a,'\0'};
unsigned char AT_response[100]; unsigned char test[5]="hello";
UART_Init(); // initialize UART
UART_Init1(); // initialize UART1
UART_Init2(); // initialize UART2
while(1)
{
here is my code
}
and the init functions are the following :
void UART_Init(void){
// as part of Lab 11, modify this program to use UART0 instead of UART1
// switching from PC5,PC4 to PA1,PA0
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 = 43; // IBRD = int(80,000,000 / (16 * 115200)) = int(43.402778)
UART0_FBRD_R = 26; // FBRD = round(0.402778 * 64) = 26
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,PA0
GPIO_PORTA_DEN_R |= 0x03; // enable digital I/O on PA1,PA0
// configure PA1,PA0 as UART0
GPIO_PORTA_PCTL_R = (GPIO_PORTA_PCTL_R&0xFFFFFF00)+0x00000011;
GPIO_PORTA_AMSEL_R &= ~0x03; // disable analog functionality on PA1,PA0
}
void UART_Init1(void){
SYSCTL_RCGC1_R |= SYSCTL_RCGC1_UART1; // activate UART1
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOC; // activate port C
UART1_CTL_R &= ~UART_CTL_UARTEN; // disable UART
UART1_IBRD_R = 520; // 80,000,000/(16*115,200)) = 43.40278
UART1_FBRD_R = 53; //6-bbit fraction, round(0.40278 * 64) = 26
UART1_LCRH_R = (UART_LCRH_WLEN_8|UART_LCRH_FEN);
UART1_CTL_R |= UART_CTL_UARTEN; // enable UART
GPIO_PORTC_AFSEL_R |= 0x30; // enable alt funct on PC5-4
GPIO_PORTC_DEN_R |= 0x30; // enable digital I/O on PC5-4
// configure PC5-4 as UART1
GPIO_PORTC_PCTL_R = (GPIO_PORTC_PCTL_R&0xFF00FFFF)+0x00220000;
GPIO_PORTC_AMSEL_R &= ~0x30; // disable analog functionality on PC5-4
}
void UART_Init2(void){
volatile unsigned long delay;
// as part of Lab 11, modify this program to use UART0 instead of UART1
// switching from PC5,PC4 to PA1,PA0
SYSCTL_RCGC1_R |= SYSCTL_RCGC1_UART2; // activate UART2
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD; // activate port D
delay = SYSCTL_RCGC2_R; // allow time for clock to start
GPIO_PORTD_LOCK_R = 0x4C4F434B; // 2) unlock GPIO Port D
GPIO_PORTD_CR_R = 0x80; // allow changes to PD7
UART2_CTL_R &= ~UART_CTL_UARTEN; // disable UART
UART2_IBRD_R = 520; // IBRD = int(80,000,000 / (16 * 115200)) = int(43.402778)
UART2_FBRD_R = 53; // 8 bit word length (no parity bits, one stop bit, FIFOs)
UART2_LCRH_R = (UART_LCRH_WLEN_8|UART_LCRH_FEN);
UART2_CTL_R |= UART_CTL_UARTEN; // enable UART
GPIO_PORTD_AFSEL_R |= 0xC0; // enable alt funct on PD6,PD7
GPIO_PORTD_DEN_R |= 0xC0; // enable digital I/O on PD6,PD7
// configure PD7,PD6 as UART2
GPIO_PORTD_PCTL_R = (GPIO_PORTD_PCTL_R&0x00FFFFFF)+0x11000000;
GPIO_PORTD_AMSEL_R &= ~0xC0; // disable analog functionality on PA1,PA0
}