- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm using 4100S MAX PRONEER KIT. I am facing a problem related to access external SPI Flash memory by using HAL API. I've attached my main.c as well.
1. When read the flash's ID,
----
uint8_t receive_data[10];
"cyhal_spi_transfer(&mSPI, transmit_read_id, 1u, receive_data, 4u, 0xFF)"
----
Sending the read id command (0x9F), I got the correct return value, 0xc2, 0x20, 0x16 as below waveform.
But when I print receive_data array, I noticed that the return value 0xc2, 0x20, 0x16 were in array of receive_data[1][2][3], why the value 0xc2, 0x20, 0x16 NOT in the receive_data[0][1][2]?
Any help will be much appreciated. Thanks a lot in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It appears that the issue is related to the size parameter passed to the cyhal_spi_transfer
function. In your code, you are passing 4u
as the size parameter, which means that the function is expecting to receive 4 bytes of data. However, in your SPI flash, the read id command returns only 3 bytes of data.
As a result, the first byte of the received data (0xc2) is being stored in receive_data[1]
, the second byte (0x20) is stored in receive_data[2]
, and the third byte (0x16) is stored in receive_data[3]
. The receive_data[0]
element remains uninitialized.
To fix this issue, you should pass 3u
as the size parameter to cyhal_spi_transfer
, instead of 4u
. This will ensure that the function only expects to receive 3 bytes of data, and the received data will be stored in receive_data[0]
, receive_data[1]
, and receive_data[2]
.
I hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Giraffe1492,
Thanks for your reply.
I pass 3u as the size parameter to cyhal_spi_transfer, instead of 4u.
But the result is
receive_data[0] = 0,
receive_data[1] = c2,
receive_data[2] = 20
So It doesn't seem to be fix the problem.
Any help will be much appreciated. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @HuEd_3452391 ,
Apologies for the delay.
When the read id command 0x9F is sent by the Master, the SPI RX buffer receives some data against this command sent. This gets stored in receive_data[0]. Then in order to receive three more data bytes from the slave, SPI writes three dummy bytes( 0xFF i.e Write fill) for which the RX buffer receives the Flash ID which is stored in receive_data[1], receive_data[2] and receive_data[3].
Thanks and regards,
Sidramesh