Hi PaulS,
Thanks for your reply and the suggestions. In order to figure out what you were talking about exactly , I've looked at the arduino library tutorial (
http://arduino.cc/it/Hacking/LibraryTutorial) and a library that has a begin() call (the built in wire.cpp and wire.h).
In the tutorial, pinMode is called in the constructor but I followed you suggestion and changed the code inside mcp4822.cpp to
--
MCP4822::MCP4822(int csPin, int ldacPin)
{
// Configure chip select and latch pins
cs = csPin;
ldac = ldacPin;
}
//---------------------------------------------------------------------------
void MCP4822::begin()
{
pinMode(cs,OUTPUT);
pinMode(ldac,OUTPUT);
digitalWrite(cs,HIGH);
digitalWrite(ldac,HIGH);
// Set to default configuration
setGain2X_AB();
}
In mcp4822.h, I added
public:
void begin
and in Keyword.txt I added "begin" as a "KEYWORD2".
after saving the files, I restart Arduino 1.0, open the setValue_AB example sketch and add MCP4822.begin(); after the SPI.begin() call in setup().
I'm clearly doing something wrong, the result on compiling is the following error message:
In file included from set_value_AB.cpp:2:
/Users/Arduino Sketches/libraries/mcp4822/mcp4822.h:25: error: variable or field 'begin' declared void
/Users/Arduino Sketches/libraries/mcp4822/mcp4822.h:26: error: expected ';' before 'void'
I've been looking for missing curly brackets or semicolons, but can't see what I should change now.
Secondly, you were asking
Have you tried adding code to explicitly set the CS pin? A lot of libraries now do this automatically.
I don't know what you mean by explicitly setting the CS pin. I have tried using the same pins for other SPI stuff under IDE 1.0 (e.g. using the SD library) and that works fine.