0

As i was beginning with SPI FLASH from winbond W25Q32FV with STM32F103RCT6 CORTEX M3. I am facing a real issue of understanding how things should work.

I am using CUBEMX. First i have selected RCC as crystal/ceramic resonator and configured my clock to 72MHz. Then i configured SPI1 as FULL DUPLEX MASTER. There i got only 3 Pin (PA5 - SCK, PA6- MISO, PA7 - MOSI) so i configured CS pin as GPIO OUTPUT on PA2.

Now to write to flash? What is the first thing I need to do? What are the steps i need to follow?

As long as i refereed to the datasheet first i need to Enable Write(0x06). Then i need to send Page Program(0x02) and then i need to send 24 bit address. Then i need to send at least 1 byte of data. All these procedure will happen when CS is low and then after sending all this CS will be high.

Then i am disabling Write enable, i.e write Disable(0x04).

After then i am trying to read data from that address, So, I send Read Data(0x03) and 24bit address. Then Recieve data in buffer.

Here is the sample code:

    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,GPIO_PIN_RESET);
    HAL_Delay(10);
    SPI_TX_BUFF[0] = 0x06;
    SPI_TX_BUFF[1] = 0x02;
    SPI_TX_BUFF[2] = 0x00;
    SPI_TX_BUFF[3] = 0x00;
    SPI_TX_BUFF[4] = 0x01;
    SPI_TX_BUFF[5] = 0x11;
    HAL_SPI_Transmit(&hspi1, SPI_TX_BUFF, 6, 50);
    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,GPIO_PIN_RESET);
    HAL_Delay(100);

    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,GPIO_PIN_RESET);
    HAL_Delay(10);
    SPI_TX_BUFF[0] = 0x04;
    HAL_SPI_Transmit(&hspi1, SPI_TX_BUFF, 1, 50);
    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,GPIO_PIN_RESET);
    HAL_Delay(100);

    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,GPIO_PIN_RESET);
    HAL_Delay(10);
    SPI_TX_BUFF[0] = 0x03;
    SPI_TX_BUFF[1] = 0x00;
    SPI_TX_BUFF[2] = 0x00;
    SPI_TX_BUFF[3] = 0x01;
    HAL_SPI_Transmit(&hspi1, SPI_TX_BUFF, 4, 50);
    HAL_SPI_Receive(&hspi1, SPI_RX_BUFF, 1, 50);
    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,GPIO_PIN_RESET);
    HAL_Delay(100);

This code is not working. More over after flashing the code i can't even enter the debug mode. It says NO TARGET CONNECTED. I know i am doing something massively wrong and need a little guidance. I just need to know what are the steps involved to successfully initiate, write and read from spi flash.

Like I am confused with few stuffs

  1. Here i am directly sending the Write enable as my first command. Here should i need to send the id first? I mean how to initiate and let know the MCU that he is having a flash connected to the spi pins.

2.How to send 24 bit address? What is the starting address i begin with to write data in flash?

3.When is flash a simple blinky. The MCU works fine but when i flash this code why the alert NO TARGET CONNECTED. Then i have to press reset and erase everything.

Any help will be appreciated.

Thank you in advance.

Devjeet Mandal
  • 345
  • 1
  • 4
  • 23
  • This question would probably get a better response on the _[electronics stack overflow site](https://electronics.stackexchange.com/)_. In fact, _[here is a discussion relating to the same hardware you reference in your question](https://electronics.stackexchange.com/questions/51229/how-do-i-write-to-spi-flash-memory)_. – ryyker May 29 '18 at 12:45
  • Indeed. This question can be copy/pasted as-in to the EE site where it is perfectly on-topic (delete it here afterwards). Questions regarding things like SPI drivers and flash will get much better answers at EE. – Lundin May 29 '18 at 12:52
  • @ryyker Thanks for your response. I have read the post and found few interesting things. Let me try those first and iff the code doesn't run i will post it in electronics stack overflow site. – Devjeet Mandal May 29 '18 at 13:01
  • @Lundin Thanks for your response – Devjeet Mandal May 29 '18 at 13:01
  • The issue with debugging is something MCU/IDE related, make sure you're using the correct pins with the SPI part. Secondly, check your code against example code, for example, are you following the same sequence of writes as seen here: https://github.com/mhollands/Winbond-W25Q32JV/blob/master/main.cpp ... you can use example code as a baseline. Other than that, just follow the spec and you should be fine. – Kcvin May 29 '18 at 13:39

0 Answers0