Sharing pin with SAADC and GPIO

Hello! I am trying using the nRF52840 and I am having trouble writing a digital output to a pin that I am sharing with the SAADC.  When I remove the analogRead, the device can easily output a digital signal to the pin in question.  When I have called analogRead, after trying to digitalWrite to the pin, it stays low, but I can see a slight pulses to 1V or so every ~10ms.  

When digging deeper, I found the specific code that causes the pin to be unusable as GPIO output is this in wiring_analog_nRF52.c:

NRF_SAADC->CH[0].PSELN = psel;
NRF_SAADC->CH[0].PSELP = psel;

So, when trying to disable the connection to the SAADC, I found in this previous post I can remap the PSELP to no connection and then restart the SAADC as such:

NRF_SAADC->CH[0].PSELP = 0;
NRF_SAADC->CH[0].PSELN = 0;
NRF_SAADC->ENABLE = 1;
__NOP();
__NOP();
__NOP();
__NOP();
NRF_SAADC->ENABLE = 0;

This doesn't seem to work, and no matter what I do to the the pin I can't seem to write an output that doesn't get pulled to ground.  Am I missing something?  Thank you in advance for the help.

  • Hi rsparks,

    I have gone over the DevZone post you linked, and also our current driver implementation. I can see that for uninitializing the channel pin select (PSELP, PSELN), the registers are just written to 0, not requiring the brief enabling of the peripheral that you did with:

    NRF_SAADC->ENABLE = 1;
    __NOP();
    __NOP();
    __NOP();
    __NOP();
    NRF_SAADC->ENABLE = 0;

    Other than that, I don't see anything that you might be missing. The only thing I can think of to help is to try reproducing the issue here. However, it seems not possible before Wednesday with my current schedule.

    Could you please check if there are any other factors? Such as the GPIO initialization was done before the SAADC channels had released the pins?

    I don't see the file "wiring_analog_nRF52.c" in any of our SDKs though. Are you using the Adafruit_nRF52_Arduino project with Arduino?

    Is using our nRF Connect SDK not an option? I guess that the complexity of a full RTOS is not what you are looking for if you opted to use the Arduino platform though.

    Hieu

Related