Created
June 9, 2014 18:11
-
-
Save tashwoods/c052a585f8a4c3b2ec3e to your computer and use it in GitHub Desktop.
RW_VCO
This file contains 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
#include "mbed.h" | |
SPI spi(p5, p6, p7); // mosi, miso, sclk | |
DigitalOut cs(p8); | |
int main() { | |
// Chip must be deselected | |
cs = 1; | |
// Setup the spi for 8 bit data, high steady state clock, | |
// second edge capture, with a 1MHz clock rate | |
spi.format(8,1); | |
spi.frequency(1000000); | |
// Select the device by seting chip select low (inverted logic) | |
cs = 0; | |
// Send 0x00, 0x00, the command to read the WHOAMI register, bytes sent in "backwards" (LSB) order | |
spi.write(0x00);//data being written to AD5791 | |
spi.write(0x00);//data being written to AD5791 | |
spi.write(0x10);//data being written to AD 5791 and bits to specify that you are writing to AD5791 | |
// Send a dummy byte to receive the contents of the WHOAMI register, bytes sent in "backwards" (LSB) order | |
int whoami = spi.write(0x00); | |
int second = spi.write(0x00); | |
int third = spi.write(0x90); | |
printf("WHOAMI register = 0x%X ", whoami); | |
printf("second register = 0x%X ", second); | |
printf("third register = 0x%X ", third); | |
printf("I work.\n"); | |
// Deselect the device | |
cs = 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment