Hello, I am trying UART communication using STMF0 familiy and Keil 5. I could send data but can not receive more than 1 byte i response. Here is my code of IRQ handler. Debugger stops only one time to the line where I read data. What is the issue in my code?
uint8_t arrayIndex=0; void USART1_IRQHandler(void) { //Check if tramsmission complete if((USART1->ISR & USART_ISR_TC) == USART_ISR_TC) { switch (commandCount) { case 0: { if(send == size-1) { send=0; commandCount++; USART1->ICR |= USART_ICR_TCCF; } else { /* clear transfer complete flag and fill TDR with a new char */ USART1->TDR = stringtosend[send++]; } break; } } //Read response if((USART1->ISR & USART_ISR_RXNE) == USART_ISR_RXNE) { chartoreceive[arrayIndex++] = (uint8_t)(USART1->RDR); /* Receive data, clear flag */ } }
A normal UART can't receive more than one character (or possibly two) unless you either activate FIFO support or use DMA to automatically clear out received data from the UART.
Make the ISR short and simple - no strange case statements. Look into the use of round-robin buffers for receive and transmit and then quickly exit.
Note that if you do use FIFO for receiving data, then you can continue to pick up incoming characters while the RXNE flag stays set.