Rajiv Tyagi
Newbie level 4
- Joined
- Jan 10, 2015
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 35
Digipot AD5293 is giving me a lot of trouble. Below is my code. I don't know why I can't get this to work or what I'm doing wrong. Can someone help, please?
On the oscilloscope I can see the MOSI changing values, SCK is present and stable, CS is correct. What am I doing wrong?
Rajiv
Code:
[syntax=cpp]
#include <SPI.h>
void setup(){
pinMode(10, OUTPUT); //CS
pinMode(11, OUTPUT); //MOSI
pinMode(12, INPUT); //MISO
pinMode(13, OUTPUT); //SCK
Serial.begin(115200);
writeCommand;
}
void loop(){
unsigned int val;
for (val = 0; val <= 1023; val++) {
writeDigipots(val);
//delay(10);
}
for (val = 1023; val > 0; val--) {
writeDigipots(val);
//delay(10);
}
}
void writeDigipots(unsigned int val){
SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV8, MSBFIRST, SPI_MODE1));
digitalWrite(10, LOW);
//SPI.transfer(0x18); //send command byte
//SPI.transfer(0x03);
byte highbyte = val >> 8 + 0x04; //high wiper byte + command
byte lowbyte = val & 0xFF;
SPI.transfer(highbyte); //send wiper data high byte
SPI.transfer(lowbyte); //send wiper data low byte
digitalWrite(10, HIGH);
SPI.endTransaction();
}
void writeCommand() {
SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV8, MSBFIRST, SPI_MODE1));
digitalWrite(10, LOW);
SPI.transfer(0x18); //send command high byte
SPI.transfer(0x03); //send command low byte
digitalWrite(10, HIGH);
SPI.endTransaction();
}
[/syntax]
On the oscilloscope I can see the MOSI changing values, SCK is present and stable, CS is correct. What am I doing wrong?
Rajiv