Question
STM32 UART Interrupt between 2 STM32F103C8 boards.
Hello guys good day. I would like to ask for your suggestions regarding the UART interrupt between 2 STM32F103C8 MCUs. I can transmit and receive between 2 MCUs using a single input and output with the use of the IRQHandler. However when I wanted to use the 2nd pin and output I could not transmit and receive anymore. So basically the interrupt is only working for a single inputt/output but for multiple input/output it does not work anymore. I have the codes below:
// I defined this function before the main
void UARTTX(uint8_t data)
{
while(!(USART2 -> SR & USART_SR_TXE));
USART2 -> DR = data;
}
// I defined this function before the main
char UARTRX()
{
while(!(USART2 -> SR & USART_SR_RXNE));
return USART2 -> DR;
}
.
.
.
// I enabled these registers before the while loop
USART2 -> CR1 |= USART_CR1_UE;
USART2 -> CR1 |= USART_CR1_TE;
USART2 -> CR1 |= USART_CR1_RE;
USART2 -> CR1 |= USART_CR1_RXNEIE;
USART2 -> CR1 |= USART_CR1_TXEIE;
.
.
.
//main code is in the IRQHandler
void USART2_IRQHandler(void)
{
HAL_UART_IRQHandler(&huart2);
{
//this is first tx output. This code is working only if the second tx output below is not enabled
if(!HAL_GPIO_ReadPin(BUTTON1_GPIO_Port, BUTTON1_Pin))
{
USART2 -> DR = 0xFF;
}
else
{
USART2 -> DR = 0x00;
}
}
//this is 2nd tx input and not working
// {
// if(HAL_GPIO_ReadPin(BUTTON2_GPIO_Port, BUTTON2_Pin))
// {
// USART2 -> DR = 0xF0;
// }
// else
// {
// USART2 -> DR = 0x0F;
// }
// }
// this is first rx input and only working if 2nd rx input below is disabled
{
if(USART2 -> DR == 0xFF)
{
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);
}
else if(USART2 -> DR == 0x00)
{
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
}
}
//this is 2nd rx input and is not working
// {
// if(USART2 -> DR == 0xF0)
// {
// HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
// }
// else if(USART2 -> DR == 0x0F)
// {
// HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET);
// }
// }
}
