I'm using nRF52 + SDK11.0.0 + s132. I have an SPI slave configured. I have 40B data being read by a master every 12ms at 1MHz SPI clock. The master is trigger to do the read via a GPIO pin going LO and then HI after CSB is de-asserted. Every once in a while, the first byte transferred is a 0 where it should always be a 3 but the remaining bytes seem okay (they are not shifted; just the 3 was replaced by 0). This could happen in a matter of once every few minutes. I tried swapping the order of nrf_drv_spis_buffers_set() and the actual setting of the tx_buffer, but it doesn't help. Relevant code is below. Please advise.
uint8_t flashlog_data_save(uint8_t len, uint8_t *buf)
{
//flashlog_initBufs();
memset(gSPIStxBuf, 0, sizeof(gSPIStxBuf));
gSPIStxBuf[0] = FLASH_DATA;
gSPIStxBuf[1] = len;
memcpy(gSPIStxBuf+2, buf, len);
flashlog_initBufs();
nrf_drv_gpiote_out_clear(NRF_IRQ_PIN);
return FLASH_NO_ERROR;
}
static void flashlog_initBufs(void)
{
uint32_t err_code;
err_code = nrf_drv_spis_buffers_set(&m_spi_slave_2, gSPIStxBuf, sizeof(gSPIStxBuf), gSPISrxBuf, sizeof(gSPISrxBuf));
APP_ERROR_CHECK(err_code);
}
static void spi_slave_handler(nrf_drv_spis_event_t event)
{
if (event.evt_type == NRF_DRV_SPIS_XFER_DONE)
{
nrf_drv_gpiote_out_set(NRF_IRQ_PIN);
}
}
static void spi_slave_init(void)
{
uint32_t err_code = NRF_SUCCESS;
nrf_drv_spis_config_t config =
{
.sck_pin = SPI2_SCK,
.mosi_pin = SPI2_MOSI,
.miso_pin = SPI2_MISO,
.csn_pin = SPI2_CSBLE_N,
.miso_drive = NRF_DRV_SPIS_DEFAULT_MISO_DRIVE,
.csn_pullup = NRF_DRV_SPIS_DEFAULT_CSN_PULLUP,
.orc = NRF_DRV_SPIS_DEFAULT_ORC,
.def = NRF_DRV_SPIS_DEFAULT_DEF,
.mode = NRF_DRV_SPIS_MODE_0,
.bit_order = NRF_DRV_SPIS_BIT_ORDER_MSB_FIRST,
.irq_priority = APP_IRQ_PRIORITY_LOW
};
err_code = nrf_drv_spis_init(&m_spi_slave_2, &config, spi_slave_handler);
APP_ERROR_CHECK(err_code);
}
Screen shot of MISO all 0s on the first (and only byte, since 0 signifies the master to stop reading). I confirmed that the remaining bytes by modifying the opcodes and not having 0 as the first byte stop the transfer in another test.