I need help with getting the UART message to recieve a commu

I need help with getting the UART message to recieve a communication on my LCD. I have done the UART message transmission test which I pasted below. Port C 11 - UART4 _RX/ is for receiving. Please use STM32F4 discovery. Thanks.

* UART message transmission test
*
* Using UART4 for this exercise:
* Port C10 - UART4_TX/
* Port C11 - UART4_RX/

*/

#include \"stm32f4xx.h\"                  // Device header

char DataString[] = \"I am FUNKY!!\"; // Init string & ptr ; // string must be terminated by \'\\0\'
int i=0;

int main(){

// ENABLE CLocks for PORT C and UART4
   RCC->AHB1ENR |= 0x4;
   RCC->APB1ENR |= 0x80000;



// Set Mode Pins on Port C pins 10 and 11 to Alternate Function
   GPIOC->MODER |= 0xa00000;

  
// Set Alternate Function Register for Port C 10 and 11
// AF8 on AFRH
   GPIOC->AFR[1] |= 0x8800;
   


// UART setup:
// 8 data bits (default), no parity (default), one stop bit (default) & no flow control (default)
   UART4->CR1 &= ~(0x1000);
   UART4->CR2 &= ~(0x3000);  //1 stop bit

// UART Baud Rate = 19.2 Kbps
   UART4->BRR = 0x341;     //from table value in BRR=52.0625

// Enable TRANSMITTER (TE bit)
   UART4->CR1 |= 0x8;

// WE WANT TO TRANSMIT SO ENABLE TRANSMIT INTERRUPT
   UART4->CR1 |= 0x80;


// Enable UART (UE bit in CR1 register)
   UART4->CR1 |= 0x2000;


// NVIC to handle interrupts

__enable_irq();
NVIC_ClearPendingIRQ(UART4_IRQn);
NVIC_SetPriority(UART4_IRQn,0);
NVIC_EnableIRQ(UART4_IRQn);

while(1);

}

// Interrupt reoutine for UART1

void UART4_IRQHandler(void){
// TX IRQ
// If TXE flag in SR is on then
  NVIC_ClearPendingIRQ(UART4_IRQn);
if((UART4->SR & 0x80)!=0){
  if(DataString[i]==\'\\0\'){
   i=0;
  }else{
   UART4->DR = DataString[i];
   i++;
  }
}

}

Solution

You are using a mixture of interrupts and polling to receive characters. You should do one or the other, not both.
You should NEVER have blocking code inside an interrupt service.
Also, you try to clear RCIF inside the interrupt service. You can\'t, it is read only. Simply reading RCREG clears it for you.
Your transmit routine waits for TXIF to be set, and the comment says \"wait until transmit completes \".
That is not true. TXIF is set when TXREG is ready for the next character, but the previous character has only just started sending at this point. You must poll the TRMT bit if you want to wait until all characters have actually been sent.
If you switch devices before TRMT is set, you will truncate the currently sending character.

I need help with getting the UART message to recieve a communication on my LCD. I have done the UART message transmission test which I pasted below. Port C 11 -
I need help with getting the UART message to recieve a communication on my LCD. I have done the UART message transmission test which I pasted below. Port C 11 -

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site