2024-09-12 08:08 AM
I'm searching for a simple API call such as found on Arduino :
does such a thing exist? Hoping for pal_lld_analogReadpad( PORT_x, pinNumber );
I find in adc_lld.h there is an array of functions which I am unsure why they exist or how to use them.
Is there an example for reading a port configured as
Thanks
Paul
Solved! Go to Solution.
2024-09-13 06:17 AM
Hi!
I'm not aware of any such simple function as analogRead(). I believe you have to use the low-level ADC driver. You can call adc_lld_start_conversion (ADCDriver *adcp, ADCConversionGroup *grpp, adcsample_t *samples, size_t depth) to start a analog-to-digital conversion chain. The ADCConversionGroup allows you to configure a chain of adc conversions that samples several channels in a row. And I think the depth parameter allows you to take multiple samples of each channel.
Once the conversion is complete, the driver will invoke a callback function that you have supplied in the configuration parameter to the adc_lld_start(ADCDriver *adcp, ADCConfig *config) function which you should have called when you initialized the ADC driver. The converted sample is provided in the buffer you get in the callback:
typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n);
If you just want to read a single channel one time, this whole driver is a bit of overkill in my opinion. It's always possible to write your own driver that suits your needs if you want to, but that is a lot of work too.
2024-09-13 06:17 AM
Hi!
I'm not aware of any such simple function as analogRead(). I believe you have to use the low-level ADC driver. You can call adc_lld_start_conversion (ADCDriver *adcp, ADCConversionGroup *grpp, adcsample_t *samples, size_t depth) to start a analog-to-digital conversion chain. The ADCConversionGroup allows you to configure a chain of adc conversions that samples several channels in a row. And I think the depth parameter allows you to take multiple samples of each channel.
Once the conversion is complete, the driver will invoke a callback function that you have supplied in the configuration parameter to the adc_lld_start(ADCDriver *adcp, ADCConfig *config) function which you should have called when you initialized the ADC driver. The converted sample is provided in the buffer you get in the callback:
typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n);
If you just want to read a single channel one time, this whole driver is a bit of overkill in my opinion. It's always possible to write your own driver that suits your needs if you want to, but that is a lot of work too.