i use your unmodified original code from bottommost link on your webseite.
ADC.zip - on Mar 1, 2011 5:58 AM by jan (version 1)
Installed libraries as usual. Import library from Arduino IDE works OK,
Wally, try skipping the library and just control the SPI access directly. SPI access of the part is pretty simple.
// include the SPI library:
#include <SPI.h>
// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
// pins 11, 12, 13 are set up by SPI library
int result;
byte highByte;
byte lowByte;
void setup() {
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
Serial.begin (38400);
}
void loop(){
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin,LOW);
// wait 10uS for the conversion per the MAX187 data sheet
delayMicroseconds(10) ;
// read the top 8 bits
highByte = SPI.transfer(0x00);
// read the rest of the bits
lowByte = SPI.transfer(0x00);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin,HIGH);
// Done reading,manipulate the data
// shift the first byte left, then get the second byte:
result = highByte << 8;
// combine the byte you just got with the previous one:
result = result | lowByte;
// may have trailing zero's to get rid of - maybe like this? Confirm with real hardware.
result = result >>4;
// do something with the data now
Serial.println(result);
delay (1000); // don't start blasting out of the serial port yet!
}
"The MAX187/MAX189 serial interface is fully compatible with SPI, QSPI, and Microwire standard serial interfaces.
If a serial interface is available, set the CPU’s serial interface in master mode so the CPU generates the serial clock.
Choose a clock frequency up to 2.5MHz.
Use a general-purpose I/O line on the CPU to pull CS low. Keep SCLK low.
Wait the for the maximum conversion time specified before activating SCLK.
Alternatively, look for a DOUT rising edge to determine the end of conversion.
Activate SCLK for a minimum of 13 clock cycles. The first falling clock edge will produce the MSB of the
DOUT conversion. DOUT output data transitions on SCLK’s falling edge and is available in MSB-first format.
Observe the SCLK to DOUT valid timing characteristic.
Data can be clocked into the ?P on SCLK’s rising edge.
Pull CS high at or after the 13th falling clock edge. If CS remains low, trailing zeros are clocked out after
the LSB.
With CS = high, wait the minimum specified time, tCS, before launching a new conversion by pulling CS
low. If a conversion is aborted by pulling CS high before the conversions end, wait for the minimum
acquisition time, tACQ, before starting a new conversion.
Data can be output in 1-byte chunks or continuously, as shown in Figure 8. The bytes will contain the result of
the conversion padded with one leading 1, and trailing 0s if SCLK is still active with CS kept low."
thanks for your help.
All you explained works, but on the other hand i'm curious now , why Jans code gives this "not declared error". I checked adc.h, adc.cpp and the paths looks ok.
(arduino-0022/libraries/ADC/)
The line "MyADC myadc(MAX1272, 10); does not make any troubles.
Why it does not accept the function call inside the loop() ?
On the other hand, the read is just the 2 SPI transfers.
So often folks get all caught up in having libraries & classes & so on, when the real thing needed is hardlly any code at all and it can be written as your own little function in just a few minutes, and often needs some customzing anyway for the device being used.