Parts: I2C Audio Volume Potentiometer (DS1807)

ds1807ii

The DS1807 contains two logarithmic digital potentiometers (pots) for audio volume adjustment. Each pot has 64 volume levels plus a mute setting. The volume level of each pot is set over a two-wire I2C serial interface. We’ll show you how to connect and interface the DS1807 below.

DS1807 I2C audio volume potentiometer (Digikey #DS1807+-ND, $3.04)

Connections

Bus Pirate DS1807 (pin #)
GND GND (1)
GND A2 (2)
GND A1 (3)
GND A0 (4)
GND AGND (11)
SDA SDA (12)
Clock SCL (13)
+5volts VCC (14)

We connected the DS1807 to the Bus Pirate universal serial interface tool as shown in the table, the same basic principals apply to any custom configuration. We used the Bus Pirate’s 5volt power supply, but the DS1807 will also work at 3.3volts. I2C requires a pull-up resistor on each signal line, we used the Bus Pirate’s on-board resistors connected to the on-board 5volt power supply.

Connect the DS1807 to an audio source as shown on page 3 of the datasheet. Connect the raw audio signal to the H pin and connect the L pin to ground, the attenuated audio signal will come from the W pin.

Interfacing

First, setup the Bus Pirate for I2C mode, and activate the 5volt power supply. We covered this procedure in our last parts post.

I2C>v<–voltage monitor
9xx VOLTAGE MONITOR: 5V: 4.9 | 3.3V: 0.0 | VPULLUP: 5.0 |
I2C>

With the power supply configured, check the voltage monitor (v) to be sure the 5volt supply is active and that 5volts is present at the pull-up resistors.

I2C>(0)<–list available macros
0.Macro menu
1.7bit address search
I2C>(1)<–run address search
xxx Searching 7bit I2C address space.
Found devices at:
0x50 0x51 0x52<–potential addresses
I2C>

The Bus Pirate’s address search macro is a quick way to locate I2C devices without looking at the datasheet. 0x50 is an I2C write address because the last bit is 0, 0x51 is read address (last bit 1). 0x52 is probably a group/global write address because it doesn’t have a corresponding read address.

We could also determine the address from the datasheet: the base address is 0101 plus the three address select bits (A0-2, all grounded, 000) and the write or read bit (0 or 1) gives 0b01010000 (0x50).

I2C>[0x51 r r]<–read pot values
210 I2C START CONDITION
220 I2C WRITE: 0x51 GOT ACK: YES <–device read address
230 I2C READ: 0x3F<–pot0
230 I2C READ: 0x3F<–pot1
240 I2C STOP CONDITION
I2C>

First, we read the potentiometer values at startup. [ issues the I2C start condition, 0x51 is the device read address, “r r” reads two bytes, and ] issues the I2C stop command. The default startup value is 63 (0x3f), one position above mute (datasheet page 2).

I2C>[0x50 0b10101001 0]<–write pot0
210 I2C START CONDITION
220 I2C WRITE: 0x50 GOT ACK: YES<–DS1807 write address
220 I2C WRITE: 0xA9 GOT ACK: YES<–pot0 write command
220 I2C WRITE: 0x00 GOT ACK: YES<–volume to set
240 I2C STOP CONDITION
I2C>[0x50 0b10101010 64]<–write pot1
210 I2C START CONDITION
220 I2C WRITE: 0x50 GOT ACK: YES<–DS1807 write address
220 I2C WRITE: 0xAA GOT ACK: YES<–pot1 write command
220 I2C WRITE: 0x40 GOT ACK: YES<–volume to set
240 I2C STOP CONDITION
I2C>[0x51 r r]<–read values back to verify
210 I2C START CONDITION
220 I2C WRITE: 0x51 GOT ACK: YES<–DS1807 read address
230 I2C READ: 0x00<–pot0 value
230 I2C READ: 0x40<–pot1 value
240 I2C STOP CONDITION
I2C>

Next, we update each volume pot with a separate command. 0x50 is the DS1807 write address, 0b10101001 (0xA9) is the command to update pot0, and 0 sets the volume to full. The next sequence uses the update pot1 command, 0b10101010 (0xaa), and sets the volume to mute (64, 0x40). Finally, we use the read procedure to verify that the values are correct.

I2C>[0x50 0xA9 64 0]<–write both pot values
210 I2C START CONDITION
220 I2C WRITE: 0x50 GOT ACK: YES
220 I2C WRITE: 0xA9 GOT ACK: YES<–update pot0 command
220 I2C WRITE: 0x40 GOT ACK: YES<–pot0 value
220 I2C WRITE: 0x00 GOT ACK: YES<–pot1 value
240 I2C STOP CONDITION
I2C>[0x51 r r]<–read back values
210 I2C START CONDITION
220 I2C WRITE: 0x51 GOT ACK: YES
230 I2C READ: 0x40<–pot0 value
230 I2C READ: 0x00<–pot1 value
240 I2C STOP CONDITION
I2C>

The pot 0 write command can also be used to set both potentiometer values with a single command. Use the pot0 update command (0b10101001, 0xA9), and  send the pot1 value (0) following the pot0 value (64).

I2C>[0x50 0b10101111 0x20]<–update both pots with the same value
210 I2C START CONDITION
220 I2C WRITE: 0x50 GOT ACK: YES
220 I2C WRITE: 0xAF GOT ACK: YES<–dual update command
220 I2C WRITE: 0x20 GOT ACK: YES<–value to set
240 I2C STOP CONDITION
I2C>[0x51 r r]<–read back values
210 I2C START CONDITION
220 I2C WRITE: 0x51 GOT ACK: YES
230 I2C READ: 0x20<–pot0 value
230 I2C READ: 0x20<–pot1 value
240 I2C STOP CONDITION
I2C>

Finally, 0xAF (0b10101111) can be used to update both potentiometers with the same value. This is probably the most useful command for stereo audio volume control where both channels have the same value and change simultaneously.

Are there any chips or components you’d like us to cover in future parts posts?

7 thoughts on “Parts: I2C Audio Volume Potentiometer (DS1807)

  1. 0x50 as address is wrong and should be 0x28.
    When connecting A0-2 to GND and scanning the i2c address I get 0x28.

    In the datasheet it says (p. 6):
    “(…) The control byte consists of a 4-bit control code. For the DS1807, this is set as 0101 binary for read/write
    operations. The next 3 bits of the control byte are the device select bits (A2, A1, and A0). They are used
    by the master device to select which of eight devices are to be accessed. The select bits are in effect the
    three least significant bits of the slave address. The last bit of the control byte (R/W) defines the operation
    to be performed. (…)”

    The text is very vague… riddle-style, but says this:
    0 | 0101 | A0 A1 A2
    read/write operation | control code … | … directly followed by address bits (least significant bits)

    –> 00101000 = 0x28

    was this code ever tested, or why did it seem to work?

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.