SAADC with 2.6.1

Hi, I having a hard time with SAADC using v2.6.1 and a custom board.  I have built the samples and gotten hem to work on the dev kit.  I am trying to apply that to the custom board with no luck.

Description of my board: I have 4 saadc channels that get varied values based on variable resistors. I define them in the code like this:

static const nrfx_saadc_channel_t m_multiple_channels[] =
{
    NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN0, 0),
    NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN1, 1),
    NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN4, 2),
    NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN5, 3)
};

I setup the saadc code in main like this:

status = nrfx_saadc_init(NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY);
 
#if defined(__ZEPHYR__)
  IRQ_DIRECT_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_SAADC), IRQ_PRIO_LOWEST, nrfx_saadc_irq_handler, 0);
#endif
  status = nrfx_saadc_channels_config(m_multiple_channels,NRFX_SAADC_CHANNEL_COUNT);
  NRFX_ASSERT(status == NRFX_SUCCESS);
    
  
  channels_mask = nrfx_saadc_channels_configured_get();
  LOG_DBG("Channel Mask: %d",channels_mask);
  nrfx_saadc_adv_config_t adv_config = NRFX_SAADC_DEFAULT_ADV_CONFIG;
  adv_config.internal_timer_cc = INTERNAL_TIMER_CC;
  adv_config.start_on_end = true;

  status = nrfx_saadc_advanced_mode_set(channels_mask, SAADC_RESOLUTION, &adv_config, saadc_handler);
  m_saadc_done = true;

  status = nrfx_saadc_buffer_set(m_samples_buffer, NRFX_SAADC_CHANNEL_COUNT);
  NRFX_ASSERT(status == NRFX_SUCCESS);
  status = nrfx_saadc_offset_calibrate(saadc_handler);
  
  //for now loop continusously
 while(1)
  {
    k_sleep(K_MSEC(500));
    nrfx_saadc_mode_trigger();
  }

The saadc_handler:

static void saadc_handler(nrfx_saadc_evt_t const *p_event)
{
  uint16_t samples_number = 0;
  nrfx_err_t err;
  (void)err;

  switch (p_event->type)
  {
    case NRFX_SAADC_EVT_DONE:    
      LOG_DBG("SAADC event: DONE");

      samples_number = p_event->data.done.size;
      for (uint16_t i = 0; i < samples_number; i++)
      {
        LOG_DBG("[Sample %d] value == %d", i, NRFX_SAADC_SAMPLE_GET(RESOLUTION, p_event->data.done.p_buffer, i));
      }

      m_saadc_ready = true;
      break;

    case NRFX_SAADC_EVT_CALIBRATEDONE:
      LOG_DBG("SAADC event: CALIBRATEDONE");
      err = nrfx_saadc_mode_trigger();
      NRFX_ASSERT(err == NRFX_SUCCESS);
      break;

    case NRFX_SAADC_EVT_READY:
      LOG_DBG("SAADC Ready for sampling");
      break;

    case NRFX_SAADC_EVT_BUF_REQ:
      err = nrfx_saadc_buffer_set(&m_samples_buffer[next_free_buf_index()][0], SAADC_BUF_SIZE);
      if(NRFX_SUCCESS != err)
        LOG_ERR("nrfx_saadc_buffer_set: %d", err - NRFX_SUCCESS);
      break;
     

     

  default:
    LOG_DBG("SAADC evt %d", p_event->type);
    break;
  }
  return;
}

I have several problems at the moment:

1) getting a fault on the board when setting the buffer.  This doesn't happen in the sample code and also doesn't happen with v2.3.0 on the custom board.  Part of the problem is the compiler doesn't like nrf_saadc_value_t being a void*. Following advice on another post I changed the buffer to an int16_t and it compiles. but get the fault setting the buffer.

2) the code I used with 2.3.0 uses ppi and rtc2 which are no longer available?? Im not remembering at the moment which isn't available anymore if needed i can go back and build the oiginal code with 2.6.1. again.

I must be missing something simple.

Thanks for the help -- Brian

Related