Hello,
I'm currently working with ISP2053 which is the nRF5340-based module.
The system, as the specific GPIO pin detects a low-to-high event, gets data from another device via SPI (ISP becomes a master) and sends the SPI received data via BLE.
But I think the BLE parts malfunction and the data are missed.
When I check the CS pin of the SPI, the SPI transmissions are established for every GPIO event, so the problem may occur after the SPI.
Following is my code for the initiation of GPIOTE, SPIM, and BLE. Please let me know if I used the functions in an inappropriate way or missed setting.
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); if (err_code != NRFX_SUCCESS) { // printk("SPI error: %x\n", err_code); } } void gpiote_init(void) { nrfx_err_t err_code; // GPIOTE init err_code = nrfx_gpiote_init(NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY); 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("GPIOTE 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; // k_sem_give(&ble_buffer_ok); } } void spi_init(void) { // spim_stim init nrfx_spim_config_t spim_stim_config = NRFX_SPIM_DEFAULT_CONFIG(pin_spim_stim_CLK, pin_spim_stim_MOSI, pin_spim_stim_MISO, pin_spim_stim_CS); spim_stim_config.frequency = NRF_SPIM_FREQ_8M; spim_stim_config.mode = NRF_SPIM_MODE_3; // nrfx_spim_init(&spim_stim, &spim_stim_config, spim_stim_event_handler, NULL); if (NRFX_SUCCESS != nrfx_spim_init(&spim_stim, &spim_stim_config, spim_stim_event_handler, NULL)) { printk("SPIM_STIM init error\n"); } IRQ_DIRECT_CONNECT(SPIM1_SPIS1_TWIM1_TWIS1_UARTE1_IRQn, 6, nrfx_spim_1_irq_handler, 0); irq_enable(SPIM1_SPIS1_TWIM1_TWIS1_UARTE1_IRQn); // spim_adc init 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("SPIM_ADC init error\n"); } IRQ_DIRECT_CONNECT(SPIM2_SPIS2_TWIM2_TWIS2_UARTE2_IRQn, 6, nrfx_spim_2_irq_handler, 0); irq_enable(SPIM2_SPIS2_TWIM2_TWIS2_UARTE2_IRQn); }
void ble_send_thread(void) { int ble_err_code = 0; while(1) { if (spim_adc_xfer_done) { if (is_ble_snd) { uint16_t length = spim_adc_m_length; ble_err_code = bt_nus_send(NULL, spim_adc_rx_buf, length); } spim_adc_xfer_done = false; } k_yield(); } } K_THREAD_DEFINE(ble_send_thread_id, 1024, ble_send_thread, NULL, NULL, NULL, 7, 0, 0);