I'm trying to read 8 adc channels using SPI, but then if I dont put some nrf_delay_ms
the MISO
return nothing and the CS
is being driven low by default, high or a period of a bit and low again (I should get the opposite with low state being hold until the end of stansfer)
but then if I add 1ms delay between two successive SPI reads it works fine. the issue is that I should read the 8 channels every 5ms.
how can I perform multiple spi stransfer without a delay between them ?
while (curr_cell < 8) {
nrf_gpio_pin_clear(CELL_SELECT[last_cell]);
nrf_gpio_pin_set(CELL_SELECT[curr_cell]);
if ((curr_cell >= 2) && (change_channel == false)) {
pressure_context.adc_channel++;
change_channel = true;
}
//ADC in single mode
spi_tx_buf[1] = (uint8_t) ((pressure_context.adc_channel & 0x01) << 6);
//Don't care last bits
spi_rx_buf[0] = 0;
spi_rx_buf[1] = 0;
spi_rx_buf[2] = 0;
spi_xfer_done = false;
nrf_drv_spi_transfer(spi, spi_tx_buf, 3, spi_rx_buf, 3);
while (!spi_xfer_done)
{
__WFE();
}
value = (uint16_t)(((spi_rx_buf[1] & 0x000F) << 8) + spi_rx_buf[2]);
pressure_context.pressure_val[curr_cell % 8] = value;
last_cell = curr_cell;
curr_cell++;
nrf_delay_ms(1);
}