Skip to main content
Mahendra
Associate III
October 6, 2020
Question

STM32L071CB SPI Driver for MX25L8035F

  • October 6, 2020
  • 7 replies
  • 1252 views

Dear experts,

I bought a MX25V8035F chip. I try to build my own SPI driver to communicate with this chip. I use STM32L071cb, STM32CubeIDE, and HAL Libraries right now. But, the STM32L071cb always receives a random number. for example, I try to read the status register of MX25V8035F by sending 0x05 hex from the mcu. the output may be 0x00, 0x03, or 0xFF. 

could you help me to find the problem ? Thank you guys.

Mahendra

------

the code

// STM32L071cb
 
#define RDSR 0x05
#define SPI1_CS_Pin GPIO_PIN_4
#define SPI1_CS_GPIO_Port GPIOA
 
uint8_t receive[8];
uint8_t command = RDSR;
 
// CS# goes low
HAL_GPIO_WritePin ( SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_RESET ); 
 
// sending RDSR instruction code
HAL_SPI_Transmit ( &hspi1, (uint8_t *)&command, 1, 100 );
 
// Status Register data out on SO
HAL_SPI_Receive ( &hspi1, (uint8_t *)receive, 1, 100 );
 
// CS# goes high
HAL_GPIO_WritePin ( SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_SET );
 
// print the received bytes
USART_PutString ( &huart2, "0x%02X\r\n", receive[0] );
 
// reset the buffer
memset(receive, 0, sizeof(receive));

the output

0693W000004IkgKQAS.png

This topic has been closed for replies.

7 replies

Tesla DeLorean
Guru
October 6, 2020

Might want to dwell after setting CS high, check min time in datasheet.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Mahendra
MahendraAuthor
Associate III
October 6, 2020

Hello clive1,

do you mean this ? or something else ?

0693W000004IlSTQA0.png

Tesla DeLorean
Guru
October 6, 2020

Something else, something specifically related to the chip select signal timing.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
TDK
October 6, 2020

> But, the STM32L071cb always receives a random number.

In your screenshot, the received number is not random but always 0x03, which seems like a valid response. When do you see the other responses?

"If you feel a post has answered your question, please click ""Accept as Solution""."
Mahendra
MahendraAuthor
Associate III
October 7, 2020

Hello TDK,

please see this image. Do I need to attach a photo of the wiring?

0693W000004IsgXQAS.png0693W000004Ist7QAC.png

Mahendra
MahendraAuthor
Associate III
October 29, 2020

Hi clive and TDK,

Thanks for helping me to find the problem. I think the poor wire cables or the chip is already broken. Im using rainbow jumper cables.

The SPI Driver can be found here.

Thanks,

Mahendra