stm32spitexas-instruments

Failing to read from an ADS8686S with an STM42F411


I am trying to read registers from an ADS8686S ADC from TI. It has the following timing diagram for register reads (from https://www.ti.com/lit/ds/symlink/ads8686s.pdf?ts=1624204868114&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FADS8686S): enter image description here

The device register is 0x10, with a supposed value of 0x2002.

I have the following SPI initialization:

static void MX_SPI1_Init(void)
{
    /* SPI1 parameter configuration*/
    hspi1.Instance = SPI1;
    hspi1.Init.Mode = SPI_MODE_MASTER;
    hspi1.Init.Direction = SPI_DIRECTION_2LINES;
    hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
    hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
    hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
    hspi1.Init.NSS = SPI_NSS_SOFT;
    hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
    hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
    hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
    hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
    hspi1.Init.CRCPolynomial = 10;
    if (HAL_SPI_Init(&hspi1) != HAL_OK)
    {
        Error_Handler();
    }
}

With the following snippet to read that register specifically:

// Read register device id (0x10 << 9) & 0xFF00
uint8_t tx[2] = { 0x20, 0x00 };
uint8_t rx[2] = { 0x00, 0x00 };

// Send read register command
set_adc_cs(GPIO_PIN_RESET);
HAL_SPI_TransmitReceive(&hspi1, tx, rx, 2, 1000);
set_adc_cs(GPIO_PIN_SET);

// Don't care
HAL_SPI_TransmitReceive(&hspi1, tx, rx, 2, 1000);

// Receive register result
set_adc_cs(GPIO_PIN_RESET);
HAL_SPI_TransmitReceive(&hspi1, tx, rx, 2, 1000);
set_adc_cs(GPIO_PIN_SET);

I read back rx as { 0x00, 0x02}. Almost like I am getting half the register. Just really unsure of the issue at this point, and have been smacking my head against the wall.

Is it my SPI settings, or am I misunderstanding something from the timing diagram?


Solution

  • My code was functioning perfectly fine. I got confirmation from TI that the reset values were not correct in the datasheet, as they included the address, which is not read back.