Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "adc.h"
- // void adc_setup(void)
- // {
- // rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN);
- // rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
- // /* Set port PA1 for ADC1 to analogue mode. */
- // gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0|GPIO1);
- // /* Setup the ADC */
- // nvic_enable_irq(NVIC_ADC_IRQ);
- // u8 channel[2] = { ADC_CHANNEL0,ADC_CHANNEL1 };
- // adc_set_clk_prescale(ADC_CCR_ADCPRE_BY2);
- // adc_disable_scan_mode(ADC1);
- // adc_set_single_conversion_mode(ADC1);
- // adc_set_sample_time(ADC1, ADC_CHANNEL0, ADC_SMPR1_SMP_1DOT5CYC);
- // adc_set_sample_time(ADC1, ADC_CHANNEL1, ADC_SMPR1_SMP_1DOT5CYC);
- // adc_set_multi_mode(ADC_CCR_MULTI_INDEPENDENT);
- // adc_set_regular_sequence(ADC1, 2, channel);
- // adc_enable_eoc_interrupt(ADC1);
- // adc_power_on(ADC1);
- // }
- void adc_setup(void)
- {
- rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN);
- rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
- /* Set port PA1 for ADC1 to analogue mode. */
- gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0|GPIO1|GPIO4);
- /* Setup the ADC */
- nvic_enable_irq(NVIC_ADC_IRQ);
- u8 channel[3] = { ADC_CHANNEL0, ADC_CHANNEL1, ADC_CHANNEL4 };
- adc_set_clk_prescale(ADC_CCR_ADCPRE_BY2);
- adc_disable_scan_mode(ADC1);
- // Check if it needs to be in single conversion mode.
- adc_set_single_conversion_mode(ADC1);
- adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR1_SMP_1DOT5CYC);
- adc_set_multi_mode(ADC_CCR_MULTI_INDEPENDENT);
- adc_set_injected_sequence(ADC1, 3, channel);
- adc_enable_eoc_interrupt_injected(ADC1);
- // adc_eoc_after_each(ADC1);
- adc_power_on(ADC1);
- }
- // void adc_setup(void)
- // {
- // int i;
- // gpio_mode_setup(GPIOF, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO3);
- // rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC3EN);
- // /* Make sure the ADC doesn't run during config. */
- // adc_off(ADC3);
- // /* We configure everything for one single conversion. */
- // adc_disable_scan_mode(ADC3);
- // adc_set_single_conversion_mode(ADC3);
- // adc_disable_external_trigger_regular(ADC3);
- // adc_set_right_aligned(ADC3);
- // /* We want to read the temperature sensor, so we have to enable it. */
- // // adc_enable_temperature_sensor();
- // adc_set_sample_time_on_all_channels(ADC3, ADC_SMPR_SMP_28DOT5CYC);
- // adc_power_on(ADC3);
- // /* Wait for ADC starting up. */
- // for (i = 0; i < 800000; i++) /* Wait a bit. */
- // __asm__("nop");
- // //adc_reset_calibration(ADC3);
- // //adc_calibration(ADC3);
- // }
- void adc_isr(void)
- {
- /* Clear Injected End Of Conversion (JEOC) */
- // value = adc_read_regular(ADC1);
- ADC_SR(ADC1) &= ~ADC_SR_JEOC;
- value = adc_read_injected(ADC1, 1);
- value = adc_read_injected(ADC1, 2);
- value = adc_read_injected(ADC1, 3);
- ADC_SR(ADC1) &= ~ADC_SR_JEOC;
- }
Advertisement
Add Comment
Please, Sign In to add comment