2.8.1.1.3 Workflow
- Create a module software instance structure for the ADC module to store the ADC driver state while in use.
structadc_module adc_instance;Note: This should never go out of scope as long as the module is in use. In most cases, this should be global. - Configure the ADC module.
- Create an ADC module configuration struct, which can be filled out to adjust the configuration of a physical ADC peripheral.
structadc_config config_adc; - Initialize the ADC configuration struct with the module's default values.
adc_get_config_defaults(&config_adc);Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings. - Set ADC configurations.
#if (SAMC21)adc_init(&adc_instance, ADC1, &config_adc);#elseadc_init(&adc_instance, ADC, &config_adc);#endif - Enable the ADC module so that conversions can be made.
adc_enable(&adc_instance);
