Class library for internal ADC and DAC connected by SPI. This library support clock generator using TIM3 for switched-capacitor filter to smooth output signal of DAC. This library includes derivative class to support interrupt occured in end of AD conversion. Validated for ST Nucleo F401RE, F411RE. 内蔵 ADC と,SPI 接続の DAC のためのクラスライブラリ.DAC の出力信号を平滑化するためのスイッチトキャパシタフィルタ用のクロックは TIM3 を使用.ST Nucleo F401RE,F411RE で動作を確認.
Dependents: UITDSP_ADDA_Example UIT2_MovingAv_Intr UIT2_VariableFIR UIT2_VowelSynthesizer ... more
Diff: DAC_MCP4921.cpp
- Revision:
- 4:03c4518de836
- Parent:
- 0:2cdd5c91d975
- Child:
- 6:9deca4a06c8c
diff -r bb97069248de -r 03c4518de836 DAC_MCP4921.cpp --- a/DAC_MCP4921.cpp Fri Mar 13 05:59:56 2015 +0000 +++ b/DAC_MCP4921.cpp Mon Mar 16 23:59:24 2015 +0000 @@ -1,17 +1,17 @@ -//-------------------------------------------------------------- -// Class for DAC MCP4921 +//------------------------------------------------------ +// Class for single DAC in MCP4921 // -// 2015/02/18, Copyright (c) 2015 MIKAMI, Naoki -//-------------------------------------------------------------- +// 2015/02/02, Copyright (c) 2015 MIKAMI, Naoki +//------------------------------------------------------ -#include "InterruptManager.h" #include "DAC_MCP4921.hpp" namespace Mikami { DAC_MCP4921::DAC_MCP4921(PinName mosi, PinName sclk, PinName cs, PinName ldac) - : spi_(mosi, NC, sclk), ld_(ldac, 0) + : spi_(mosi, NC, sclk), + ld_(ldac, 0), mySpi_((SPI_TypeDef*)NULL) { if ( (mosi == PA_7) || (mosi == PB_5) ) mySpi_ = SPI1; if ( (mosi == PB_15) || (mosi == PC_3) ) mySpi_ = SPI2; @@ -27,16 +27,10 @@ mySpi_->CR1 += SPI_CR1_BR_0; #endif // __STM32F411xE_H - cs_ = new DigitalOut(cs, 1); - - mySpi_->CR2 |= SPI_CR2_RXNEIE; // Enable SPI RX buffer not empty interrupt - - IRQn_Type irq = SPI1_IRQn; - if (mySpi_ == SPI2) irq = SPI2_IRQn; - if (mySpi_ == SPI3) irq = SPI3_IRQn; - - NVIC_SetVector(irq, (uint32_t)Isr); // See "cmsis_nvic.h" - NVIC_EnableIRQ(irq); // See "core_cm4.h" + // timer prescaler is set same value of boud rate for SPI + uint16_t psc = (2 << ((mySpi_->CR1 >> 3) & 0x07)) - 1; + if (mySpi_ != SPI1) psc = (psc + 1)*2 - 1; + ss_ = new Tim4_ss(psc, 19, cs); } void DAC_MCP4921::ScfClockTim3(uint32_t clock, PinName pin) @@ -44,7 +38,7 @@ if ( (pin != PA_6) && (pin != PB_4) && (pin != PB_5) && (pin != PC_6) && (pin != PC_7) && (pin != PC_8) && (pin != PC_9) ) { - fprintf(stderr, "\r\nIllegal pin name in DAC_MCP4922::ScfClockTim3()\r\n"); + fprintf(stderr, "\r\nIllegal pin name in DAC_MCP4921::ScfClockTim3()\r\n"); while (true) {} } @@ -62,8 +56,4 @@ if (pin == PC_9) TIM3->CCR4 = (TIM3->ARR + 1)/2; } - - DigitalOut* DAC_MCP4921::cs_; - SPI_TypeDef* DAC_MCP4921::mySpi_; } -