Library for MCP4822 SPI 12-bit DAC, both outputs supported, nLDAC connected to GND.
MCP4822.h@11:96eff565b2c0, 2011-01-31 (annotated)
- Committer:
- Lerche
- Date:
- Mon Jan 31 07:22:18 2011 +0000
- Revision:
- 11:96eff565b2c0
- Parent:
- 10:d1edaa2e2905
Added .shdn() command, and write(channel, value) command
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Lerche | 0:014a10a4fed1 | 1 | /* MCP4822 library |
Lerche | 0:014a10a4fed1 | 2 | * Copyright (c) 2008-2010, Lerche |
Lerche | 0:014a10a4fed1 | 3 | * |
Lerche | 0:014a10a4fed1 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
Lerche | 0:014a10a4fed1 | 5 | * of this software and associated documentation files (the "Software"), to deal |
Lerche | 0:014a10a4fed1 | 6 | * in the Software without restriction, including without limitation the rights |
Lerche | 0:014a10a4fed1 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Lerche | 0:014a10a4fed1 | 8 | * copies of the Software, and to permit persons to whom the Software is |
Lerche | 0:014a10a4fed1 | 9 | * furnished to do so, subject to the following conditions: |
Lerche | 0:014a10a4fed1 | 10 | * |
Lerche | 0:014a10a4fed1 | 11 | * The above copyright notice and this permission notice shall be included in |
Lerche | 0:014a10a4fed1 | 12 | * all copies or substantial portions of the Software. |
Lerche | 0:014a10a4fed1 | 13 | * |
Lerche | 0:014a10a4fed1 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Lerche | 0:014a10a4fed1 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Lerche | 0:014a10a4fed1 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Lerche | 0:014a10a4fed1 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Lerche | 0:014a10a4fed1 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Lerche | 0:014a10a4fed1 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Lerche | 0:014a10a4fed1 | 20 | * THE SOFTWARE. |
Lerche | 0:014a10a4fed1 | 21 | */ |
Lerche | 0:014a10a4fed1 | 22 | |
Lerche | 0:014a10a4fed1 | 23 | #include "mbed.h" |
Lerche | 0:014a10a4fed1 | 24 | |
Lerche | 5:c4acc07d6998 | 25 | #ifndef MCP4822_H |
Lerche | 5:c4acc07d6998 | 26 | #define MCP4822_H |
Lerche | 8:4adf01cb9dd2 | 27 | |
Lerche | 8:4adf01cb9dd2 | 28 | /** Interface to a 12-bit SPI dual-output DAC */ |
Lerche | 0:014a10a4fed1 | 29 | class MCP4822 { |
Lerche | 0:014a10a4fed1 | 30 | public: |
Lerche | 5:c4acc07d6998 | 31 | /** Constructor: MCP4822 |
Lerche | 0:014a10a4fed1 | 32 | * |
Lerche | 10:d1edaa2e2905 | 33 | * @param MOSI - The SPI Data out pin |
Lerche | 10:d1edaa2e2905 | 34 | * @param SCLK - The SPI clock pin |
Lerche | 7:a89ef6c30783 | 35 | * @param /CS - The ChipSelect pin |
Lerche | 0:014a10a4fed1 | 36 | */ |
Lerche | 0:014a10a4fed1 | 37 | MCP4822 (PinName mosi, PinName sclk, PinName ncs); |
Lerche | 6:ac02ff2992fe | 38 | /** Write to the A-output, max 4095 (0xFFF) with 1 mV steps |
Lerche | 6:ac02ff2992fe | 39 | * |
Lerche | 7:a89ef6c30783 | 40 | * @param ValueA The value to be written |
Lerche | 0:014a10a4fed1 | 41 | */ |
Lerche | 0:014a10a4fed1 | 42 | void writeA (int ValueA); |
Lerche | 6:ac02ff2992fe | 43 | /** Write to the B-output, max 4095 (0xFFF) with 1 mV steps |
Lerche | 6:ac02ff2992fe | 44 | * |
Lerche | 7:a89ef6c30783 | 45 | * @param ValueB The valkue to be written |
Lerche | 0:014a10a4fed1 | 46 | */ |
Lerche | 0:014a10a4fed1 | 47 | void writeB (int ValueB); |
Lerche | 11:96eff565b2c0 | 48 | /** Write to any output, accoding to letter. |
Lerche | 11:96eff565b2c0 | 49 | * |
Lerche | 11:96eff565b2c0 | 50 | * |
Lerche | 11:96eff565b2c0 | 51 | */ |
Lerche | 11:96eff565b2c0 | 52 | void write(char chan, int value); |
Lerche | 11:96eff565b2c0 | 53 | /** Shutdown the output on specific channel |
Lerche | 11:96eff565b2c0 | 54 | * |
Lerche | 11:96eff565b2c0 | 55 | * |
Lerche | 11:96eff565b2c0 | 56 | */ |
Lerche | 11:96eff565b2c0 | 57 | void shdn(); |
Lerche | 0:014a10a4fed1 | 58 | |
Lerche | 0:014a10a4fed1 | 59 | private : |
Lerche | 0:014a10a4fed1 | 60 | SPI _spi; |
Lerche | 0:014a10a4fed1 | 61 | DigitalOut _ncs; |
Lerche | 0:014a10a4fed1 | 62 | void _init(); |
Lerche | 0:014a10a4fed1 | 63 | }; |
Lerche | 7:a89ef6c30783 | 64 | |
Lerche | 0:014a10a4fed1 | 65 | #endif |