The MCP4922 is a 12 bit DAC. This library should provide easy access to its basic functionality.

Dependencies:   DAC

Committer:
JimmyTheHack
Date:
Wed Jul 04 01:29:05 2012 +0000
Revision:
0:4e1ee1c4d3bb
updated SPI_DAC library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JimmyTheHack 0:4e1ee1c4d3bb 1 #ifndef DAC_SPI_CPP
JimmyTheHack 0:4e1ee1c4d3bb 2 #define DAC_SPI_CPP
JimmyTheHack 0:4e1ee1c4d3bb 3
JimmyTheHack 0:4e1ee1c4d3bb 4 #include "DAC_SPI.h"
JimmyTheHack 0:4e1ee1c4d3bb 5 /*SPI Channels */
JimmyTheHack 0:4e1ee1c4d3bb 6 //since we only have two SPI channels, which must be shared, define them here.
JimmyTheHack 0:4e1ee1c4d3bb 7 SPI SPI_A(p5, NC, p7); //If using with other serial devices, can pass a pointer to the serial channel.
JimmyTheHack 0:4e1ee1c4d3bb 8 SPI SPI_B(p11, NC, p13);
JimmyTheHack 0:4e1ee1c4d3bb 9
JimmyTheHack 0:4e1ee1c4d3bb 10 /*Initialize DAC */
JimmyTheHack 0:4e1ee1c4d3bb 11 DAC_SPI::DAC_SPI(int SPIchannelNum, PinName _CS, PinName _LDAC) : CS(_CS), LDAC(_LDAC){
JimmyTheHack 0:4e1ee1c4d3bb 12 if (SPIchannelNum ==1){
JimmyTheHack 0:4e1ee1c4d3bb 13 DACspi = &SPI_B;
JimmyTheHack 0:4e1ee1c4d3bb 14 }
JimmyTheHack 0:4e1ee1c4d3bb 15 else{
JimmyTheHack 0:4e1ee1c4d3bb 16 DACspi = &SPI_A;
JimmyTheHack 0:4e1ee1c4d3bb 17 }
JimmyTheHack 0:4e1ee1c4d3bb 18 messageBits(16);
JimmyTheHack 0:4e1ee1c4d3bb 19 }
JimmyTheHack 0:4e1ee1c4d3bb 20
JimmyTheHack 0:4e1ee1c4d3bb 21 /** Manually change the SPI frequency
JimmyTheHack 0:4e1ee1c4d3bb 22 * Must be a value supported by the mbed and DAC
JimmyTheHack 0:4e1ee1c4d3bb 23 */
JimmyTheHack 0:4e1ee1c4d3bb 24 void DAC_SPI::frequency(int freq){
JimmyTheHack 0:4e1ee1c4d3bb 25 (*DACspi).frequency(freq);
JimmyTheHack 0:4e1ee1c4d3bb 26 }
JimmyTheHack 0:4e1ee1c4d3bb 27
JimmyTheHack 0:4e1ee1c4d3bb 28
JimmyTheHack 0:4e1ee1c4d3bb 29 //specify the number of bits used in message packets to the DAC.
JimmyTheHack 0:4e1ee1c4d3bb 30 void DAC_SPI::messageBits(int bits){
JimmyTheHack 0:4e1ee1c4d3bb 31 (*DACspi).format(bits,0);
JimmyTheHack 0:4e1ee1c4d3bb 32 }
JimmyTheHack 0:4e1ee1c4d3bb 33
JimmyTheHack 0:4e1ee1c4d3bb 34 //select a DACnum for use with chips with multiple onboard DACs.
JimmyTheHack 0:4e1ee1c4d3bb 35 void DAC_SPI::select(char DACnum){
JimmyTheHack 0:4e1ee1c4d3bb 36 DACselect=DACnum;
JimmyTheHack 0:4e1ee1c4d3bb 37 }
JimmyTheHack 0:4e1ee1c4d3bb 38
JimmyTheHack 0:4e1ee1c4d3bb 39 #endif //DAC_SPI_CPP