Skip to content

Instantly share code, notes, and snippets.

@silbo
Last active January 15, 2016 18:42
Show Gist options
  • Save silbo/67a2c1a5ffaea83c38da to your computer and use it in GitHub Desktop.
Save silbo/67a2c1a5ffaea83c38da to your computer and use it in GitHub Desktop.
AD7173 test
/*
====================
AD7173 ADC test code
====================
*/
#include <SPI.h>
void print_byte(byte value) {
char format[10];
sprintf(format, "0x%.2X ", value);
Serial.print(format);
}
void setup() {
/* initiate serial communication */
Serial.begin(115200);
/* initiate ADC, returns true if the device ID is valid */
SPI.begin();
//SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE3);
//SPI.setClockDivider(SPI_CLOCK_DIV4);
digitalWrite(SS, HIGH);
delay(10);
digitalWrite(SS, LOW);
for (int i = 0; i < 10; i++) {
byte value[2];
digitalWrite(SS, LOW);
//SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3));
SPI.transfer(0x00);
SPI.transfer(0x47);
value[0] = SPI.transfer(0x00);
value[1] = SPI.transfer(0x00);
//SPI.endTransaction();
digitalWrite(SS, HIGH);
print_byte(value[0]);
print_byte(value[1]);
Serial.println();
}
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment