This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS8686SEVM-PDK: Trying to read registers from STM32 fails

Part Number: ADS8686SEVM-PDK
Other Parts Discussed in Thread: ADS8686S

I have some extremely simple code trying to read from the ADS8686S registers in SPI mode. I cannot get it to work, though I do believe I am following the timing diagram in 7.5.3.3 of the datasheet.

SPI configuration:


/* 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_LOW;
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;

Followed by a very simple function trying to read register 0x02 (excuse the hardcoded values please, haven't yet wrapped intlo a function as I cannot get this example to work):

uint8_t rx[8] = { 0x00 };

// Read register 0x02
uint8_t tx[2] = { 0x04, 0x00 };

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

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

// Receive register data
set_adc_cs(GPIO_PIN_RESET);
HAL_SPI_Receive(&hspi1, rx, 2, 1000);
set_adc_cs(GPIO_PIN_SET);

The result of this, is that I always read 0x00, 0xFF into rx. This does not match the reset value of the register. In fact, I ready the same 0x00, 0xFF for the first several registers. If I try and read device ID, register 0x10 (with tx[2] = { 0x20, 0x00 }), I read back all 0s. So my command is sort of received, but the result makes no sense. What can I be doing wrong with such a simple example?

  • I fixed the SPI configuration to be SPI mode 2:

    /* 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_256;
    hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
    hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
    hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
    hspi1.Init.CRCPolynomial = 10;

    I decided to focus on reading DEVICE_ID, and tweaked the read a bit:

    uint8_t rx[2] = { 0x00, 0x00 };
    uint8_t tx[2] = { 0x00, 0x00 };

    // Read register device id
    tx[0] = 0x20;

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

    tx[0] = 0x00;
    // 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);

    With this code, I get back {0x00, 0x02}, when I am expecting {0x20, 0x02}. I am unclear on what I am doing wrong still, but it does seem closer. Almost like I am missing a byte somehow. Any ideas, I am banging my head against a wall at this point it feels like?

  • Hi Jordan,

    I apologized for the late response and thanks for your update.

    The data (0x00 20) you read for Device_ID register is correct. The 0x20 you expected represents the register address 0x10, actually the register address will not be output on the SDO when the register is read. The reset value(0x2002) for the Device_ID register shown in the datasheet is incorrect and it should be updated to 0x0002. Also, the reset value for all registers in the ADS8686S datasheet should be updated. I hope this helps, thanks.

    Regards,

    Dale