5 years, 8 months ago.

Communicating with an SPI DAC

I'm trying to interface the TLV5616 with an mbed via SPI.

The connections I've made are as follows:

Note: mbed is powered from same 5V supply.

https://i.stack.imgur.com/duiLJ.png

I modified the mbed SPI helloworld prorgam: <<code>>

  1. include "mbed.h"

SPI spi(p5, p6, p7); mosi, miso, sclk DigitalOut cs(p8);

int main() {

uint16_t fixed = 0x4000; uint16_t value = 1000;

uint16_t final = value << 2; final = fixed ^ value; cs = 1;

spi.format(16,3); spi.frequency(1000000);

Select the device by seting chip select low cs = 0;

Send 0x8f, the command to read the WHOAMI register spi.write(final);

Deselect the device cs = 1;

}

<</code>

The first 4 bits (from the left) should be 0100, and the last 2 bit, 00. The 10-bit value goes in between. This is explained in the datasheet (http://www.tij.co.jp/jp/lit/ds/symlink/tlv5616.pdf).

I've used the bit pattern 0x4000, and XOR'd it with the 10-bit value, which is shifted by two. This should result in a bit pattern accepted by the DAC.

However, when measuring the DAC output, the value tends to stay around 200mv, sometimes going under, which leads me to believe something is not quite working. With a value of 1000, you would expect a value closer to 3.3v (REF).

I should mention that I haven't used a capacitor in this circuit, although I don't think it's necessary to test the basic functionality.

Any thoughts on what's going wrong?

1 Answer

5 years, 8 months ago.

Please check your <<code>> and <</code>> tags. They should be on separate lines.

The problem is that you dont actually use the shifted value of 1000.

The 'final' variable should be computed as

...
uint16_t final = value << 2; 
final = fixed | final ;
....

Note that it is also better to use 'or' rather than 'xor' in this case.