Hi! ich versuche einen Arduino mit einem ADS1248EVM-Board via SPI kommunizieren zu lassen... Es soll am ADU eine Spannung bis maximal 2 Volt angelegt werden, die dann vom Arduino via Serial Monitor angezeigt werden soll... Allerdings stimmt der angezeigte Wert mit dem angelegten nicht überein... kleine Übersicht: Eingangsspannung Angezeigte im Serial Monitor 0V 0.00V (in-Wert 700) 0,102V 3,31V (in-Wert 15662300) 0,501V 2,38V (in-Wert 11280500) 0,999V 1,23V (in-Wert 5815200) 1,504V 0,06V (in-Wert 280300) 2,003V 2,45V (in-Wert 11583000) 2,498V 1,30V (in-Wert 6167400) 2,996V 0,16V (in-Wert 748400) Wie man schon sieht, kann ich sogar 3V an den Eingang legen, obwohl ich die interne Referenzspannung von 2,048V verwende... Und, wie man erkennt, ist ein Sprung drin... Bis ca. 0-1,55V zählt der ADU den in-Wert bis 16777216 (24 Bit) 0 herunter und beginnt wieder bei 1677216 und bei 3,06V ist er wieder bei 0... Hier mein Code: /* ADS1248EVM <----------> Arduino 1: /CS <- to digital pin 10 (SS pin) 11: MOSI <- to digital pin 11 (MOSI pin) 13: MISO -> to digital pin 12 (MISO pin) 3: SCLK <- to digital pin 13 (SCK pin) 6: RST <- to digital pin 9 (RESET) 4+10+18 - ground */ #include <SPI.h> // include the SPI library // set I/O pins used in addition to clock, data in, data out const byte slaveSelectPin = 10; // digital pin 10 for /CS const byte resetPin = 9; // digital pin 9 for /RESET const int nsamples = 5; // how many ADC readings to average together // SPI_CLOCK_DIV16 gives me a 1.0 MHz SPI clock, with 16 MHz crystal on Arduino void setup() { Serial.begin(9600); // set up serial comm to PC at this baud rate pinMode (slaveSelectPin, OUTPUT); pinMode (resetPin, OUTPUT); digitalWrite(slaveSelectPin,HIGH); // chip select is active low digitalWrite(resetPin,HIGH); // reset is active low SPI.begin(); // initialize SPI, covering MOSI,MISO,SCK signals SPI.setBitOrder(MSBFIRST); // data is clocked in MSB first SPI.setDataMode(SPI_MODE0); // SCLK idle low (CPOL=0), MOSI read on rising edge (CPHI=0) SPI.setClockDivider(SPI_CLOCK_DIV16); // system clock = 16 MHz, chip max = 1 MHz Serial.println("ADS1248 Test"); } // ======================================================================== ===== // Main Loop: void loop() { int i; float volts; long in; // incoming serial 32-bit word long sum = 0; for (i=0; i<nsamples; i++) { in = SpiRead(); in &= 0x1FFFFFFF; // force high three bits to zero in = in>>5; // truncate lowest 5 bits delay(198); // (msec). Total Looptime: +2 mse Serial.println(in); } volts = in * (0.0000002112); // = in * (2,048 / 16777216) // VRef und 24-Bit-Auflösung Serial.println(volts); } // end main loop // ================================================================= // SpiRead() -- read out 4 bytes from ADS1248 chip via SPI interface // ================================================================= long SpiRead(void) { long result = 0; long b; // long result2 = 0;// MOSI/SDI pin 7 HIGH => 7 Hz, best resolution digitalWrite(slaveSelectPin,LOW); // take the SS pin low to select the chip delayMicroseconds(1); // probably not needed, only need 25 nsec delay b = SPI.transfer(0xff); // B3 result = b<<8; b = SPI.transfer(0xff); // B2 result |= b; result = result<<8; b = SPI.transfer(0xff); // B1 result |= b; result = result<<8; b = SPI.transfer(0xff); // B0 result |= b; // take the SS pin high to de-select the chip: digitalWrite(slaveSelectPin,HIGH); return(result); } Hat jemand ne Ahnung, woran es liegen könnte???
Der ADS1248 liefert nur 3 Byte Daten, die SPI Lesefunktion liesst 4 Bytes. Außerdem sehe ich keinerlei Initialisierung des ADCs in dem Code.
ah, ok... initialisiert wird der ADC doch in der eingefügten SPI-library... ich probier es mal zu ändern... danke! :)
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.