Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UITDSP_ADDA_Example2
Diff: DAC_MCP4921.hpp
- Revision:
- 1:e997f4e94491
- Parent:
- 0:46d099dfd9d6
--- a/DAC_MCP4921.hpp Sat Mar 14 06:49:49 2015 +0000
+++ b/DAC_MCP4921.hpp Mon Mar 16 23:59:49 2015 +0000
@@ -1,29 +1,28 @@
-//------------------------------------------------------
-// Class for single DAC in MCP4921 -- Header
-// Fast version
+//--------------------------------------------------------------
+// Class for DAC MCP4921 -- Header
+// This class can be also used for MCP4922 (only channel A)
//
-// Default pin assign
+// Default pin assign
// D11 SPI Master Out Slave In
// D13 SPI Serial Clock
-// D10 SPI Slave Select ----------------------- TIM4
+// D10 SPI Slave Select
// D12 to MCP4921 LDAC pin
// D9 clock for Switched-capacitor filter ---- TIM3
//
-// Argument cs in constructor must be output of TIM4,
-// i.e. D10(PB_6), PB_7, D15(PB_8), or D14(PB_9)
+// Argument "cs" in constructor can be used for any pin
+// corresponding to DigitalOut class in mbed
//
-// Argument pin in function ScfClockTim3() can be
-// PA_6(D12), PB_4(D5), PC_6, PB_5(D4), PC_7(D9),
-// PC_8, or PC_9
+// Argument "pin" in member function ScfClockTim3() can be set
+// PA_6(D12), PB_4(D5), PC_6, PB_5(D4), PC_7(D9),
+// PC_8, or PC_9
//
-// 2015/02/02, Copyright (c) 2015 MIKAMI, Naoki
-//------------------------------------------------------
+// 2015/01/31, Copyright (c) 2015 MIKAMI, Naoki
+//--------------------------------------------------------------
#ifndef DAC_MCP4921_HPP
#define DAC_MCP4921_HPP
#include "mbed.h"
-#include "tim4_slaveSelect.hpp"
namespace Mikami
{
@@ -42,7 +41,6 @@
{
if (value < -1.0f) value = -1.0f;
if (value > 1.0f) value = 1.0f;
-
WriteDac((uint16_t)((value + 1.0f)*2047));
}
@@ -60,27 +58,27 @@
// Check busy
bool IsBusy()
- { return (mySpi_->SR & SPI_SR_BSY) == SPI_SR_BSY; }
+ { return (mySpi_->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY; }
// Little wait
void Wait()
- { __NOP(); __NOP(); __NOP(); }
-
+ { __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); }
+
// Set clock for switched-capacitor filter
void ScfClockTim3(uint32_t clock, PinName pin = D9);
protected:
- void SlaveSelect() { ss_->SlaveSelect(); }
+ void SlaveSelect() { *cs_ = 0; }
void WriteSpi(uint16_t value) { mySpi_->DR = value; }
private:
SPI spi_; // SPI object of mbed
- Tim4_ss* ss_;
DigitalOut ld_; // for LDAC
+ static DigitalOut* cs_;
// Pointer of I2C
- SPI_TypeDef* mySpi_;
-
+ static SPI_TypeDef* mySpi_;
+
// for inhibition of copy constructor
DAC_MCP4921(const DAC_MCP4921&);
// for inhibition of substitute operator
@@ -93,6 +91,14 @@
SlaveSelect();
WriteSpi(value | 0x3000);
}
+
+ // ISR for RXNE interrupt of SPI
+ static void Isr()
+ {
+ *cs_ = 1;
+ uint16_t value = mySpi_->DR; // Clear RXNE
+ }
};
}
#endif // DAC_MCP4921_HPP
+