AnsweredAssumed Answered

using stm32f439 spi with serial flash, reading failed

Question asked by sal.gajji on Mar 6, 2017
Latest reply on Mar 7, 2017 by KIC8462852 EPIC204278916

Hi,
I have a macronix serial flash(MX66L1G45G) interfaced to my stm32f436 via spi4. hardware connections are correct.

 

Initialization functions are as follows.

 

int DRV_SPI_Init(void)
{    
    hspi.Instance = SPI4;
    hspi.Init.Mode = SPI_MODE_MASTER;
    hspi.Init.Direction = SPI_DIRECTION_2LINES;
    hspi.Init.DataSize = SPI_DATASIZE_8BIT;
    hspi.Init.CLKPolarity = SPI_POLARITY_HIGH;
    hspi.Init.CLKPhase = SPI_PHASE_2EDGE;
    hspi.Init.NSS = SPI_NSS_SOFT;
    //hspi.Init.NSS = SPI_NSS_HARD_OUTPUT ;
    hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
    hspi.Init.FirstBit = SPI_FIRSTBIT_MSB;
    hspi.Init.TIMode = SPI_TIMODE_DISABLED;
    hspi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;

 

    if(HAL_SPI_Init(&hspi) != HAL_OK)
    {
        retVal = -1;
    }

    return 0;
}

 

 

void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
{
    /* Variable declaration */
  GPIO_InitTypeDef GPIO_InitStruct;

  if(hspi->Instance==SPI4)
  {
    /* Peripheral clock enable */
    __SPI4_CLK_ENABLE();
    __GPIOE_CLK_ENABLE();

 

    /**SPI4 GPIO Configuration    
    PE11     ------> SPI4_NSS
    PE12     ------> SPI4_SCK
    PE13     ------> SPI4_MISO
    PE14     ------> SPI4_MOSI
    */
    GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; //?
    GPIO_InitStruct.Pull = GPIO_NOPULL;    //?
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; //?        
    GPIO_InitStruct.Alternate = GPIO_AF5_SPI4;  
    HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

 

    GPIO_InitStruct.Pin = GPIO_PIN_11;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

 

    /* Peripheral interrupt init*/
    HAL_NVIC_SetPriority(SPI4_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(SPI4_IRQn);
  }
}


When I write some thing i always get HAL_OK in return and when I try to read to confirm I always get 0 back in the
reciving buffer with HAL_OK.

 

For example i am trying to read EAR register

//put nss low
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_11, GPIO_PIN_RESET);

 

//read
hStatus = HAL_SPI_TransmitReceive(&(hspi), txData, txData, 3, 4); //static uint8_t txData[3] = {0xC8, 0xFF, 0xFF}; cmd followed by two dummy bytes

 

//wait xmission complete
while( hspi.State == HAL_SPI_STATE_BUSY );

 

//put nss high
HAL_GPIO_WritePin( GPIOE , GPIO_PIN_11 , GPIO_PIN_SET );

Can anybody point out any reason of not working, or any recommendation.

Thankyou !

Outcomes