Part Number: ADS131M08
Tool/software:
I'm using an STM32L4P5 Discovery kit to read the default values of the registers from the ADS131M08. When I introduce a minimum delay of 4ms between the SPI transmit and receive, I successfully get the expected default value. Without this delay, I receive an incorrect value.
For example, when reading the ID register:
- Without delay:
id = 0x0007 - With 4ms delay:
id = 0x2801
why this delay is necessary and how to potentially eliminate it?
SPI Parameter settings:
SPI mode = MODE 1 (CPOL = 0 , CPHA = 1)
SCK = 3MHz
uint16_t ads131m08_rreg (uint8_t addr) {
// 24 bits word length
uint8_t cmd[3];
uint8_t res[3]; // response
uint16_t read_cmd = OPCODE_RREG | (addr << 7);
cmd[0] = read_cmd >> 8;
cmd[1] = (uint8_t) read_cmd & 0x00FF;
cmd[2] = 0x00; // zero padding to match 24 bits word length
/*chip select*/
HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_RESET);
if (HAL_SPI_Transmit_DMA(&hspi2, cmd, 3) != HAL_OK) {
// Handle error
HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_SET);
return 0;
}
HAL_Delay(4); // Delay required to get the response
// Wait for the transmit to complete
while (HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY) {
// Do nothing, just wait
}
if (HAL_SPI_Receive_DMA(&hspi2, res, 3) != HAL_OK) {
// Handle error
HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_SET);
return 0;
}
// Wait for the receive to complete
while (HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY) {
// Do nothing, just wait
}
HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_SET);
uint16_t ret = ((uint16_t) res[0] << 8) | res[1];
return ret;
}
- Srihari