cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L071CB SPI Driver for MX25L8035F

Mahendra
Associate II

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

7 REPLIES 7

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Mahendra
Associate II

Hello clive1,

do you mean this ? or something else ?

0693W000004IlSTQA0.png

TDK
Guru

> 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".

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hello TDK,

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

0693W000004IsgXQAS.png0693W000004Ist7QAC.png

Is this what you mean ? the specifically chip signal timing.

0693W000004JD0tQAG.png0693W000004JD2dQAG.png

Mahendra
Associate II

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