Sto tentando di realizzare una libreria per gestire un ADC.
In modo tale da creare un'istanza per ogni ADC collegato.
Nella compilazione nonostante tutto ho fatto l'include della SPI.h mi solleva l'errore
'SPI' was non declared in this scope.
Non capisco dove il problema (sicuramente una banalità)
/* codice preso da http://forum.arduino.cc/index.php?topic=57873.0 */
#include "Arduino.h"
#include "ADS1252.h"
#include <SPI.h>
ADS1252::ADS1252(int SCLK, int MISO)
{
SCLKPIN=SCLK;
MISOPIN=MISO;
pinMode(SCLKPIN, OUTPUT); pinMode(MISOPIN, INPUT);
// corresponding to SCK pin and DRDY/DOUT pin on ADC
}
void ADS1252::init()
{
resetADC();
// put ADC on reset at the outset
SPI.begin(); // riga dove viene generato l'errore
// initialize SPI (with default settings, including...
// CPOL = 0: so that SCLK is normally LOW
// CPHA = 0: data sampled on rising edge (LOW to HIGH)
// perhaps try changing CPHA ??
digitalWrite(SCLKPIN, LOW);
// release ADC from reset; now we're at a known point
// in the timing diagram, and just have to wait for
// the beginning of a conversion cycle
}
long ADS1252::readRaw()
{
if (digitalRead(MISOPIN) == HIGH) readADC();
return value;
}
float ADS1252::readVolt()
{
if (digitalRead(MISOPIN) == HIGH) readADC();
return value*3300/16777216;
}
void ADS1252::readADC()
{
drdyWait();
// go to drdy_wait routine, where we wait for
// DRDY phase to pass, and thus for DOUT phase to begin
byte1 = SPI.transfer(0x00);
byte2 = SPI.transfer(0x00);
byte3 = SPI.transfer(0x00);
value = ....
}
void ADS1252::resetADC()
// to reset ADC, we need SCLK HIGH for min of 4 CONVCYCLES
// so here, hold SCLK HIGH for 5 CONVCYCLEs = 1440 usec
{
digitalWrite(SCLKPIN, HIGH);
delayMicroseconds(1440);
}
void ADS1252::drdyWait()
// wait for DRDY to pass and to reach start-point of DOUT
{
delayMicroseconds(30);
// to be safe, 30 usec, instead of 27 usec, which is
// the expected period of DRDY phase
}