Basic libraries for functionality of the MCP4822 DAC, an easy to use DAC outputting up to 4.096V.

Dependencies:   DAC

Committer:
JimmyTheHack
Date:
Thu Jun 14 03:58:16 2012 +0000
Revision:
0:a10e8793cf0a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JimmyTheHack 0:a10e8793cf0a 1 #include "DAC_SPI.h"
JimmyTheHack 0:a10e8793cf0a 2
JimmyTheHack 0:a10e8793cf0a 3 /*SPI Channels */
JimmyTheHack 0:a10e8793cf0a 4 SPI SPI_A(p5, NC, p7); //since we only have two SPI channels, which must be shared, define them here.
JimmyTheHack 0:a10e8793cf0a 5 SPI SPI_B(p11, NC, p13);
JimmyTheHack 0:a10e8793cf0a 6
JimmyTheHack 0:a10e8793cf0a 7 /*Initialize DAC */
JimmyTheHack 0:a10e8793cf0a 8 DAC_SPI::DAC_SPI(int SPIchannelNum, PinName _CS, PinName _LDAC) : CS(_CS), LDAC(_LDAC){
JimmyTheHack 0:a10e8793cf0a 9 if (SPIchannelNum ==1){
JimmyTheHack 0:a10e8793cf0a 10 DACspi = &SPI_B;
JimmyTheHack 0:a10e8793cf0a 11 }
JimmyTheHack 0:a10e8793cf0a 12 else{
JimmyTheHack 0:a10e8793cf0a 13 DACspi = &SPI_A;
JimmyTheHack 0:a10e8793cf0a 14 }
JimmyTheHack 0:a10e8793cf0a 15 messageBits(16);
JimmyTheHack 0:a10e8793cf0a 16 }
JimmyTheHack 0:a10e8793cf0a 17
JimmyTheHack 0:a10e8793cf0a 18 /** Manually change the SPI frequency
JimmyTheHack 0:a10e8793cf0a 19 * Must be a value supported by the mbed and DAC
JimmyTheHack 0:a10e8793cf0a 20 */
JimmyTheHack 0:a10e8793cf0a 21 void DAC_SPI::frequency(int freq){
JimmyTheHack 0:a10e8793cf0a 22 (*DACspi).frequency(freq);
JimmyTheHack 0:a10e8793cf0a 23 }
JimmyTheHack 0:a10e8793cf0a 24
JimmyTheHack 0:a10e8793cf0a 25
JimmyTheHack 0:a10e8793cf0a 26 //specify the number of bits used in message packets to the DAC.
JimmyTheHack 0:a10e8793cf0a 27 void DAC_SPI::messageBits(int bits){
JimmyTheHack 0:a10e8793cf0a 28 (*DACspi).format(bits,0);
JimmyTheHack 0:a10e8793cf0a 29 }