title: STM32 Usart receive interrupt works only once
body: <p>I am trying to get my STM32F103 to receive 4 bytes via USART and store them in a value.</p>
  
  <p>So far, if I reset the microcontroller, the first time I send the 4 bytes they're received normally and the microcontroller stores them in USART_RX_BUF, however if I send another 4 bytes, USART_RX_BUF stays unchanged, furthermore, the contents of USART_RX_BUF don't seem to be copied into dato as I'd like</p>
  
  <p>The code for the USART interrupt routine is: </p>
  
  <pre class="lang-c prettyprint-override"><code>void USART1_IRQHandler(void
  {
      u8 Res;
  #if SYSTEM_SUPPORT_OS       
      OSIntEnter();    
  #endif
      if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)  
      {
          Res =USART_ReceiveData(USART1);
  
          if((USART_RX_STA&amp;0x8000)==0)
          {
              if(USART_RX_STA&amp;0x4000)
              {
                  if(Res!=0x0a)USART_RX_STA=0;
                  else{
                      USART_RX_STA|=0x8000;   
                      dato[0]= USART_RX_BUF[0];
                      dato[1]= USART_RX_BUF[1];
                      dato[2]= USART_RX_BUF[2];
                      dato[3]= USART_RX_BUF[3];
                      //USART_RX_STA= 0;
                      //memset(USART_RX_BUF,0,5);
                  } 
  
  
              }
              else //No se recibio 0x0d todavia
              {   
                  if(Res==0x0d)USART_RX_STA|=0x4000;
                  else
                  {
                      USART_RX_BUF[USART_RX_STA&amp;0X3FFF]=Res ;
                      USART_RX_STA++;
                      if(USART_RX_STA&gt;(USART_REC_LEN-1))USART_RX_STA=0;
  
                  }        
              }
          }            
      } 
  </code></pre>
  
  <p>As described, this code receives only 4 bytes and ignores anything I send after those 4 bytes (The received data buffer can't be overwritten) and for the data from the buffer to be written into the array called dato. </p>
  
  <p>Thanks for helping</p>