TheLegace

Untitled

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