title: Problem with Reading Rx buffer in SPI STM32
body: <p>I have little bit problem when reading Rx Buffer in STM32 SPI. I can watch my signal when transmit or receive in my scope. But I never can get any data in my Rx Buffer. I just use coocox software for this project. </p>
  
  <p>For this project, I use STM32F103 and LoRa module (SX1278). I use Full duplex communication for my SPI Configuration. There is 2 cycle to read register status in my LoRa module. First cycle is to write address and second cycle is for read/write register. My problem is reading register in my LoRa module.</p>
  
  <p>This is my simple code to read register.</p>
  
  <pre><code>  void SPI2_IRQHandler(void)
    {
         RxSPIBuff = &amp;Buffer_Rx[0];
         if (SPI_I2S_GetITStatus(SPI2, SPI_I2S_IT_RXNE) == SET)
         {
            /* Store the I2S2 received data in the relative data table */
            //Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI2);
           //if (SPI_I2S_GetITStatus(SPI2, SPI_I2S_FLAG_RXNE)==SET)
              USART_SendData(USART1, SPI_I2S_ReceiveData(SPI2));
         }
    }
  
   void InitSPI_Lora(void)
   {
  SPI_InitTypeDef SPI_InitStruct;
  GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  
  // RCC Peripheral Configuration
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  
  // GPIO Configuration
  GPIO_InitStructure.GPIO_Pin = MOSI_LoRa | SCLK_LoRa;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(SPI_LoRa, &amp;GPIO_InitStructure);
  
  GPIO_InitStructure.GPIO_Pin = NSS_LoRa;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(PeriphNSS_LoRa, &amp;GPIO_InitStructure);
  
  GPIO_InitStructure.GPIO_Pin = MISO_LoRa;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(SPI_LoRa, &amp;GPIO_InitStructure);
  
  GPIO_InitStructure.GPIO_Pin = Reset_LoRa;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(PeriphRst_LoRa, &amp;GPIO_InitStructure);
  
  GPIO_InitStructure.GPIO_Pin = DIO0_LoRa;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(PeriphDI0_LoRa, &amp;GPIO_InitStructure);
  
  // SPI Configuration
  SPI_InitStruct.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_32; // 7us every 8 bit data
  SPI_InitStruct.SPI_CPHA=SPI_CPHA_1Edge;
  SPI_InitStruct.SPI_CPOL=SPI_CPOL_Low;
  SPI_InitStruct.SPI_DataSize=SPI_DataSize_8b;
  SPI_InitStruct.SPI_Direction=SPI_Direction_2Lines_FullDuplex;
  SPI_InitStruct.SPI_FirstBit=SPI_FirstBit_MSB;
  SPI_InitStruct.SPI_Mode=SPI_Mode_Master;
  SPI_InitStruct.SPI_NSS=SPI_NSS_Soft;
  
  // NVIC Configuration
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
  /* SPI1 IRQ Channel configuration */
  NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&amp;NVIC_InitStructure);
  
  SPI_I2S_DeInit(SPI2);
  
  /* Enable the I2S1 RxNE interrupt */
  SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE);
  
  SPI_Init(SPI2, &amp;SPI_InitStruct);
  SPI_Cmd(SPI2, ENABLE);
   }
  
   void SendSPI_Lora(unsigned short val, unsigned char status)
   {
  SPI_I2S_SendData(SPI2, val);
  while(SPI_I2S_GetITStatus(SPI2, SPI_I2S_FLAG_TXE)==SET);
  SPI_I2S_ClearFlag(SPI2, SPI_I2S_FLAG_TXE);
   }
  
  
   void AccessSPI(unsigned char Cmd, unsigned short *ptrBuff, unsigned char    Operation)
   {
  unsigned short m, temp;
  
  NSS_LO_LoRa;
  SendSPI_Lora(Cmd, kWriteSPI);       // Send Command
  if (Operation==kWriteSPI)
  {
      temp=*ptrBuff;
      SendSPI_Lora(temp, Operation);
  }
  else
  {
      RxIdx=0;
      SendSPI_Lora(0, Operation);
      ptrBuff = RxSPIBuff;
  }
  Delay(2);
  NSS_HI_LoRa;
   }
  
   // Main Sequence
   void test(void)
   {
  unsigned char statusLoRa,buff,irqFlags,newData,newOpMode;
  unsigned char size = 0;
  
  AccessSPI(R_REGISTER|RegVersion, &amp;newOpMode, kReadSPI);
   }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/o3TUd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o3TUd.jpg" alt="enter image description here"></a>
  Pict 1. Write signal in MOSI pin</p>
  
  <p><a href="https://i.stack.imgur.com/F8jAf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F8jAf.jpg" alt="enter image description here"></a>
  Pict 2. Read Signal in MISO pin</p>
  
  <p>I think my problem is about delay to receive data after transmit data with SPI. But i cannot solve this problem because i should transmit data to receive. Is there any solution for this?</p>