TheLegace

Untitled

May 22nd, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. #include "adc.h"
  2.  
  3.  
  4. void adc_setup(void)
  5. {
  6.     rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN);
  7.     rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
  8. /* Set port PA1 for ADC1 to analogue mode. */
  9.     gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0|GPIO1);
  10. /* Setup the ADC */
  11.     nvic_enable_irq(NVIC_ADC_IRQ);
  12.     u8 channel[2] = { ADC_CHANNEL0,ADC_CHANNEL1 };
  13.     adc_set_clk_prescale(ADC_CCR_ADCPRE_BY2);
  14.     adc_disable_scan_mode(ADC1);
  15.     adc_set_single_conversion_mode(ADC1);
  16.     adc_set_sample_time(ADC1, ADC_CHANNEL0, ADC_SMPR1_SMP_1DOT5CYC);
  17.     adc_set_sample_time(ADC1, ADC_CHANNEL1, ADC_SMPR1_SMP_1DOT5CYC);
  18.     adc_set_multi_mode(ADC_CCR_MULTI_INDEPENDENT);
  19.     adc_set_regular_sequence(ADC1, 2, channel);
  20.     adc_enable_eoc_interrupt(ADC1);
  21.     adc_power_on(ADC1);
  22. }
  23.  
  24. // void adc_setup(void)
  25. // {
  26. //     int i;
  27. //  gpio_mode_setup(GPIOF, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO3);
  28. //     rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC3EN);
  29.  
  30. //     /* Make sure the ADC doesn't run during config. */
  31. //     adc_off(ADC3);
  32.  
  33. //     /* We configure everything for one single conversion. */
  34. //     adc_disable_scan_mode(ADC3);
  35. //     adc_set_single_conversion_mode(ADC3);
  36. //     adc_disable_external_trigger_regular(ADC3);
  37. //     adc_set_right_aligned(ADC3);
  38. //     /* We want to read the temperature sensor, so we have to enable it. */
  39. //     // adc_enable_temperature_sensor();
  40. //     adc_set_sample_time_on_all_channels(ADC3, ADC_SMPR_SMP_28DOT5CYC);
  41. //     adc_power_on(ADC3);
  42.    
  43. //     /* Wait for ADC starting up. */
  44. //     for (i = 0; i < 800000; i++)    /* Wait a bit. */
  45. //             __asm__("nop");
  46.  
  47. //     //adc_reset_calibration(ADC3);
  48. //     //adc_calibration(ADC3);
  49. // }
  50.  
  51. void adc_isr(void)
  52. {
  53.     /* Clear Injected End Of Conversion (JEOC) */
  54.     value = adc_read_regular(ADC1);
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment