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?