Hi All,
I've run into a weird issue where my SPIM rx buffer remains empty (it's not even filled with garbage - just empty). Am I operating the SPI drivers properly? My process is shown below:
When a command comes in over Bluetooth, I have a "master devkit" initiate a SPI transaction with a "slave devkit". The following function occurs in my main loop (so the CPU starts this ... for now).
static void process_commands()
{
if (strcmp(token,"read") == 0) {
NRF_LOG_INFO("read reg cmd recieved");
token = strtok(NULL, delimiter);
NRF_LOG_INFO("read token: %s", token);
addr = (uint8_t) atoi(token);
NRF_LOG_INFO("read addr: %d", addr);
spi_tx_buf[0] = addr;
spi_tx_buf[1] = 0;
spi_tx_buf[63] = 0;
spi_tx_buf[64] = 0;
spi_cmd_flag = SPI_READ_REG; //spi_cmd_flag = read
// NRF_LOG_HEXDUMP_DEBUG(spi_tx_buf, spi_length);
NRF_LOG_INFO("cmd: %d - %d ... %d - %d",spi_tx_buf[0], spi_tx_buf[1], spi_tx_buf[63], spi_tx_buf[64]);
// shoot off SPI_TRX
if (spi_xfer_done == true)
{
NRF_LOG_INFO("SENDING SPI CMD...");
spi_xfer_done = false;
nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(spi_tx_buf, spi_length, spi_rx_buf, spi_length);
APP_ERROR_CHECK(nrfx_spim_xfer(&spi, &xfer_desc, 0));
}
}
...
...
}
Then I have my spi event handler take whatever was in the rx buffer and send it back to my 'base station' over bluetooth:
void spim_event_handler(nrfx_spim_evt_t const * p_event,
void * p_context)
{
spi_xfer_done = true;
NRF_LOG_INFO("SPI TRX COMPLETE");
if (spi_cmd_flag == SPI_READ_REG) {
NRF_LOG_INFO("READ REG CCOMPLETE");
spi_cmd_flag = 0;
while(ble_nus_data_send(&m_nus, spi_rx_buf, &spi_length, m_conn_handle) != NRF_SUCCESS);
}
...
...
}Unfortunately, when I run this nothing is transmitted over bluetooth... If I try a hexdump it shows nothing (and in fact it crashes the devkit too...). I do not have access to a logic analyzer just yet but I'm looking at getting one to confirm that data is indeed being sent over the MISO. I can confirm that data is being shifted into my "slave" device (LEDs are changing when they're supposed to indicate valid SPI shift ins). Am I handling the SPIM TRX properly though? As in am I setting up the nrfx_spim_xfer object properly?
Thank you for all your help! I'm really stuck!
Ryan
