Hi!
I have custom board with nRF51822 and I need to communicate with serial flash W25X40 using SPI master example with SoftDevice enabled (S110 is used). I worked with serial flashes before but didn't encountered the problems described below.
During debugging I figured out that after first execution of the spi_master_send_recv function all subsequent transfers use original values of the TX buffer.
Here's example that explains what I mean:
TX and RX buffers are declared as global arrays:
uint8_t tx_data[5] = {0x00, 0x00, 0x00, 0x00, 0x00} // Transmit buffer
uint8_t rx_data[4]; // Receive buffer
Then after standard procedures I initialize SPI interface:
leds_init();
buttons_init();
ble_stack_init();
timers_init();
device_manager_init();
gap_params_init();
advertising_init();
services_init();
sensor_sim_init();
conn_params_init();
// Start execution.
application_timers_start();
advertising_start();
spi_master_init(SPI_MASTER_0, spi_master_event_handler, false);
After that two transfers are being executed in endless loop, the first one reads chip info and the second should read one byte located at address 0x000000:
for (;; )
{
tx_data[0] = 0x9F;
spi_master_send_recv(SPI_MASTER_0, tx_data, 1, rx_data, 4);
tx_data[0] = 0x03;
spi_master_send_recv(SPI_MASTER_0, tx_data, 4, rx_data, 1);
power_manage();
}
The first transfer returns correct values according to the datasheet. The problem I mentioned above is that the second transfer uses value 0x9F rather than 0x03 as if SPI master instance references to the saved copy of original array - this was revealed when I stepped in the function and watched actual TX buffer values.
So far I have two questions:
- How should I modify values of the TX buffer after first using of spi_master_send_recv function?
- Do I use spi_master_send_recv function correctly for reading data from serial flash?
Thanks!