cancel
Showing results for 
Search instead for 
Did you mean: 

How to interface STM32L151QD with MX25R6435F external flash memory using SPI?

Rekha.k
Associate II

interface STM32L151QD with MX25R6435F flash memory using SPI. But i found clock frequency of STM = 32MHz maximum and Flash mem frequency = 80MHz . so how to implement SPI interface between these two. Is it possible??? Do we have any example code???

10 REPLIES 10
Andreas Bolsch
Lead II

Maybe read the flash's datasheet? Table 17 AC Characteristics says clearly: fSCLK from DC *UP TO* 33 MHz or DC *UP TO* to 80 Mhz depending on mode and instruction.

Thank you Andreas. I read datasheet. it is clear now. but i am new to SPI implementation. Can you suggest how to start this activity???

S.Ma
Principal

Would be easier to use an STM32 with QSPI support, then using a Discovery where a QSPI flash is present in SW project example, only reuse and tuning existing SW would be needed. QSPI will map the memory withiin the STM32 memory space by HW, allowing XIP (execute in place).

Depends on whether you want to learn or to copy: For the first option you could inspect the diagrams regarding RDID, RDSR, WREN, READ, CE and PP commands in the flash's datasheet carefully. Then implement SPI bitbanging (i. e. by using GPIOs only, without the hardware SPI!) first, in the order above: This way you will realize thoroughly how the SPI communication works. And only afterwards move to the hardware SPI (or as suggested below, QSPI on an F4/F7). Because without a good understanding of the SPI at bit level, it's hard to diagnose problems.

Starting with the RDID command is helpful, as the result is known: 0xC2, 0x28, 0x17. Then with RDSR and WREN check whether you can set the WEL bit successfully. READ, CE, PP can be tested only together, because without a known contents of the flash (distinct from the erased state) it's hard to tell whether the READ works as intended etc.

Thank you Andreas Bolsch your explanation was helpful. i follow your comments : i will go through datasheet and implement SPI using GPIO.

sure i will try to adapt QSPI once after implementing generic SPI using GPIO.

Thank You...

uint8_t spiTxbuf[1], spiRxbuf[1]; 
 
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); //make slave select low
  spiTxbuf[0] = READ_ID_CMD; //0x9F
  HAL_SPI_Transmit(&hspi2, spiTxbuf, 1, 50);
  HAL_SPI_Receive(&hspi2, spiRxbuf, 1, 50);
  //3. Bring slave select high
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
 
   

Hi Andreas,

i am trying to read device ID using above snippet. but i am not getting correct value(0x17) in spiRxbuf [] . is it the correct way to send spi commands to flash memory?

Please suggest

Thanks

The spi master issues the clock signal, but only on transmit. If you want to receive something, must must still send something (dummy bytes). Hence, for the id command, 4 bytes have to be clocked out (command and 3 dummy bytes). Simulaneously 4 bytes are clocked in, on dummy and 3 bytes payload.

Thank you. understood concept and directed me in right direction.