Library for build-in ADC and DAC in STM32F446 mounted on Nucleo F446RE. Nucleo F446RE に搭載されている STM32F446 の内蔵 ADC, DAC 用のライブラリ.
Dependents: Demo_F446_AD_DA F446_MySoundMachine F446_ADF_Nlms F446_Spectrogram
F446_ADC_Interrupt.hpp@0:c945b4fe9a48, 2016-11-11 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Fri Nov 11 06:28:48 2016 +0000
- Revision:
- 0:c945b4fe9a48
- Child:
- 1:6b9f2af6613d
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:c945b4fe9a48 | 1 | //---------------------------------------------------------- |
MikamiUitOpen | 0:c945b4fe9a48 | 2 | // Simultanuous AD Conversion by interrupt using |
MikamiUitOpen | 0:c945b4fe9a48 | 3 | // ADC2 and ADC3 on STM32F446 ---- Header |
MikamiUitOpen | 0:c945b4fe9a48 | 4 | // |
MikamiUitOpen | 0:c945b4fe9a48 | 5 | // STM32F446 の ADC2, ADC3 を使って同時に AD 変換を開始し, |
MikamiUitOpen | 0:c945b4fe9a48 | 6 | // 割り込みによりアナログ信号を入力するクラス(ヘッダ) |
MikamiUitOpen | 0:c945b4fe9a48 | 7 | // AdcDual クラスの派生クラス |
MikamiUitOpen | 0:c945b4fe9a48 | 8 | // |
MikamiUitOpen | 0:c945b4fe9a48 | 9 | // 2016/11/11, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:c945b4fe9a48 | 10 | //---------------------------------------------------------- |
MikamiUitOpen | 0:c945b4fe9a48 | 11 | |
MikamiUitOpen | 0:c945b4fe9a48 | 12 | #ifndef F446_ADC_DUAL_INTERRUPT_HPP |
MikamiUitOpen | 0:c945b4fe9a48 | 13 | #define F446_ADC_DUAL_INTERRUPT_HPP |
MikamiUitOpen | 0:c945b4fe9a48 | 14 | |
MikamiUitOpen | 0:c945b4fe9a48 | 15 | #include "F446_ADC.hpp" |
MikamiUitOpen | 0:c945b4fe9a48 | 16 | |
MikamiUitOpen | 0:c945b4fe9a48 | 17 | namespace Mikami |
MikamiUitOpen | 0:c945b4fe9a48 | 18 | { |
MikamiUitOpen | 0:c945b4fe9a48 | 19 | class AdcDual_Intr : public AdcDual |
MikamiUitOpen | 0:c945b4fe9a48 | 20 | { |
MikamiUitOpen | 0:c945b4fe9a48 | 21 | public: |
MikamiUitOpen | 0:c945b4fe9a48 | 22 | AdcDual_Intr(int frequency) : AdcDual(frequency) |
MikamiUitOpen | 0:c945b4fe9a48 | 23 | { ADC2->CR1 |= ADC_CR1_EOCIE; } |
MikamiUitOpen | 0:c945b4fe9a48 | 24 | |
MikamiUitOpen | 0:c945b4fe9a48 | 25 | // -1.0f <= data1, data2 <= 1.0f |
MikamiUitOpen | 0:c945b4fe9a48 | 26 | virtual void Read(float &ad2, float &ad1) |
MikamiUitOpen | 0:c945b4fe9a48 | 27 | { |
MikamiUitOpen | 0:c945b4fe9a48 | 28 | ad1 = ToFloat(ADC2->DR); |
MikamiUitOpen | 0:c945b4fe9a48 | 29 | ad2 = ToFloat(ADC3->DR); |
MikamiUitOpen | 0:c945b4fe9a48 | 30 | } |
MikamiUitOpen | 0:c945b4fe9a48 | 31 | |
MikamiUitOpen | 0:c945b4fe9a48 | 32 | // 0 <= data1, data2 <= 4095 |
MikamiUitOpen | 0:c945b4fe9a48 | 33 | virtual void Read(uint16_t &ad2, uint16_t &ad1) |
MikamiUitOpen | 0:c945b4fe9a48 | 34 | { |
MikamiUitOpen | 0:c945b4fe9a48 | 35 | ad1 = ADC2->DR; |
MikamiUitOpen | 0:c945b4fe9a48 | 36 | ad2 = ADC3->DR; |
MikamiUitOpen | 0:c945b4fe9a48 | 37 | } |
MikamiUitOpen | 0:c945b4fe9a48 | 38 | |
MikamiUitOpen | 0:c945b4fe9a48 | 39 | // Set interrupt vector and enable IRQ of ADC |
MikamiUitOpen | 0:c945b4fe9a48 | 40 | void SetIntrVec(void (*Func)()) |
MikamiUitOpen | 0:c945b4fe9a48 | 41 | { |
MikamiUitOpen | 0:c945b4fe9a48 | 42 | NVIC_SetVector(ADC_IRQn, (uint32_t)Func); // See "cmsis_nvic.h" |
MikamiUitOpen | 0:c945b4fe9a48 | 43 | NVIC_EnableIRQ(ADC_IRQn); // See "core_cm4.h" |
MikamiUitOpen | 0:c945b4fe9a48 | 44 | } |
MikamiUitOpen | 0:c945b4fe9a48 | 45 | |
MikamiUitOpen | 0:c945b4fe9a48 | 46 | void DisableAdcIntr() |
MikamiUitOpen | 0:c945b4fe9a48 | 47 | { NVIC_DisableIRQ(ADC_IRQn); } |
MikamiUitOpen | 0:c945b4fe9a48 | 48 | |
MikamiUitOpen | 0:c945b4fe9a48 | 49 | private: |
MikamiUitOpen | 0:c945b4fe9a48 | 50 | // for inhibition of copy constructor |
MikamiUitOpen | 0:c945b4fe9a48 | 51 | AdcDual_Intr(const AdcDual_Intr&); |
MikamiUitOpen | 0:c945b4fe9a48 | 52 | // for inhibition of substitute operator |
MikamiUitOpen | 0:c945b4fe9a48 | 53 | AdcDual_Intr& operator=(const AdcDual_Intr&); |
MikamiUitOpen | 0:c945b4fe9a48 | 54 | }; |
MikamiUitOpen | 0:c945b4fe9a48 | 55 | } |
MikamiUitOpen | 0:c945b4fe9a48 | 56 | #endif // F446_ADC_DUAL_INTERRUPT_HPP |