AnsweredAssumed Answered

STM32f217IG SPI Master MISO question

Question asked by preston.rob on Jun 7, 2012
Latest reply on Dec 11, 2012 by carter.bob
I have read through many posts about SPI problems and configuration questions.  I feel I have everything configured correctly, however I do not receive any data transferred across the MISO line.  Below shows the configuration code used:
/////////////////////////////////////////////////////////////// Begin Config////////////////////////////////////////////////////////////////////////////////
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
SPI_InitTypeDef  SPI_InitStructure;

  /* Enable the SPI clock */
  SPIx_CLK_INIT(SPIx_CLK, ENABLE);


  /* Enable GPIO clocks */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI | RCC_AHB1Periph_GPIOC  , ENABLE);


  /* Connect SPI pins to AF5 */  
  GPIO_PinAFConfig(GPIOI, GPIO_PinSource1, GPIO_AF_SPI2); // SPI SCLK
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource3, GPIO_AF_SPI2); // MOSI
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource2, GPIO_AF_SPI2); // MISO
  GPIO_PinAFConfig(GPIOI, GPIO_PinSource2, GPIO_AF_SPI2); // CS
  
    /* SPI CS pin configuration */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init (GPIOI, &GPIO_InitStructure);
    
  
   /* SPI SCK pin configuration */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_DOWN;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  GPIO_Init(GPIOI, &GPIO_InitStructure);


  /* SPI  MOSI pin configuration */
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_3;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  
    /* SPI  MISO pin configuration */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_2;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  

/* SPI configuration -------------------------------------------------------*/
  SPI_I2S_DeInit(SPI2);
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_Init(SPI2, &SPI_InitStructure);
  
  /* Configure the Priority Group to 1 bit */                
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  
  /* Configure the SPI interrupt priority */
  NVIC_InitStructure.NVIC_IRQChannel = SPIx_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//////////////////////////////////////////////////////////////////END CONFIG /////////////////////////////////////////////////////////
ok so after this config (assuming its correct) I set the CS pin high and enable spi and interrupts :
GPIO_WriteBit(GPIOI,GPIO_Pin_2, Bit_SET);
SPI_Cmd(SPI2, ENABLE);
SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_TXE, ENABLE);
SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE);


Next I Transmit a 0x9F out to an EEPROM to read the device ID. ( CS is active low and is MSB first)
 GPIO_WriteBit(GPIOI,GPIO_Pin_2, Bit_RESET); // CS LOW
  SPI_I2S_SendData(SPI2, 0x9F);  // Send Data

Every time the TxE is empty it sends out the 9F.  The RXNE does go high and i read the first received 512 bytes in the DR as follows:

  if (SPI_I2S_GetITStatus(SPI2, SPI_I2S_IT_RXNE) == SET)
  {
      if (Rx_Idx < 512)
     {
        RxBuffer[Rx_Idx++] = SPI_I2S_ReceiveData(SPI2);
     }
    else
    {
               SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, DISABLE);


      GPIO_WriteBit(GPIOI,GPIO_Pin_2, Bit_SET);// CS HIGH
      int x = 0; 
    }
}

On the oscilloscope I do see data across the MISO line ( Device ID ) but I do not receive it in the micro rx buffer.

Any suggestions would be of great help; Maybe I overlooked something. 

Thanks in advanced for your help

Outcomes