TheLegace

Untitled

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