Post Go back to editing

Proper SPI Write for 2 x Daisy Chained AD5207

Thread Summary

The user asked about the correct SPI data format for controlling two daisy-chained AD5207 digital potentiometer ICs. The final answer confirmed that adding 4 leading zeros to the 24-bit word, followed by the 10-bit data for each IC, is the correct approach. The user also encountered issues with an overly large capacitor on the daisy chain serial data line, which was clarified to be a parasitic trace capacitance, not an actual component, and should be kept below 20pF to avoid propagation delays.
AI Generated Content
Category: Software
Product Number: AD5207

Hi, I am working on a project using 2 daisy chained AD5207 digital potentiometer ICs controlled by the SPI interface of an STM32 micro. I'm following the directions given in the AD5207 datasheet, but I am a little confused about how to properly format the serial data, since the AD5207 wants 10 bits of Serial information, whereas any SPI port will write bits in multiples of 8, meaning there will be extra unused bits at the beginning or end. I can think of two ways this could be handled. One is treating each 10-bit packet as a 16-bit write, with 6 blank bits at the beginning or end. Another would be offsetting the two 10-bit packets within 3 8-bit writes, with 4 blank bits at the beginning or end. Please advise which method is correct. 

Here is the example code for each scenario. Which is correct?

static void ad5207_write_spi_dual(uint8_t pot, uint8_t val1, uint8_t val2) {

//pot selects pot channel a or b, val1 controls IC 1, val2 controls IC 2

#if 1

//4 8-bit writes, leading 0's

uint8_t spi_block[4] = { 0, 0, 0, 0 };

spi_block[0] = pot;

spi_block[1] = val2;

spi_block[2] = pot;

spi_block[3] = val1;

#elif 0

//4 8-bit writes, trailing 0's

uint8_t spi_block[4] = { 0, 0, 0, 0 };

spi_block[0] = (pot << 6) | (val2 >> 2);

spi_block[1] = (val2 << 6) & 255; 

spi_block[2] = (pot << 6) | (val1 >> 2);

spi_block[3] = (val1 << 6) & 255;

#elif 0

//3 8-bit writes, leading 0's

uint8_t spi_block[3] = { 0, 0, 0 };

spi_block[0] = (pot << 2) | (val2 >> 6);

spi_block[1] = pot | ((val2 << 2) & 255);

spi_block[2] = val1;

#else

//3 8 bit writes, trailing 0's

uint8_t spi_block[3] = { 0, 0, 0 };

spi_block[0] = (pot << 6) | (val2 >> 2);

spi_block[1] = (pot << 4) | ((val2 << 6) & 255) | (val1 >> 4);

spi_block[2] = (val1 << 4) & 255;

#endif

HAL_GPIO_WritePin(SPI1_SEL_GPIO_Port, SPI1_SEL_Pin, GPIO_PIN_RESET);

delay(1);

HAL_SPI_Transmit(&hspi1, (uint8_t*) spi_block, sizeof(spi_block), 5);

delay(1);

HAL_GPIO_WritePin(SPI1_SEL_GPIO_Port, SPI1_SEL_Pin, GPIO_PIN_SET);

delay(1);

}

On a further note, are there any common hardware issues that might lead to daisy chain behavior not working? 

More Content

Before You Switch


Switching languages will make ADI Explorer unavailable. Resume your session by switching back to English and reopening ADI Explorer.