I've adapted the SPI example to read a value from an Analog Devices ADXL350 accelerometer as follows:
int main(void) { bsp_board_leds_init(); APP_ERROR_CHECK(NRF_LOG_INIT(NULL)); NRF_LOG_DEFAULT_BACKENDS_INIT(); NRF_LOG_INFO("SPI example."); nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG; spi_config.ss_pin = SPI_SS_PIN; spi_config.miso_pin = SPI_MISO_PIN; spi_config.mosi_pin = SPI_MOSI_PIN; spi_config.sck_pin = SPI_SCK_PIN; spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST; spi_config.mode = NRF_DRV_SPI_MODE_0; spi_config.frequency = NRF_DRV_SPI_FREQ_125K; APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL)); while (1) { // Reset rx buffer and transfer done flag memset(m_rx_buf, 0, m_length); spi_xfer_done = false; uint8_t tx = 0x2c | 0x80; uint8_t rx = 0; APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, &tx, 1, &rx, 1)); while (!spi_xfer_done) { __WFE(); } NRF_LOG_INFO("Read %X", rx); NRF_LOG_FLUSH(); bsp_board_led_invert(BSP_BOARD_LED_0); nrf_delay_ms(200); } }
But when connected to the accelerometer this hangs waiting for the transfer to finish. I'm not sure what I'm doing wrong here, do you have any advice?
I'm using nRF52DK and as per the example code, I'm using pins 3,4,28,29 for the SPI connections