Created
April 20, 2010 01:36
-
-
Save cagerton/371905 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//MOSI: | |
#define DATAOUT 11 | |
//MISO: (not used, but part of builtin SPI) | |
#define DATAIN 12 | |
#define SPICLOCK 13 | |
#define SLAVESELECT 10 | |
#define LDAC 8 | |
void setup() { | |
byte clr; | |
pinMode(LDAC, OUTPUT); | |
pinMode(DATAOUT, OUTPUT); | |
pinMode(DATAIN, INPUT); | |
pinMode(SPICLOCK,OUTPUT); | |
pinMode(SLAVESELECT,OUTPUT); | |
digitalWrite(SLAVESELECT,HIGH); //disable device | |
SPCR = (1<<SPE)|(1<<MSTR); // SPI-Control = SPi-Enable, MaSTeR | |
clr=SPSR; // read reg twice | |
clr=SPDR; | |
delay(10); | |
} | |
void write_values(uint16_t samplex, uint16_t sampley) | |
{ | |
uint8_t dacSPI0 = 0; | |
uint8_t dacSPI1 = 0; | |
dacSPI0 = (samplex >> 8) & 0x00FF; // data bits 15-12. | |
dacSPI0 |= dacSPI0 |= B00110000;; | |
dacSPI1 = samplex & 0x00FF; // data | |
digitalWrite(SLAVESELECT,LOW); | |
SPDR = dacSPI0; // Start the transmission | |
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission | |
{ | |
}; | |
SPDR = dacSPI1; | |
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission | |
{ | |
}; | |
digitalWrite(LDAC, LOW); | |
digitalWrite(LDAC, HIGH); | |
digitalWrite(SLAVESELECT,HIGH); | |
dacSPI0 = 0; | |
dacSPI1 = 0; | |
dacSPI0 = (sampley >> 8) & 0x00FF; // data bits 15-12. | |
dacSPI0 |= B10110000; | |
dacSPI1 = sampley & 0x00FF; // data | |
digitalWrite(SLAVESELECT,LOW); | |
SPDR = dacSPI0; // Start the transmission | |
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission | |
{ | |
}; | |
SPDR = dacSPI1; | |
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission | |
{ | |
}; | |
digitalWrite(SLAVESELECT,HIGH); | |
} | |
void loop(){ | |
//... | |
} |
Author
cagerton
commented
Apr 20, 2010
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment