I am trying to talk to an LT1257 using an Arduino Nano Atmega328. I am not using the default slave select pin. I am using pin 5 as chip select for the DAC. The LT1257 data sheet shows this timing diagram. What I inferred from this diagram is that SCLK can be used to clock in the data and it remains in the shift register and is loaded into the DAC register only when Load is pulled low. LT1257 timing diagram
I wrote this snippet to load a 0x0000 to the DAC. However, when I probe the output voltage it is ~1.02V. The DAC uses an internal reference of 2.048V. So I think this must be the default 1/2*FS output when the DAC powers on. Please review my code and point the errors. (At the DAC output I have a 1k resistor connected to ground).
#include<SPI.h>
#define SCLK 13
#define MISO 12
#define MOSI 11
#define DAC_LOAD 5
#define DAC_SPI_CLOCK_SPEED 1000000 //Upto 1.4MHz
void setup()
{
Serial.begin(9600);
init();
SPI.begin();
dac_write();
}
void init()
{
pinMode(SCLK, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(DAC_LOAD, OUTPUT);
digitalWrite(SCLK, HIGH);
digitalWrite(MOSI, HIGH);
digitalWrite(DAC_LOAD, HIGH);
}
void dac_write()
{
SPI.beginTransaction(SPISettings(DAC_SPI_CLOCK_SPEED, MSBFIRST, SPI_MODE0));
delay(10);
SPI.transfer(0x0000);
delay(10);
digitalWrite(DAC_LOAD, LOW);
delay(10);
digitalWrite(DAC_LOAD, HIGH);
delay(10);
SPI.endTransaction();
}
void loop()
{
while(1)
{
Serial.println("Ping!");
delay(1000);
}
}
-
Notice that SPI.transfer() transfers one byte (8 bits) only, not 12 as you'd want.JimmyB– JimmyB2017年02月19日 09:56:06 +00:00Commented Feb 19, 2017 at 9:56
-
I tried SPI.transfer16() too and that didn't work either.user1155386– user11553862017年02月19日 16:47:02 +00:00Commented Feb 19, 2017 at 16:47
-
Probably unrelated, but: From the diagram, the clock seems to be idle high => SPI mode 3. Also, what is MISO connected to? If nothing, use or enable a pull-up or -down on that input.JimmyB– JimmyB2017年02月20日 18:30:21 +00:00Commented Feb 20, 2017 at 18:30
-
Plus: Apparently !LOAD must be asserted during the last falling edge of the clock line, see t6 and t7. You'll have a hard time trying that with the hardware SPI. You probably have to go with software bit-banging.JimmyB– JimmyB2017年02月20日 18:34:28 +00:00Commented Feb 20, 2017 at 18:34
2 Answers 2
I read the LT1257 data-sheet more carefully. There is a pull down nmos at the output of the DAC. So when uninitialized, the output of LT1257 should be ~0V. So the output I was measuring (~1.02V) is spurious. I suspect I damaged the IC. I tried the same code on a different LT1257 and it worked. I can confirm now that this code is working.
For a master to select an SPI slave to transmit data to it [the slave], the Slave Select pin is held low.
-
Do you see any reference to the SS signal in the timing diagram?JimmyB– JimmyB2017年02月20日 18:35:46 +00:00Commented Feb 20, 2017 at 18:35
-
OK. The OP refered to an SPI device with slave select pin and I assumed a standard 4 wire SPI device. The datasheet refers to the protocol as '3 wire cascadable serial'. Anyway, here is description of an apparently successful attempt to interface an LT1257 to an Arduino link6v6gt– 6v6gt2017年02月20日 21:35:01 +00:00Commented Feb 20, 2017 at 21:35