libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
adc.c
Go to the documentation of this file.
1/** @addtogroup adc_file ADC peripheral API
2 * @ingroup peripheral_apis
3 *
4 * @author @htmlonly © @endhtmlonly 2012
5 * Ken Sarkies <ksarkies@internode.on.net>
6 *
7 * @date 30 August 2012
8 *
9 * This library supports the A/D Converter Control System in the STM32 series
10 * of ARM Cortex Microcontrollers by ST Microelectronics.
11 *
12 * Devices can have up to three A/D converters each with their own set of
13 * registers. However all the A/D converters share a common clock which is
14 * prescaled from the APB2 clock by default by a minimum factor of 2 to a
15 * maximum of 8. The ADC resolution can be set to 12, 10, 8 or 6 bits.
16 *
17 * Each A/D converter has up to 19 channels:
18 * @li On ADC1 the analog channels 16 is internally connected to the
19 * temperature sensor, channel 17 to V<sub>REFINT</sub>, and channel 18
20 * to V<sub>BATT</sub>.
21 * @li On ADC2 and ADC3 the analog channels 16 - 18 are not used.
22 *
23 * The conversions can occur as a one-off conversion whereby the process stops
24 * once conversion is complete. The conversions can also be continuous wherein
25 * a new conversion starts immediately the previous conversion has ended.
26 *
27 * Conversion can occur as a single channel conversion or a scan of a group of
28 * channels in either continuous or one-off mode. If more than one channel is
29 * converted in a scan group, DMA must be used to transfer the data as there is
30 * only one result register available. An interrupt can be set to occur at the
31 * end*
32 * of conversion, which occurs after all channels have been scanned.
33 *
34 * A discontinuous mode allows a subgroup of group of a channels to be
35 * converted in bursts of a given length.
36 *
37 * Injected conversions allow a second group of channels to be converted
38 * separately from the regular group. An interrupt can be set to occur at the
39 * end of conversion, which occurs after all channels have been scanned.
40 *
41 * @section adc_f3_api_ex Basic ADC Handling API.
42 *
43 * Example 1: Simple single channel conversion polled. Enable the peripheral
44 * clock and ADC, reset ADC and set the prescaler divider. Set multiple mode to
45 * independent.
46 *
47 * @code
48 * gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1);
49 * rcc_periph_clock_enable(RCC_ADC1);
50 * adc_set_clk_prescale(RCC_CFGR_ADCPRE_BY2);
51 * adc_disable_scan_mode(ADC1);
52 * adc_set_single_conversion_mode(ADC1);
53 * adc_set_sample_time(ADC1, ADC_CHANNEL0, ADC_SMPR1_SMP_1DOT5CYC);
54 * uint8_t channels[] = ADC_CHANNEL0;
55 * adc_set_regular_sequence(ADC1, 1, channels);
56 * adc_set_multi_mode(ADC_CCR_DUAL_INDEPENDENT);
57 * adc_power_on(ADC1);
58 * adc_start_conversion_regular(ADC1);
59 * while (! adc_eoc(ADC1));
60 * reg16 = adc_read_regular(ADC1);
61 * @endcode
62 *
63 * LGPL License Terms @ref lgpl_license
64 */
65/*
66 * This file is part of the libopencm3 project.
67 *
68 * Copyright (C) 2012 Ken Sarkies <ksarkies@internode.on.net>
69 *
70 * This library is free software: you can redistribute it and/or modify
71 * it under the terms of the GNU Lesser General Public License as published by
72 * the Free Software Foundation, either version 3 of the License, or
73 * (at your option) any later version.
74 *
75 * This library is distributed in the hope that it will be useful,
76 * but WITHOUT ANY WARRANTY; without even the implied warranty of
77 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78 * GNU Lesser General Public License for more details.
79 *
80 * You should have received a copy of the GNU Lesser General Public License
81 * along with this library. If not, see <http://www.gnu.org/licenses/>.
82 */
83
85
86/**@{*/
87
88/*---------------------------------------------------------------------------*/
89/** @brief ADC Enable Analog Watchdog for Regular Conversions
90 *
91 * The analog watchdog allows the monitoring of an analog signal between two
92 * threshold levels. The thresholds must be preset. Comparison is done before
93 * data alignment takes place, so the thresholds are left-aligned.
94 *
95 * @param[in] adc Unsigned int32. ADC block register address base @ref
96 * adc_reg_base
97 */
98
100{
102}
103
104/*---------------------------------------------------------------------------*/
105/** @brief ADC Enable Analog Watchdog for Regular Conversions
106 *
107 * The analog watchdog allows the monitoring of an analog signal between two
108 * threshold levels. The thresholds must be preset. Comparison is done before
109 * data alignment takes place, so the thresholds are left-aligned.
110 *
111 * @param[in] adc Unsigned int32. ADC block register address base @ref
112 * adc_reg_base
113 */
115{
116 ADC_CFGR1(adc) &= ~ADC_CFGR1_AWD1EN;
117}
118
119/*---------------------------------------------------------------------------*/
120/** @brief ADC Enable Analog Watchdog for Injected Conversions
121 *
122 * The analog watchdog allows the monitoring of an analog signal between two
123 * threshold levels. The thresholds must be preset. Comparison is done before
124 * data alignment takes place, so the thresholds are left-aligned.
125 *
126 * @param[in] adc Unsigned int32. ADC block register address base @ref
127 * adc_reg_base
128 */
129
131{
133}
134
135/*---------------------------------------------------------------------------*/
136/** @brief ADC Disable Analog Watchdog for Injected Conversions
137 *
138 * @param[in] adc Unsigned int32. ADC block register address base @ref
139 * adc_reg_base
140 */
141
143{
144 ADC_CFGR1(adc) &= ~ADC_CFGR1_JAWD1EN;
145}
146
147/*---------------------------------------------------------------------------*/
148/** @brief ADC Enable Discontinuous Mode for Regular Conversions
149 *
150 * In this mode the ADC converts, on each trigger, a subgroup of up to 8 of the
151 * defined regular channel group. The subgroup is defined by the number of
152 * consecutive channels to be converted. After a subgroup has been converted
153 * the next trigger will start conversion of the immediately following subgroup
154 * of the same length or until the whole group has all been converted. When the
155 * whole group has been converted, the next trigger will restart conversion of
156 * the subgroup at the beginning of the whole group.
157 *
158 * @param[in] adc ADC block register address base @ref adc_reg_base
159 * @param[in] length Number of channels in the group @ref adc_cr1_discnum
160 */
161void adc_enable_discontinuous_mode_regular(uint32_t adc, uint8_t length)
162{
163 if ((length-1) > 7) {
164 return;
165 }
167 ADC_CFGR1(adc) |= ((length-1) << ADC_CFGR1_DISCNUM_SHIFT);
168}
169
170/*---------------------------------------------------------------------------*/
171/** @brief ADC Disable Discontinuous Mode for Regular Conversions
172 *
173 * @param[in] adc Unsigned int32. ADC block register address base @ref
174 * adc_reg_base
175 */
176
178{
179 ADC_CFGR1(adc) &= ~ADC_CFGR1_DISCEN;
180}
181
182/*---------------------------------------------------------------------------*/
183/** @brief ADC Enable Discontinuous Mode for Injected Conversions
184 *
185 * In this mode the ADC converts sequentially one channel of the defined group
186 * of injected channels, cycling back to the first channel in the group once
187 * the entire group has been converted.
188 *
189 * @param[in] adc Unsigned int32. ADC block register address base @ref
190 * adc_reg_base
191 */
192
194{
196}
197
198/*---------------------------------------------------------------------------*/
199/** @brief ADC Disable Discontinuous Mode for Injected Conversions
200 *
201 * @param[in] adc Unsigned int32. ADC block register address base @ref
202 * adc_reg_base
203 */
204
206{
207 ADC_CFGR1(adc) &= ~ADC_CFGR1_JDISCEN;
208}
209
210/*---------------------------------------------------------------------------*/
211/** @brief ADC Enable Automatic Injected Conversions
212 *
213 * The ADC converts a defined injected group of channels immediately after the
214 * regular channels have been converted. The external trigger on the injected
215 * channels is disabled as required.
216 *
217 * @param[in] adc Unsigned int32. ADC block register address base @ref
218 * adc_reg_base
219 */
220
222{
225}
226
227/*---------------------------------------------------------------------------*/
228/** @brief ADC Disable Automatic Injected Conversions
229 *
230 * @param[in] adc Unsigned int32. ADC block register address base @ref
231 * adc_reg_base
232 */
233
235{
236 ADC_CFGR1(adc) &= ~ADC_CFGR1_JAUTO;
237}
238/*---------------------------------------------------------------------------*/
239/** @brief ADC Enable Analog Watchdog for All Regular and/or Injected Channels
240 *
241 * The analog watchdog allows the monitoring of an analog signal between two
242 * threshold levels. The thresholds must be preset. Comparison is done before
243 * data alignment takes place, so the thresholds are left-aligned.
244 *
245 * @note The analog watchdog must be enabled for either or both of the regular
246 * or injected channels. If neither are enabled, the analog watchdog feature
247 * will be disabled.
248 *
249 * @ref adc_enable_analog_watchdog_injected, @ref
250 * adc_enable_analog_watchdog_regular.
251 *
252 * @param[in] adc Unsigned int32. ADC block register address base @ref
253 * adc_reg_base
254 */
255
257{
258 ADC_CFGR1(adc) &= ~ADC_CFGR1_AWD1SGL;
259}
260
261/*---------------------------------------------------------------------------*/
262/** @brief ADC Enable Analog Watchdog for a Selected Channel
263 *
264 * The analog watchdog allows the monitoring of an analog signal between two
265 * threshold levels. The thresholds must be preset. Comparison is done before
266 * data alignment takes place, so the thresholds are left-aligned.
267 *
268 * @note The analog watchdog must be enabled for either or both of the regular
269 * or injected channels. If neither are enabled, the analog watchdog feature
270 * will be disabled. If both are enabled, the same channel number is monitored
271 * @ref adc_enable_analog_watchdog_injected, @ref
272 * adc_enable_analog_watchdog_regular.
273 *
274 * @param[in] adc Unsigned int32. ADC block register address base @ref
275 * adc_reg_base
276 * @param[in] channel Unsigned int8. ADC channel numbe
277 * @ref adc_watchdog_channel
278 */
279
281 uint8_t channel)
282{
283 ADC_CFGR1(adc) = (ADC_CFGR1(adc) & ~ADC_CFGR1_AWD1CH) |
284 ADC_CFGR1_AWD1CH_VAL(channel);
285
287}
288
289
290/*---------------------------------------------------------------------------*/
291/** @brief ADC Enable Injected End-Of-Conversion Interrupt
292 *
293 * @param[in] adc Unsigned int32. ADC block register address base @ref
294 * adc_reg_base
295 */
296
298{
299 ADC_IER(adc) |= ADC_IER_JEOCIE;
300}
301
302/*---------------------------------------------------------------------------*/
303/** @brief ADC Disable Injected End-Of-Conversion Interrupt
304 *
305 * @param[in] adc Unsigned int32. ADC block register address base @ref
306 * adc_reg_base
307 */
308
310{
311 ADC_IER(adc) &= ~ADC_IER_JEOCIE;
312}
313
314/*---------------------------------------------------------------------------*/
315/** @brief ADC Enable Injected End-Of-Sequence Interrupt
316 *
317 * @param[in] adc Unsigned int32. ADC block register address base @ref
318 * adc_reg_base
319 */
320
322{
323 ADC_IER(adc) |= ADC_IER_JEOSIE;
324}
325
326/*---------------------------------------------------------------------------*/
327/** @brief ADC Disable Injected End-Of-Sequence Interrupt
328 *
329 * @param[in] adc Unsigned int32. ADC block register address base @ref
330 * adc_reg_base
331 */
332
334{
335 ADC_IER(adc) &= ~ADC_IER_JEOSIE;
336}
337
338
339/*---------------------------------------------------------------------------*/
340/** @brief ADC Enable Analog Watchdog Interrupt
341 *
342 * @param[in] adc Unsigned int32. ADC block register address base @ref
343 * adc_reg_base
344 */
345
347{
348 ADC_IER(adc) |= ADC_IER_AWD1IE;
349 ADC_IER(adc) |= ADC_IER_AWD2IE;
350 ADC_IER(adc) |= ADC_IER_AWD3IE;
351}
352
353/*---------------------------------------------------------------------------*/
354/** @brief ADC Disable Analog Watchdog Interrupt
355 *
356 * @param[in] adc Unsigned int32. ADC block register address base @ref
357 * adc_reg_base
358 */
359
361{
362 ADC_IER(adc) &= ~ADC_IER_AWD1IE;
363 ADC_IER(adc) &= ~ADC_IER_AWD2IE;
364 ADC_IER(adc) &= ~ADC_IER_AWD3IE;
365}
366
367/*---------------------------------------------------------------------------*/
368/** @brief ADC Enable Regular End-Of-Sequence Interrupt
369 *
370 * @param[in] adc Unsigned int32. ADC block register address base @ref
371 * adc_reg_base
372 */
373
374void adc_enable_eos_interrupt(uint32_t adc)
375{
376 ADC_IER(adc) |= ADC_IER_EOSIE;
377}
378
379/*---------------------------------------------------------------------------*/
380/** @brief ADC Disable Regular End-Of-Sequence Interrupt
381 *
382 * @param[in] adc Unsigned int32. ADC block register address base @ref
383 * adc_reg_base
384 */
385
387{
388 ADC_IER(adc) &= ~ADC_IER_EOSIE;
389}
390
391
392/*---------------------------------------------------------------------------*/
393/** @brief ADC Software Triggered Conversion on Injected Channels
394 *
395 * This starts conversion on a set of defined injected channels.
396 * Depending on the configuration bits JEXTEN, a conversion will start
397 * immediately (software trigger configuration) or once an injected hardware
398 * trigger event occurs (hardware trigger configuration).
399 *
400 * @param[in] adc Unsigned int32. ADC block register address base @ref
401 * adc_reg_base
402 */
403
405{
406 /* Start conversion on injected channels. */
407 ADC_CR(adc) |= ADC_CR_JADSTART;
408}
409
410
411/** ADC Set Analog Watchdog Upper Threshold.
412 * @param[in] adc ADC block register address base
413 * @ref adc_reg_base
414 * @param[in] threshold Upper threshold value
415 */
416void adc_set_watchdog_high_threshold(uint32_t adc, uint16_t threshold)
417{
418 uint32_t reg32 = 0;
419 uint32_t mask = 0xf000ffff;
420
421 reg32 |= (threshold << 16);
422 reg32 &= ~mask; /* clear masked bits. */
423
424 ADC_TR1(adc) = (ADC_TR1(adc) & mask) | reg32;
425 ADC_TR2(adc) = (ADC_TR2(adc) & mask) | reg32;
426 ADC_TR3(adc) = (ADC_TR3(adc) & mask) | reg32;
427}
428
429/** ADC Set Analog Watchdog Lower Threshold.
430 * @param[in] adc ADC block register address base
431 * @ref adc_reg_base
432 * @param[in] threshold Lower threshold value
433 */
434void adc_set_watchdog_low_threshold(uint32_t adc, uint16_t threshold)
435{
436 uint32_t reg32 = 0;
437 uint32_t mask = 0xfffff000;
438 reg32 = (uint32_t)threshold;
439 reg32 &= ~mask; /* clear masked bits. */
440
441 ADC_TR1(adc) = (ADC_TR1(adc) & mask) | reg32;
442 ADC_TR2(adc) = (ADC_TR2(adc) & mask) | reg32;
443 ADC_TR3(adc) = (ADC_TR3(adc) & mask) | reg32;
444}
445
446
447/*---------------------------------------------------------------------------*/
448/** @brief ADC Set an Injected Channel Conversion Sequence
449 *
450 * Defines a sequence of channels to be converted as an injected group with a
451 * length from 1 to 4 channels. If this is called during conversion, the current
452 * conversion is reset and conversion begins again with the newly defined group.
453 *
454 * @param[in] adc Unsigned int32. ADC block register address base
455 * @ref adc_reg_base
456 * @param[in] length Unsigned int8. Number of channels in the group.
457 * @param[in] channel Unsigned int8[]. Set of channels in sequence, integers
458 * 0..18
459 */
460
461void adc_set_injected_sequence(uint32_t adc, uint8_t length, uint8_t channel[])
462{
463 uint32_t reg32 = 0;
464 uint8_t i = 0;
465
466 /* Maximum sequence length is 4 channels. Minimum sequence is 1.*/
467 if ((length - 1) > 3) {
468 return;
469 }
470
471 for (i = 0; i < length; i++) {
472 reg32 |= ADC_JSQR_JSQ_VAL(4 - i, channel[length - i - 1]);
473 }
474
475 reg32 |= ADC_JSQR_JL_VAL(length);
476
477 ADC_JSQR(adc) = reg32;
478}
479
480/*---------------------------------------------------------------------------*/
481/** @brief ADC Read the End-of-Conversion Flag for Injected Conversion
482 *
483 * This flag is set by hardware at the end of each injected conversion of a
484 * channel when a new data is available in the corresponding ADCx_JDRy register.
485 *
486 * @param[in] adc Unsigned int32. ADC block register address base
487 * @ref adc_reg_base
488 * @returns bool. End of conversion flag.
489 */
490
491bool adc_eoc_injected(uint32_t adc)
492{
493 return ADC_ISR(adc) & ADC_ISR_JEOC;
494}
495
496/*---------------------------------------------------------------------------*/
497/** @brief ADC Read the End-of-Sequence Flag for Injected Conversions
498 *
499 * This flag is set after all channels of an injected group have been
500 * converted.
501 *
502 * @param[in] adc Unsigned int32. ADC block register address base
503 * @ref adc_reg_base
504 * @returns bool. End of conversion flag.
505 */
506bool adc_eos_injected(uint32_t adc)
507{
508 return ADC_ISR(adc) & ADC_ISR_JEOS;
509}
510
511
512/*---------------------------------------------------------------------------*/
513/** @brief ADC Read from an Injected Conversion Result Register
514 *
515 * The result read back from the selected injected result register (one of four)
516 * is 12 bits, right or left aligned within the first 16 bits. The result can
517 * have a negative value if the injected channel offset has been set @see
518 * adc_set_injected_offset.
519 *
520 * @param[in] adc Unsigned int32. ADC block register address base @ref
521 * adc_reg_base
522 * @param[in] reg Unsigned int8. Register number (1 ... 4).
523 * @returns Unsigned int32 conversion result.
524 */
525
526uint32_t adc_read_injected(uint32_t adc, uint8_t reg)
527{
528 switch (reg) {
529 case 1:
530 return ADC_JDR1(adc);
531 case 2:
532 return ADC_JDR2(adc);
533 case 3:
534 return ADC_JDR3(adc);
535 case 4:
536 return ADC_JDR4(adc);
537 }
538 return 0;
539}
540
541/*---------------------------------------------------------------------------*/
542/** @brief ADC Set the Injected Channel Data Offset
543 *
544 * This value is subtracted from the injected channel results after conversion
545 * is complete, and can result in negative results. A separate value can be
546 * specified for each injected data register.
547 *
548 * @param[in] adc Unsigned int32. ADC block register address base
549 * @ref adc_reg_base
550 * @param[in] reg Unsigned int8. Register number (1 ... 4).
551 * @param[in] offset Unsigned int32.
552*/
553
554void adc_set_injected_offset(uint32_t adc, uint8_t reg, uint32_t offset)
555{
556 switch (reg) {
557 case 1:
559 ADC_OFR1(adc) |= offset;
560 break;
561 case 2:
563 ADC_OFR2(adc) |= offset;
564 break;
565 case 3:
567 ADC_OFR3(adc) |= offset;
568 break;
569 case 4:
571 ADC_OFR4(adc) |= offset;
572 break;
573 }
574}
575
576/*---------------------------------------------------------------------------*/
577/** @brief ADC Set Clock Prescale
578 *
579 * The ADC clock taken from the APB2 clock can be scaled down by 2, 4, 6 or 8.
580 *
581 * @param adc peripheral of choice @ref adc_reg_base
582 * @param[in] prescale Unsigned int32. Prescale value for ADC Clock @ref
583 * adc_ccr_adcpre
584 */
585void adc_set_clk_prescale(uint32_t adc, uint32_t prescale)
586{
587 uint32_t reg32 = ((ADC_CCR(adc) & ~ADC_CCR_CKMODE_MASK) | prescale);
588 ADC_CCR(adc) = reg32;
589}
590
591/*---------------------------------------------------------------------------*/
592/** @brief ADC set multi mode
593 *
594 * The multiple mode can uses these arrangement:
595 * - ADC1 as master and ADC2 as slave
596 * - ADC3 as master and ADC4 as slave
597 *
598 * This setting is applied to ADC master only (ADC1 or ADC3).
599 *
600 * The various modes possible are described in the reference manual.
601 *
602 * @param adc peripheral of choice @ref adc_reg_base
603 * @param[in] mode Multiple mode selection from @ref adc_multi_mode
604 */
605void adc_set_multi_mode(uint32_t adc, uint32_t mode)
606{
608 ADC_CCR(adc) |= (mode << ADC_CCR_DUAL_SHIFT);
609}
610
611/*---------------------------------------------------------------------------*/
612/** @brief ADC Enable an External Trigger for Regular Channels
613 *
614 * This enables an external trigger for set of defined regular channels, and
615 * sets the polarity of the trigger event: rising or falling edge or both. Note
616 * that if the trigger polarity is zero, triggering is disabled.
617 *
618 * @param[in] adc Unsigned int32. ADC block register address base @ref
619 * adc_reg_base
620 * @param[in] trigger Unsigned int32. Trigger identifier
621 * @ref adc_trigger_regular
622 * @param[in] polarity Unsigned int32. Trigger polarity @ref
623 * adc_trigger_polarity_regular
624 */
625
626void adc_enable_external_trigger_regular(uint32_t adc, uint32_t trigger,
627 uint32_t polarity)
628{
629 uint32_t reg32 = ADC_CFGR1(adc);
630
632 reg32 |= (trigger | polarity);
633 ADC_CFGR1(adc) = reg32;
634}
635
636/*---------------------------------------------------------------------------*/
637/** @brief ADC Disable an External Trigger for Regular Channels
638 *
639 * @param[in] adc Unsigned int32. ADC block register address base
640 * @ref adc_reg_base
641 */
642
644{
645 ADC_CFGR1(adc) &= ~ADC_CFGR1_EXTEN_MASK;
646}
647
648/*---------------------------------------------------------------------------*/
649/** @brief ADC Enable an External Trigger for Injected Channels
650 *
651 * This enables an external trigger for set of defined injected channels, and
652 * sets the polarity of the trigger event: rising or falling edge or both.
653 *
654 * @param[in] adc Unsigned int32. ADC block register address base
655 * @ref adc_reg_base
656 * @param[in] trigger Unsigned int8. Trigger identifier
657 * @ref adc_trigger_injected
658 * @param[in] polarity Unsigned int32. Trigger polarity
659 * @ref adc_trigger_polarity_injected
660*/
661
662void adc_enable_external_trigger_injected(uint32_t adc, uint32_t trigger,
663 uint32_t polarity)
664{
665 uint32_t reg32 = ADC_JSQR(adc);
666
668 reg32 |= (trigger | polarity);
669 ADC_JSQR(adc) = reg32;
670}
671
672/*---------------------------------------------------------------------------*/
673/** @brief ADC Disable an External Trigger for Injected Channels
674 *
675 * @param[in] adc Unsigned int32. ADC block register address base @ref
676 * adc_reg_base
677 */
678
680{
681 ADC_JSQR(adc) &= ~ADC_JSQR_JEXTEN_MASK;
682}
683
684
685/*---------------------------------------------------------------------------*/
686/** @brief ADC Read the Analog Watchdog Flag
687 *
688 * This flag is set when the converted voltage crosses the high or low
689 * thresholds.
690 *
691 * @param[in] adc Unsigned int32. ADC block register address base
692 * @ref adc_reg_base
693 * @returns bool. AWD flag.
694 */
695
696bool adc_awd(uint32_t adc)
697{
698 return (ADC_ISR(adc) & ADC_ISR_AWD1) &&
699 (ADC_ISR(adc) & ADC_ISR_AWD2) &&
700 (ADC_ISR(adc) & ADC_ISR_AWD3);
701}
702
703
704/**
705 * Enable the ADC Voltage regulator
706 * Before any use of the ADC, the ADC Voltage regulator must be enabled.
707 * You must wait up to 10uSecs afterwards before trying anything else.
708 * @param[in] adc ADC block register address base
709 * @sa adc_disable_regulator
710 */
711void adc_enable_regulator(uint32_t adc)
712{
713 ADC_CR(adc) &= ~ADC_CR_ADVREGEN_MASK;
715}
716
717/**
718 * Disable the ADC Voltage regulator
719 * You can disable the adc vreg when not in use to save power
720 * @param[in] adc ADC block register address base
721 * @sa adc_enable_regulator
722 */
723void adc_disable_regulator(uint32_t adc)
724{
725 ADC_CR(adc) &= ~ADC_CR_ADVREGEN_MASK;
727}
728
729/**@}*/
730
#define ADC_CFGR1_AWD1CH_VAL(x)
AWD1CH: Analog watchdog 1 channel selection.
#define ADC_CFGR1_AWD1SGL
AWD1SGL: Enable the watchdog 1 on a single channel or on all channels.
#define ADC_CFGR1_EXTEN_MASK
#define ADC_CFGR1_AWD1EN
AWD1EN: Analog watchdog 1 enable on regular channels.
#define ADC_CFGR1_DISCEN
DISCEN: Discontinuous mode for regular channels.
#define ADC_JSQR_JL_VAL(val)
Definition: f3/adc.h:269
#define ADC_IER_AWD3IE
#define ADC_CR_JADSTART
#define ADC_CFGR1_JAUTO
#define ADC_JSQR_JSQ_VAL(n, val)
Definition: f3/adc.h:268
#define ADC_ISR_JEOC
#define ADC_CFGR1_JAWD1EN
#define ADC_IER_JEOSIE
#define ADC_OFR4_OFFSET4_EN
Definition: f3/adc.h:359
#define ADC_IER_AWD2IE
#define ADC_OFR1_OFFSET1_EN
Definition: f3/adc.h:320
#define ADC_CFGR1_DISCNUM_SHIFT
#define ADC_ISR_AWD3
#define ADC_CCR_DUAL_MASK
Definition: f3/adc.h:535
#define ADC_CCR_DUAL_SHIFT
Definition: f3/adc.h:536
#define ADC_CFGR1_JDISCEN
#define ADC_JSQR_JEXTSEL_MASK
Definition: f3/adc.h:308
#define ADC_CR_ADVREGEN_ENABLE
ADVREGEN: ADC voltage regulator enable.
Definition: f3/adc.h:208
#define ADC_ISR_AWD2
#define ADC_OFR2_OFFSET2_EN
Definition: f3/adc.h:333
#define ADC_OFR3_OFFSET3_EN
Definition: f3/adc.h:346
#define ADC_IER_JEOCIE
#define ADC_CFGR1_EXTSEL_MASK
Definition: f3/adc.h:219
#define ADC_ISR_JEOS
#define ADC_JSQR_JEXTEN_MASK
Definition: f3/adc.h:288
#define ADC_CR_ADVREGEN_DISABLE
Definition: f3/adc.h:209
void adc_disable_automatic_injected_group_conversion(uint32_t adc)
ADC Disable Automatic Injected Conversions.
Definition: adc.c:234
void adc_set_watchdog_high_threshold(uint32_t adc, uint16_t threshold)
ADC Set Analog Watchdog Upper Threshold.
Definition: adc.c:416
void adc_enable_discontinuous_mode_injected(uint32_t adc)
ADC Enable Discontinuous Mode for Injected Conversions.
Definition: adc.c:193
void adc_disable_eos_interrupt(uint32_t adc)
ADC Disable Regular End-Of-Sequence Interrupt.
Definition: adc.c:386
void adc_disable_regulator(uint32_t adc)
Disable the ADC Voltage regulator You can disable the adc vreg when not in use to save power.
Definition: adc.c:723
void adc_disable_discontinuous_mode_regular(uint32_t adc)
ADC Disable Discontinuous Mode for Regular Conversions.
Definition: adc.c:177
void adc_enable_all_awd_interrupt(uint32_t adc)
ADC Enable Analog Watchdog Interrupt.
Definition: adc.c:346
void adc_enable_eos_interrupt(uint32_t adc)
ADC Enable Regular End-Of-Sequence Interrupt.
Definition: adc.c:374
void adc_start_conversion_injected(uint32_t adc)
ADC Software Triggered Conversion on Injected Channels.
Definition: adc.c:404
void adc_enable_discontinuous_mode_regular(uint32_t adc, uint8_t length)
ADC Enable Discontinuous Mode for Regular Conversions.
Definition: adc.c:161
void adc_disable_eoc_interrupt_injected(uint32_t adc)
ADC Disable Injected End-Of-Conversion Interrupt.
Definition: adc.c:309
void adc_set_injected_sequence(uint32_t adc, uint8_t length, uint8_t channel[])
ADC Set an Injected Channel Conversion Sequence.
Definition: adc.c:461
void adc_enable_analog_watchdog_on_all_channels(uint32_t adc)
ADC Enable Analog Watchdog for All Regular and/or Injected Channels.
Definition: adc.c:256
void adc_enable_external_trigger_regular(uint32_t adc, uint32_t trigger, uint32_t polarity)
ADC Enable an External Trigger for Regular Channels.
Definition: adc.c:626
void adc_disable_all_awd_interrupt(uint32_t adc)
ADC Disable Analog Watchdog Interrupt.
Definition: adc.c:360
void adc_enable_external_trigger_injected(uint32_t adc, uint32_t trigger, uint32_t polarity)
ADC Enable an External Trigger for Injected Channels.
Definition: adc.c:662
void adc_disable_external_trigger_injected(uint32_t adc)
ADC Disable an External Trigger for Injected Channels.
Definition: adc.c:679
void adc_enable_eos_interrupt_injected(uint32_t adc)
ADC Enable Injected End-Of-Sequence Interrupt.
Definition: adc.c:321
void adc_enable_automatic_injected_group_conversion(uint32_t adc)
ADC Enable Automatic Injected Conversions.
Definition: adc.c:221
void adc_set_clk_prescale(uint32_t adc, uint32_t prescale)
ADC Set Clock Prescale.
Definition: adc.c:585
void adc_set_multi_mode(uint32_t adc, uint32_t mode)
ADC set multi mode.
Definition: adc.c:605
void adc_enable_regulator(uint32_t adc)
Enable the ADC Voltage regulator Before any use of the ADC, the ADC Voltage regulator must be enabled...
Definition: adc.c:711
bool adc_awd(uint32_t adc)
ADC Read the Analog Watchdog Flag.
Definition: adc.c:696
void adc_enable_eoc_interrupt_injected(uint32_t adc)
ADC Enable Injected End-Of-Conversion Interrupt.
Definition: adc.c:297
void adc_enable_analog_watchdog_injected(uint32_t adc)
ADC Enable Analog Watchdog for Injected Conversions.
Definition: adc.c:130
uint32_t adc_read_injected(uint32_t adc, uint8_t reg)
ADC Read from an Injected Conversion Result Register.
Definition: adc.c:526
void adc_disable_eos_interrupt_injected(uint32_t adc)
ADC Disable Injected End-Of-Sequence Interrupt.
Definition: adc.c:333
void adc_set_injected_offset(uint32_t adc, uint8_t reg, uint32_t offset)
ADC Set the Injected Channel Data Offset.
Definition: adc.c:554
void adc_enable_analog_watchdog_on_selected_channel(uint32_t adc, uint8_t channel)
ADC Enable Analog Watchdog for a Selected Channel.
Definition: adc.c:280
void adc_disable_analog_watchdog_injected(uint32_t adc)
ADC Disable Analog Watchdog for Injected Conversions.
Definition: adc.c:142
void adc_enable_analog_watchdog_regular(uint32_t adc)
ADC Enable Analog Watchdog for Regular Conversions.
Definition: adc.c:99
bool adc_eoc_injected(uint32_t adc)
ADC Read the End-of-Conversion Flag for Injected Conversion.
Definition: adc.c:491
void adc_set_watchdog_low_threshold(uint32_t adc, uint16_t threshold)
ADC Set Analog Watchdog Lower Threshold.
Definition: adc.c:434
bool adc_eos_injected(uint32_t adc)
ADC Read the End-of-Sequence Flag for Injected Conversions.
Definition: adc.c:506
void adc_disable_external_trigger_regular(uint32_t adc)
ADC Disable an External Trigger for Regular Channels.
Definition: adc.c:643
void adc_disable_discontinuous_mode_injected(uint32_t adc)
ADC Disable Discontinuous Mode for Injected Conversions.
Definition: adc.c:205
void adc_disable_analog_watchdog_regular(uint32_t adc)
ADC Enable Analog Watchdog for Regular Conversions.
Definition: adc.c:114
#define ADC_IER_AWD1IE
AWD1IE: Analog watchdog 1 interrupt enable.
Definition: adc_common_v2.h:90
#define ADC_IER_EOSIE
EOSIE: End of regular sequence of conversions interrupt enable.
Definition: adc_common_v2.h:94
#define ADC_ISR_AWD1
AWD1: Analog watchdog 1 flag.
Definition: adc_common_v2.h:70
#define ADC_TR3(adc)
#define ADC_CR(adc)
Control Register.
Definition: adc_common_v2.h:46
#define ADC_ISR(adc)
ADC interrupt and status register.
Definition: adc_common_v2.h:42
#define ADC_CCR(adc)
Common Configuration register.
Definition: adc_common_v2.h:60
#define ADC_JDR3(adc)
#define ADC_IER(adc)
Interrupt Enable Register.
Definition: adc_common_v2.h:44
#define ADC_OFR1(adc)
#define ADC_JDR4(adc)
#define ADC_JDR1(adc)
#define ADC_OFR4(adc)
#define ADC_JSQR(adc)
#define ADC_OFR3(adc)
#define ADC_JDR2(adc)
#define ADC_OFR2(adc)
#define ADC_TR2(adc)
#define ADC_CFGR1(adc)
Configuration Register 1.
Definition: adc_common_v2.h:48
#define ADC_TR1(adc)
Watchdog Threshold Register 1.
Definition: adc_common_v2.h:54