cancel
Showing results for 
Search instead for 
Did you mean: 

using stm32f439 spi with serial flash, reading failed

gajji sal
Associate
Posted on March 06, 2017 at 15:31

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 !

#serial-flash #stm32f439 #spi
3 REPLIES 3
S.Ma
Principal
Posted on March 06, 2017 at 17:30

Use an oscilloscope to see what is going on the bus.

Also use different buffer for TX and RX to be sure.

Posted on March 07, 2017 at 14:48

thankyou for the reply. Due to form factor its impossible to access pins directly and use oscilloscope. Is it possible to use uvision's logic analyzer or something similar ?

Posted on March 07, 2017 at 15:31

If you'd like to probe with oscilloscope, the finest wire usually can by scratching the resist

http://sg.element14.com/roadrunner/rrp-a-105/wire-0-15mm-assorted-pk-4/dp/5017233?ost=5017233&selectedCategoryId=&categoryNameResp=All&searchView=table&iscrfnonsku=false

 

On the solder iron put a solder drop on both side of the cut wire

Poke the solder drop with the end of the wire to remove the coating

Solder the wire on PCB or package pin. Then you can probe.

Don't use logic analyser. Oscilloscope is the prime tool to make sure the signals looks good, including the slew rate.

When it works on the scope, then the logic analyser is no longer needed...