2020-10-06 12:26 AM
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
2020-10-06 12:53 AM
Might want to dwell after setting CS high, check min time in datasheet.
2020-10-06 01:33 AM
Hello clive1,
do you mean this ? or something else ?
2020-10-06 02:39 AM
> 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?
2020-10-06 04:55 AM
Something else, something specifically related to the chip select signal timing.
2020-10-06 08:25 PM
Hello TDK,
please see this image. Do I need to attach a photo of the wiring?
2020-10-06 08:41 PM
Is this what you mean ? the specifically chip signal timing.
2020-10-29 06:14 AM
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