Actions

EmSys

Tm4clib-adc-programming-examples

From EdWiki

Programming Examples

The following example shows how to use the ADC API to initialize a sample sequencer for processor triggering, trigger the sample sequence, and then read back the data when it is ready.

  1. #include "cortex.h"
  2. #include "adc.h"
  3.  
  4. uint32_t ui32Value;
  5.  
  6. /* Enable the first sample sequencer to capture the value of channel 0 when the processor trigger occurs. */
  7. adc_sequence_configure(ADC0, 0, ADC_TRIGGER_PROCESSOR, 0);
  8. adc_sequence_step_configure(ADC0, 0, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0);
  9. adc_enable_sequence(ADC0, 0);
  10.  
  11. /* Trigger the sample sequence. */
  12. adc_processor_trigger(ADC0, 0);
  13.  
  14. /* Wait until the sample sequence has completed. */
  15. while(!adc_int_status(ADC0, 0, false)) {
  16.     ;
  17. }
  18.  
  19. /* Read the value from the ADC. */
  20. adc_get_sequence_data(ADC0, 0, &ui32Value);