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?


