Library for MCP4822 SPI 12-bit DAC, both outputs supported, nLDAC connected to GND.

Dependents:   MCP4822_2aLerche

MCP4822.h

Committer:
Lerche
Date:
2011-01-21
Revision:
2:eb2c8b6c0b42
Parent:
0:014a10a4fed1
Child:
3:3d1178177669

File content as of revision 2:eb2c8b6c0b42:

/* MCP4822 library 
 * Copyright (c) 2008-2010, Lerche
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "mbed.h"

#ifndef MCP4822_H
#define MCP4822_H

/* Class: MCP4822
 *  Abstraction for a SPI DAC
 */ 
 
 namespace mbed {
class MCP4822 {

public:
     /* Constructor: MCP4822
      *  Create an instance of the MCP4822 connected to specfied SPI pins.
      * 
      * Variables: 
      *  @param SCK - The SPI clock pin 
      *  @param SDO - The SPI Data out pin 
      *  @param /CS - The ChipSelect pin 
      */ 
    MCP4822 (PinName mosi, PinName sclk, PinName ncs);
     /* Function: write to A-output 
      *  Write to the A-output, max 4095 (0xFFF) with 1 mV steps
      * 
      * Variables: 
      *  @param ValueA The value to be written
      */ 
    void writeA (int ValueA);
     /* Function: write to B-output 
      *  Write to the B-output, max 4095 (0xFFF) with 1 mV steps
      * 
      * Variables: 
      *  @param ValueB The valkue to be written
      */ 
    void writeB (int ValueB);
    
    private :    
        SPI _spi;
        DigitalOut _ncs;
        void _init();
  };
}
#endif