cancel
Showing results for 
Search instead for 
Did you mean: 

SPC560 Analog read of a pin

Bucko
Associate

I'm searching for a simple API call such as found on Arduino :

theValue = analogRead(port);

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 

Bucko_0-1726153376450.png

Thanks

Paul

 

1 ACCEPTED SOLUTION

Accepted Solutions
DaveJ
Associate II

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. 

View solution in original post

1 REPLY 1
DaveJ
Associate II

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.