Why am i not able to Configure same UART on two different channels alternatively and communicate?
Hai,
i tried configuring UART1 on PA9 and PB6 designed to communicate with two different devices.I tried transmitting data by configuring each pins individually and disabling (configuring the pin as low) the pins after transmission.My Transmission doesn't seem to work.Please go through my code and share suggestions for the same.
#include "stm32f0xx.h" // Device header
#include "RTE_Components.h" // Component selection
#include "config.h"
#include <stdio.h>
#include <string.h>
#define baudDivisor 0X1388
void UARTinit();
void send_string(char *msg);
void UARTPutChar(char ch);
void enable_PA9();
void enable_PB6();
int main()
{
Start_HSE();
PORTB_CLK_EN;
PORTA_CLK_EN;
UARTinit();
while(1)
{
enable_PA9(); //dissable PB6 and enable PA9
while(!(USART1->ISR & 0x40)); USART1 -> TDR = 'a' ;
enable_PB6(); //dissable PA9 and enable PB6
while(!(USART1->ISR & 0x40)); USART1 -> TDR = 'b' ;
}
}
void UARTinit()
{
RCC->APB2ENR |= (RCC_APB2ENR_USART1EN); // Enable USART1 clock
USART1->CR1 &= ~(BIT(0));
USART1->CR1 = USART_CR1_TE | USART_CR1_RE |USART_CR1_RXNEIE;
USART1->BRR = baudDivisor;
USART1->CR2 = USART_CR2_MSBFIRST;
USART1->CR3 = 0;
USART1->CR1 |= USART_CR1_UE ;
NVIC_EnableIRQ(USART1_IRQn);
}
void enable_PB6()
{
//configuring PA9 as Output low
PORTA_IO = BIT_OUT(9);
PORTA = BIT_CLR(9);
//configuring PB6 as TX pin
GPIOB->AFR[0] = 0x0000;
GPIOB->MODER = BIT(15) | BIT(13);
}
void enable_PA9();
{
//configuring PB6 as Output low
PORTB_IO = BIT_OUT(6);
PORTB |= BIT_CLR(6);
//configuring PA9 as TX pin
GPIOA->MODER |= BIT(21) | BIT(19);
GPIOA->AFR[1] = BIT(8) | BIT(4);
}