This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using SAADC in nRF Connect SDK

Hi

I have been experimenting with ncs recently, just trying different things out.

I'm making an application based on the following example (Which is basically code from one of the Nordic's guides, which uses SAADC to control PWM output and with it LED intensity)

https://github.com/simon-iversen/sdk-nrf/tree/light_controller/samples/light_controller

Can anyone guide me through how can I set different AIN pin to be used(let's say AIN4) in this example?
I still don't understand how the whole device tree thing works, and I believe this would require some changes to the device tree.

Parents
  • Hello,

    Can anyone guide me through how can I set different AIN pin to be used(let's say AIN4) in this example?

    In this particular example you should be able to change the AIN pin to sample by changing the 15th line of main.c from:

    #define ADC_1ST_CHANNEL_INPUT NRF_SAADC_INPUT_AIN0

    To
    #define ADC_1ST_CHANNEL_INPUT NRF_SAADC_INPUT_AIN4


    I still don't understand how the whole device tree thing works, and I believe this would require some changes to the device tree.

    Yes, the device tree is a structure to familiarize with in its own, but in essence it is what Zephyr draws from when you for example set CONFIG_UART=y in prj.conf - this will make Zephyr initialize the UART peripheral, using the default parameters gotten from the device tree. This way, each board can have its own device tree, with different default mappings and configurations, while all you have to do in Zephyr to make use of it is CONFIG_*=y.
    If this then needs reconfiguring or modification you will have to modify the device tree file directly.

    Please do not hesitate to ask if any part of this should be unclear, or in the case that you've got any other questions!

    Best regards,
    Karl

  • Hi Karl

    I completely missed that #define. I thought I needed to use device_get_binding() to get to the arduino_adc: analog-connector from the device tree. I was trying something like:

    #define ADC_IN(i) DT_INST(i,ardunio_uno_adc)
    #define ADC_1 ADC_IN(1)
    
    const struct device *adc_dev;
    adc_dev = device_get_binding(ADC_1);
     

    I guess I still need some documentation reading.

    Thank you very much for your help, this works.

    And thank you for a detailed explanation!


    Best regards

    Emir

  • Thank you very much for your help, this works.

    And thank you for a detailed explanation!

    No problem at all, Emir - I'm happy to help! :) 

    Please do not hesitate to open another ticket if you should encounter any issues or questions in the future.

    Good luck with your development!

    Best regards,
    Karl

Reply Children
No Data
Related