TheLegace

Untitled

May 24th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.00 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.     rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN);
  27.     rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
  28. /* Set port PA1 for ADC1 to analogue mode. */
  29.     gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0|GPIO1|GPIO4);
  30. /* Setup the ADC */
  31.     nvic_enable_irq(NVIC_ADC_IRQ);
  32.     // u8 channel[3] = {ADC_CHANNEL0 , ADC_CHANNEL1,  ADC_CHANNEL4};
  33.     u8 channel[1] = {ADC_CHANNEL4};
  34.     adc_set_clk_prescale(ADC_CCR_ADCPRE_BY2);
  35.     adc_disable_scan_mode(ADC1);
  36.     // Check if it needs to be in single conversion mode.
  37.     adc_set_single_conversion_mode(ADC1);
  38.     adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR1_SMP_1DOT5CYC);
  39.     adc_set_multi_mode(ADC_CCR_MULTI_INDEPENDENT);
  40.     adc_set_injected_sequence(ADC1, 1, channel);
  41.     adc_enable_eoc_interrupt_injected(ADC1);
  42.     // adc_eoc_after_each(ADC1);
  43.     adc_power_on(ADC1);
  44. }
  45.  
  46. // void adc_setup(void)
  47. // {
  48. //     int i;
  49. //  gpio_mode_setup(GPIOF, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO3);
  50. //     rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC3EN);
  51.  
  52. //     /* Make sure the ADC doesn't run during config. */
  53. //     adc_off(ADC3);
  54.  
  55. //     /* We configure everything for one single conversion. */
  56. //     adc_disable_scan_mode(ADC3);
  57. //     adc_set_single_conversion_mode(ADC3);
  58. //     adc_disable_external_trigger_regular(ADC3);
  59. //     adc_set_right_aligned(ADC3);
  60. //     /* We want to read the temperature sensor, so we have to enable it. */
  61. //     // adc_enable_temperature_sensor();
  62. //     adc_set_sample_time_on_all_channels(ADC3, ADC_SMPR_SMP_28DOT5CYC);
  63. //     adc_power_on(ADC3);
  64.    
  65. //     /* Wait for ADC starting up. */
  66. //     for (i = 0; i < 800000; i++)    /* Wait a bit. */
  67. //             __asm__("nop");
  68.  
  69. //     //adc_reset_calibration(ADC3);
  70. //     //adc_calibration(ADC3);
  71. // }
  72.  
  73. void adc_isr(void)
  74. {
  75.     /* Clear Injected End Of Conversion (JEOC) */
  76.     // value = adc_read_regular(ADC1);
  77.     ADC_SR(ADC1) &= ~ADC_SR_JEOC;
  78.     value = adc_read_injected(ADC1, 3);
  79.     // value = adc_read_injected(ADC1, 3);
  80.     // value = adc_read_injected(ADC1, 2);
  81.  
  82.    
  83.    
  84.  
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment