0

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?

bodangly
  • 2,473
  • 17
  • 28
  • The diagram looks different from most of the SPI interface I encountered, but I think the data you need to send should be 16-bits wide, so you might need `SPI_DATASIZE_16BIT`. If you want to read from register 0x10, you might need to send 0x2000, 0x0 as Read bit, 0x10 as register size, with the data bits ignored, as one 16-bit frame, and subsequently use a 16-bit array of size 1 to receive the data. If you used a logic analyzer to scope out the SPI signals, and it turns out that you are receiving the correct data but is not parsed correctly by the STM32, check `CPOL` and `CPHA`. – Cimory Jun 23 '21 at 08:41

2 Answers2

0

It says bit 15 must be set for a read. You have it clear. Try:

uint8_t tx[2] = { 0xA0, 0x00 };
Tom V
  • 4,827
  • 2
  • 5
  • 22
0

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.

bodangly
  • 2,473
  • 17
  • 28