Hi guys,
Im new to arduino and to these sorts of things in general (meaning SPI etc). In fact, i just received my arduino the other day. I have to say, i am very happy with it so far.
Sorry to bug, though, but i need a little hand with an SPI pot i am working with.
The pot is an MCP42100, you can find a datasheet here: http://futurlec.com.au/SFMicrochip/MCP42100.jsp
I am sure that i had it working late last night, but when i got up this morning it wasn't working. How frustrating! So i was hoping somewhere here could tell me what i might be doing wrong. maybe i have made a silly mistake?
Thanks for your help!
Here is the Arduino code i am using (for 0007 version):
#define SLAVESELECT 10//ss
#define SPICLOCK 13//sck
#define DATAOUT 12//MOSI
#define DATAIN 11//MOSI
// command bytes
byte cmdWritePot1 = B00010001; // write data, to pot 1
byte cmdWritePot2 = B00010010; // write data, to pot 2
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
return SPDR; // return the received byte
}
// Setup Function Begins Here
void setup()
{
Serial.begin(9600);
byte i;
byte clr;
pinMode(DATAOUT,OUTPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(SLAVESELECT,OUTPUT);
digitalWrite(SLAVESELECT,HIGH); //disable device
SPCR = B01111000;
SPCR = (1<<SPE)|(1<<MSTR);
clr=SPSR;
clr=SPDR;
delay(10);
}
byte write_pots(int potValue11, int potValue12)
{
// spi pot chip 1
digitalWrite(SLAVESELECT,LOW); // enable chip 1
// set value for pot A
spi_transfer(cmdWritePot1); // command byte out to select pot and init write
spi_transfer(potValue11); // 8 bit pot value
// set value for pot B
spi_transfer(cmdWritePot2); // command byte out to select pot and init write
spi_transfer(potValue12); // 8 bit pot value
digitalWrite(SLAVESELECT,HIGH); // disable spi pot chip 1
}
// Main Loop Begins Here
void loop()
{
write_pots(255,0);
delay(100);
}
Here is a pic of my breadboard: