ntc thermistor with nrf54L15DK

Hello,

I have some issues to do function an ntc thermistor with a nrf54L15DK.

An error about a wrong configuration of the adc reference or or the ADC gain appears almost everytime, and when it doesn't appear, nothing appear in the console.

Here is my prj.conf :

CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_GPIO=y
CONFIG_ADC=y
CONFIG_SENSOR=y
CONFIG_NTC_THERMISTOR=y
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_MAIN_STACK_SIZE=2048
# Active le pilote SAADC sur nRF

# (Optionnel) Permet le runtime PM si vous utilisez zephyr,pm-device-runtime-auto
CONFIG_PM_DEVICE_RUNTIME=y
CONFIG_PM_DEVICE=y
CONFIG_SERIAL=n
CONFIG_CONSOLE=n
CONFIG_RTT_CONSOLE=y
CONFIG_PRINTK=y

my overlay file :

/ {
    ntc0: ntc_thermistor {
        compatible = "ntc-thermistor-generic";
        status = "okay";
        io-channels = <&adc 4>;
        pullup-uv               = <3300>;
        pullup-ohm               = <10000>;       // résistance pull-up du module
        pulldown-ohm             = <10000>;       // résistance fixe de votre diviseur (NTC en pulldown)
        zephyr,compensation-table =
        <(0) 33869>,
        <(10) 20260>,
        <(20) 12552>,
        <(30) 8026>,
        <(40) 5281>,
        <(50) 3565>,
        <(60) 2465>,
        <(70) 1741>,
        <(80) 1254>,
        <(90) 920>,
        <(100) 686>;    
    };
};

/ {
    zephyr,user {
        io-channels = <&adc 4>;
    };
};


&adc {                      // on accède au périphérique ADC
    #address-cells = <1>;       // chaque enfant a 1 valeur dans reg, le canal
    #size-cells = <0>;          // pas de taille pour reg(seulement utile pour la mémoire)
    status = "okay";            // active le périphérique

    channel@4 {                 // on configure le canal 0 du SAADC
       
        reg = <0x4>;              // est le numéro du canal ADC
        zephyr,gain = "ADC_GAIN_1";               // diviseur de tension, ici 6
        zephyr,reference = "ADC_REF_INTERNAL";      // utilise la référence interne de 0.6 V
        //zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;   //Temps de capture de la tension, ici 10 micro sec
        zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
        //zephyr,input-positive = <NRF_SAADC_AIN0>;  // définit l’entrée connectée physiquement AIN0 = P0.04
        zephyr,input-positive = <NRF_SAADC_AIN4>; /* P1.11 for the nRF54L15 DK */
        //zephyr,resolution = <12>;           // résolution du convertisseur en 12 bits
    };

};

and my main.c file :

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/logging/log.h>
#include <zephyr/devicetree.h>
#include <hal/nrf_saadc.h>

LOG_MODULE_REGISTER(app);

int main(void)
{

// printk("Gain 1/6 = %d\n", NRF_SAADC_GAIN1_2);
//     printk("Gain 1/4 = %d\n", NRF_SAADC_GAIN1_4);

printk("gdrgsrt");
    printk("NTC sensor not ready");
    const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(ntc0));

    if (!device_is_ready(dev)) {
        LOG_ERR("NTC sensor not ready");
        return 1;
    }

    // if (sensor_init(dev) < 0) {
    //         LOG_ERR("Failed to init");
    //         continue;
    //     }

    while (1) {
        struct sensor_value temp;

        if (sensor_sample_fetch(dev) < 0) {
            LOG_ERR("Failed to fetch sample");
            continue;
        }

        if (sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp) < 0) {
            LOG_ERR("Failed to get temperature");
            continue;
        }

        LOG_INF("Temperature: %d.%06d C", temp.val1, temp.val2);
        k_sleep(K_SECONDS(1));
    }
}

Thank you !

Parents
  • Hi

    Can you explain what exactly this config error you're seeing is? And when you don't see it. Do you get any life signs at all from the nRF54L15 so you know whether it's running or not?

    Have you checked out the ADC lesson in the Intermediate course of our Devacademy here? https://academy.nordicsemi.com/courses/nrf-connect-sdk-intermediate/lessons/lesson-6-analog-to-digital-converter-adc/topic/adc-peripheral-on-nordic-devices/ It goes through how to use the ADC peripheral on Nordic devices, what ADC API to use when, and some exercises with sample code that showcases various ADC use cases.

    I see you've already switched to a free pin at least. Adding some more debugging to your project should give some information on where the application crashes.

    Best regards,

    Simon

  • Hello,

    Thank you for your answer!!

    I look at the course you sent, it helps me, thanks!!

    I change my prj.conf to :

    CONFIG_CBPRINTF_FP_SUPPORT=y
    CONFIG_GPIO=y
    CONFIG_ADC=y
    CONFIG_SENSOR=y
    CONFIG_LOG=y
    CONFIG_LOG_DEFAULT_LEVEL=3
    CONFIG_MAIN_STACK_SIZE=2048
    # Active le pilote SAADC sur nRF

    # (Optionnel) Permet le runtime PM si vous utilisez zephyr,pm-device-runtime-auto
    CONFIG_PM_DEVICE_RUNTIME=y
    CONFIG_PM_DEVICE=y
    CONFIG_SERIAL=y
    CONFIG_USE_SEGGER_RTT=n
    CONFIG_CONSOLE=y
    CONFIG_RTT_CONSOLE=n
    CONFIG_PRINTK=y

    and my overllay file to :
    / {
        ntc0: ntc_thermistor {
            compatible = "ntc-thermistor-generic";
            status = "okay";
            io-channels = <&adc 4>;
            pullup-uv               = <3300>;
            pullup-ohm               = <10000>;       // résistance pull-up du module
            pulldown-ohm             = <10000>;       // résistance fixe de votre diviseur (NTC en pulldown)
            zephyr,compensation-table =
            <(0) 33869>,
            <(10) 20260>,
            <(20) 12552>,
            <(30) 8026>,
            <(40) 5281>,
            <(50) 3565>,
            <(60) 2465>,
            <(70) 1741>,
            <(80) 1254>,
            <(90) 920>,
            <(100) 686>;    
        };
       
    };

    &adc {
        #address-cells = <1>;
        #size-cells = <0>;
        status = "okay";
        channel@4 {
            reg = <4>;
            zephyr,gain = "ADC_GAIN_1";
            zephyr,reference = "ADC_REF_INTERNAL";
            zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
            zephyr,input-positive = <NRF_SAADC_AIN4>; /* P1.11 for the nRF54L15 DK */
            zephyr,resolution = <14>;
        };
    };
     
    I have the NTC thermistor enabled in NRF kCONFIG :

    But when I build the project and I flash it, nothing appears on the terminal (COM8). Do you know why ? 
    Thanks!!
Reply
  • Hello,

    Thank you for your answer!!

    I look at the course you sent, it helps me, thanks!!

    I change my prj.conf to :

    CONFIG_CBPRINTF_FP_SUPPORT=y
    CONFIG_GPIO=y
    CONFIG_ADC=y
    CONFIG_SENSOR=y
    CONFIG_LOG=y
    CONFIG_LOG_DEFAULT_LEVEL=3
    CONFIG_MAIN_STACK_SIZE=2048
    # Active le pilote SAADC sur nRF

    # (Optionnel) Permet le runtime PM si vous utilisez zephyr,pm-device-runtime-auto
    CONFIG_PM_DEVICE_RUNTIME=y
    CONFIG_PM_DEVICE=y
    CONFIG_SERIAL=y
    CONFIG_USE_SEGGER_RTT=n
    CONFIG_CONSOLE=y
    CONFIG_RTT_CONSOLE=n
    CONFIG_PRINTK=y

    and my overllay file to :
    / {
        ntc0: ntc_thermistor {
            compatible = "ntc-thermistor-generic";
            status = "okay";
            io-channels = <&adc 4>;
            pullup-uv               = <3300>;
            pullup-ohm               = <10000>;       // résistance pull-up du module
            pulldown-ohm             = <10000>;       // résistance fixe de votre diviseur (NTC en pulldown)
            zephyr,compensation-table =
            <(0) 33869>,
            <(10) 20260>,
            <(20) 12552>,
            <(30) 8026>,
            <(40) 5281>,
            <(50) 3565>,
            <(60) 2465>,
            <(70) 1741>,
            <(80) 1254>,
            <(90) 920>,
            <(100) 686>;    
        };
       
    };

    &adc {
        #address-cells = <1>;
        #size-cells = <0>;
        status = "okay";
        channel@4 {
            reg = <4>;
            zephyr,gain = "ADC_GAIN_1";
            zephyr,reference = "ADC_REF_INTERNAL";
            zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
            zephyr,input-positive = <NRF_SAADC_AIN4>; /* P1.11 for the nRF54L15 DK */
            zephyr,resolution = <14>;
        };
    };
     
    I have the NTC thermistor enabled in NRF kCONFIG :

    But when I build the project and I flash it, nothing appears on the terminal (COM8). Do you know why ? 
    Thanks!!
Children
Related