Hello,
I'm trying to move from nRF5 SDK with nRF52840 to NCS with nRF5340 and experiencing a lot of problems replacing the nrf driver functions with nrfx.
Thanks to the other precedents in the devzone, I implemented all the functions except the SPIM Rx.
The problem is that I see the SPI slave (nRF52840-DK and I checked it works well with another nRF52840-DK) toggles the MISO pin, but the SPI master (nRF5340) cannot read the input.
Following is the code how I configured the SPIM.
nrfx_spim_t spim_adc = NRFX_SPIM_INSTANCE(2);
#define spim_adc_m_length 240
static uint8_t spim_adc_rx_buf[spim_adc_m_length+1];
nrfx_spim_xfer_desc_t spim_adc_desc = NRFX_SPIM_XFER_RX(spim_adc_rx_buf, spim_adc_m_length);
static volatile bool spim_adc_xfer_done;
(...)
void gpiote_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
nrfx_err_t err_code = nrfx_spim_xfer(&spim_adc, &spim_adc_desc, 0);
}
void gpiote_init(void)
{
nrfx_err_t err_code;
err_code = nrfx_gpiote_init(6);
nrfx_gpiote_in_config_t gpiote_cfg = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(false);
err_code = nrfx_gpiote_in_init(pin_spim_fpga_ind, &gpiote_cfg, gpiote_handler);
if (NRFX_SUCCESS != err_code)
{
printk("Init error\n");
}
nrfx_gpiote_in_event_enable(pin_spim_fpga_ind, true);
}
(...)
void spim_adc_event_handler(nrfx_spim_evt_t const *p_event, void *p_context)
{
if (p_event->type == NRFX_SPIM_EVENT_DONE)
{
spim_adc_xfer_done = true;
}
}
void spi_init(void)
{
nrfx_spim_config_t spim_adc_config = NRFX_SPIM_DEFAULT_CONFIG(pin_spim_adc_CLK, pin_spim_adc_MOSI, pin_spim_adc_MISO, pin_spim_adc_CS);
spim_adc_config.frequency = NRF_SPIM_FREQ_8M;
spim_adc_config.mode = NRF_SPIM_MODE_3;
// nrfx_spim_init(&spim_adc, &spim_adc_config, spim_adc_event_handler, NULL);
if (NRFX_SUCCESS != nrfx_spim_init(&spim_adc, &spim_adc_config, spim_adc_event_handler, NULL))
{
printk("Init error\n");
}
IRQ_DIRECT_CONNECT(SPIM2_SPIS2_TWIM2_TWIS2_UARTE2_IRQn, 2, nrfx_spim_2_irq_handler, 0);
irq_enable(SPIM2_SPIS2_TWIM2_TWIS2_UARTE2_IRQn);
}
(...)
void main(void)
{
// Set CPU clock to 64 MHz
HFCLKCTL_R &= ~(0x01);
// Init
ble_init();
nus_init();
gpio_pin_init();
spi_init();
gpiote_init();
// Load configuration
if (IS_ENABLED(CONFIG_SETTINGS)) {
settings_load();
}
// Start BLE advertising
advertising_init();
// Enable cache and hit/miss tracking
while((NVMC_READY_R&0x1) == 0);
NVMC_ICACHECNF_R = 0x101;
// Main loop responses to the BLE RX event after the callback
for(;;)
{
if (spim_adc_xfer_done)
{
uint16_t length = spim_adc_m_length;
bt_nus_send(NULL, spim_adc_rx_buf, length);
spim_adc_xfer_done = false;
}
}
}
As you can see, when the SPI transaction is over, I send the Rx buffer data via Bluetooth. The result is a 240 bytes length array with only zero value.
Please let me know if I missed something required to enable SPI Rx.
P.S. The code crashes when I locate the bt_nus_data_send() in the SPIM handler but there was no problem doing so with ble_nus_data_send(). Is this the problem of priority which was managed by SoftDevice before?



