This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

hardfault about the saadc channel init

Hi,

I meet a hard fault handler issue when initialize the saadc channel. The code is as followed.

 

#define SAADC_SAMPLES_IN_BUFFER 2
int16_t touchs[2];
nrf_saadc_channel_config_t channel[2]; //saadc channel
nrf_drv_saadc_config_t saadc_config = NRFX_SAADC_DEFAULT_CONFIG;  //saadc
static nrf_saadc_value_t buffer[2][SAADC_SAMPLES_IN_BUFFER];  //buffer for saadc
void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
    if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
    {
        nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER);
        for (int i = 0; i < SAADC_SAMPLES_IN_BUFFER; i++)
        {
            touchs[i] = p_event->data.done.p_buffer[i];
        }
    }
}

void saadc_init()
{
    nrf_drv_saadc_init(&saadc_config, saadc_callback); //initial the saadc with the callback function
    saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT; //res = 12?
    channel[0].pin_p = yp;  //channel 0 yp
    nrf_drv_saadc_channel_init(0, &channel[0]);
    channel[1].pin_p = xp;   //channel 1 xp
    nrf_drv_saadc_channel_init(1, &channel[1]);
    nrf_drv_saadc_buffer_convert(buffer[0], SAADC_SAMPLES_IN_BUFFER); //read sample from saadc to buffer?
    nrf_drv_saadc_buffer_convert(buffer[1], SAADC_SAMPLES_IN_BUFFER);
}

When I set the breakpoint at line 22, the debugging process can work well, but when I move the breakpoint to line 24, the debugging process will jump to hard fault handler. Do you think my configuration of the saadc channel is wrong?

Thanks in advance for your help,

Leo

Related