I’m trying to read an impedance value with ADPD4000 connected to stm32L4, but I have two problems with the reading of the fifo buffer and the execution of the code.
- About the fifo, I don’t why it does not fill or it fills up with no sense value. I attached a photo with the values that adc returns

- To run the code without problems, I had to insert a delay step between every function. If I don't do this the code doesn't run or it runs badly. For example, if I do not insert the delay before adi_adpdssm_getFifoLvl(), the data available in the FIFO returns zero.
I followed the example code which is on the official repository. Here is my configuration..
//ADPD4000 Impedance measurement
{0x0009U, 0x0094U}, // 32MHz trim
{0x000BU, 0x02EAU}, // 1MHz trim
{0x000DU, 0x0D05U}, // Sampling rate, 0D05 for 300 Hz, 2710 for 100Hz, 09C4 for 400 Hz
{0x000FU, 0x0006U}, // 1MHz osc
//{0x000FU, 0x0001U}, // 32kHz osc
//enable timeslot A and set idle mode
{0x0010U, 0x0000U}, // Timeslot enable, 0100 Timeslots AB, 0000 Timeslots A
{0x0020U, 0x0002U}, // Float input 3&4, 5&6, 7&8 during sleep
{0x0021U, 0x0068U}, // IN7/IN8 configured as a differential pair (IN5-IN6 single ended). VC2 set to AVDD during sleep
{0x0022U, 0x0003U},// gpio0 out inverted,
{0x0023U, 0x0002}, // gpio0 interruput x (pin cgf0 configured as output)
{0x0014U, 0x8000U}, // fifo to int x (enable interrupt of x)
{0x0006U, 0x0010U}, // FIFO interrupt generation threshold. Generate FIFO interrupt during a FIFO write when the number of bytes in the FIFO exceeds this valuee. The FIFO is 256 bytes
// Slots config
//////Timeslot A Impedance measurement on IN5 //////
////// IN5 as single-ended input //////
{0x0100U, 0x0000U}, // CH2 disabled, input resistor 500 ohms
{0x0101U, 0x41DAU}, // Full AFE, TIA+BPF+INT+ADC
//{0x0101U, 0x40E6U}, //TIA, integrator, and ADC.
//enable IN6
{0x0102U, 0x0300U}, // IN6 to CH1, IN5 disabled. R11=100Kohm is used like a reference for impedence measurements.
{0x0103U, 0x5A45U}, // PRECON TO Vref, alternate VC2 on each subsequent Time Slot x vref to vdel (TIA_Vref+250mV)
{0x0104U, 0xE209U}, // 100K GAIN both channels, vref=.9
{0x0105U, 0x0000U}, // LEDs off
{0x0106U, 0x0000U},// LEDs off
{0x0107U, 0x0110U}, // 16 PULSE 1 INT
{0x0108U, 0x0014U}, // 50 kHz pulse train, continuous TIA connection
{0x010AU, 0x0003U}, // INT Width
{0x010BU, 0x180FU}, // INT timing offset, 15.75us
//{0x010CU, 0x100FU}, // MOD pulse width and offset
{0x010CU, 0x0310U}, //Mod pulse width 3us, mod offset 16us
{0x010DU, 0x0099}, // CHOP
{0x010EU, 0x0000U}, // OFFSET
{0x010FU, 0x0000U}, // OFFSET
{0x0110U, 0x0003U},// 3 BYTES SIG Number of bytes of signal data to be written to the FIFO for Time Slot x. Selectable between 0 bytes and four bytes.
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <adi_adpd_driver.h>
#include "adi_adpd_ssm.h"
#include "adi_adpd_reg.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi2;
UART_HandleTypeDef huart2;
/* USER CODE BEGIN PV */
tAdiAdpdDcfgInst dcfg_ADPD4000[28] ={
//ADPD4000 Impedance measurement
{0x0009U, 0x0094U}, // 32MHz trim
{0x000BU, 0x02EAU}, // 1MHz trim
{0x000DU, 0x0D05U}, // Sampling rate, 0D05 for 300 Hz, 2710 for 100Hz, 09C4 for 400 Hz
{0x000FU, 0x0006U}, // 1MHz osc
//{0x000FU, 0x0001U}, // 32kHz osc
///*il primo bit abilita l'oscillatore a 32, il secondo a 1M, il terzo selezione il low frequency oscillator*/
//abilito solo il timeslot A e setto il standby la modalità
{0x0010U, 0x0000U}, // Timeslot enable, 0100 Timeslots AB, 0000 Timeslots A
{0x0020U, 0x0002U}, // Float input 3&4, 5&6, 7&8 during sleep
{0x0021U, 0x0068U}, // IN7/IN8 configured as a differential pair (IN5-IN6 single ended). VC2 set to AVDD during sleep
//{0x0022U, 0x0403U}, // gpio0 out inverted, gpio3 output normal
{0x0022U, 0x0003U},
{0x0023U, 0x0002}, // gpio0 interruput x (pin cgf0 configured as output)
{0x0014U, 0x8000U}, // fifo to int x (enable interrupt of x)
{0x0006U, 0x0010U}, //aggiunto io.FIFO interrupt generation threshold. Generate FIFO interrupt during a
//FIFO write when the number of bytes in the FIFO exceeds this valuee. The FIFO is 256 bytes
// Slots config
//////Timeslot A Impedance measurement on IN5 //////
////// IN5 as single-ended input //////
{0x0100U, 0x0000U}, // CH2 disabled, input resistor 500 ohms
{0x0101U, 0x41DAU}, // Full AFE, TIA+BPF+INT+ADC
//{0x0101U, 0x40E6U}, //TIA, integrator, and ADC.
//il registro 0x0102 si riferische ai canali attivi sulla board
{0x0102U, 0x0300U}, // IN6 to CH1, IN5 disabled. R11=100Kohm is used like a reference for impedence measurements.
//{0x0103U, 0x5A2CU}, // PRECON TO Vref, pulse VC2 vref to vdel (TIA_Vref+250mV)
//{0x0103U, 0x5B05U},
{0x0103U, 0x5A45U}, // PRECON TO Vref, alternate VC2 on each subsequent Time Slot x vref to vdel (TIA_Vref+250mV)
{0x0104U, 0xE209U}, // 100K GAIN both channels, vref=.9
{0x0105U, 0x0000U}, // LEDs off
{0x0106U, 0x0000U},// LEDs off
{0x0107U, 0x0110U}, // 16 PULSE 1 INT
{0x0108U, 0x0014U}, // 50 kHz pulse train, continuous TIA connection
{0x010AU, 0x0003U}, // INT Width
{0x010BU, 0x180FU}, // INT timing offset, 15.75us
//{0x010CU, 0x100FU}, // MOD pulse width and offset
{0x010CU, 0x0310U}, //Mod pulse width 3us, mod offset 16us
{0x010DU, 0x0099}, // CHOP
{0x010EU, 0x0000U}, // OFFSET
{0x010FU, 0x0000U}, // OFFSET
{0x0110U, 0x0003U},// 3 BYTES SIG Number of bytes of signal data to be written to the FIFO for Time Slot x.
// Selectable between 0 bytes and four bytes.
//{0x0110U, 0x0004U},// 4 BYTES SIG
{0xFFFF, 0xFFFF}, //terminator
};
static tAdiAdpdSSmInst oAdiAppInst;
static uint8_t aFifoDataBuf[MAX_SAMPLES_IN_FIFO];
static uint16_t dev_id; uint16_t o_dri_res, res;
static uint8_t tx_buffer[1000];
static int command=0, kk=0;
static uint8_t gnAdpdDataReady = 0;
uint32_t gnAdpdTimeCurVal = 0;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI2_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */
static void tx_com( uint8_t *tx_buffer, uint16_t len );
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SPI2_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
uint32_t adpd_ch1 = 0U;
uint16_t loop = 0U;
static uint32_t tick = 0U;
/*Switch pin definition*/
//HAL_GPIO_WritePin(GPIOG, GPIO_PIN_0, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_14, GPIO_PIN_SET);
/*set CS pin */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET);
uint16_t nRetVal;
uint16_t nRegValue = 0U;
uint16_t nAdpdFifoLevelSize;
ADI_ADPD_COMM_MODE bus_mode;
while(dev_id!=0x00C0)
{
o_dri_res=adi_adpddrv_OpenDriver();
dev_id= adi_adpddrv_GetDevId();
}
sprintf((char *)tx_buffer, "Adi board recognized!\n\r");
tx_com(tx_buffer, strlen((char const *)tx_buffer));
bus_mode = adi_adpddrv_GetComMode();
if (bus_mode != E_ADI_ADPD_SPI_BUS)
{while(1);}
HAL_Delay(100);
/*load the config file. I had to add a verify control to be sure about the writing registers*/
if (adi_adpdssm_loadDcfg(dcfg_ADPD4000, 0xFFU) != ADI_ADPD_SSM_SUCCESS)
{
while(1);
}
sprintf((char *)tx_buffer, "Adress configuration done!\n\r");
tx_com(tx_buffer, strlen((char const *)tx_buffer));
HAL_Delay(100);
/*The function save configuration for each slot (12 slot) */
adi_adpdssm_slotinit(&oAdiAppInst);
HAL_Delay(10);
if (adi_adpdssm_setOperationMode(E_ADI_ADPD_MODE_SAMPLE) != ADI_ADPD_DRV_SUCCESS)
{
while(1);
}
nRetVal=adi_adpddrv_RegRead(ADPD4x_REG_INT_STATUS_FIFO, &nRegValue);
sprintf((char *)tx_buffer, "Set Operation Mode done!\n\r");
tx_com(tx_buffer, strlen((char const *)tx_buffer));
HAL_Delay(10);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
if (gnAdpdDataReady){
gnAdpdDataReady=0;
uint32_t nRetValue = 0U;
// Not using ADPD400x auto clear int flag -> need to clear
adi_adpddrv_RegWrite(ADPD4x_REG_INT_STATUS_DATA, 0x8000);
/* Read the size of the data available in the FIFO */
//nAdpdFifoLevelSize indicates
HAL_Delay(5);
nRetValue = adi_adpdssm_getFifoLvl(&nAdpdFifoLevelSize);
if (nRetValue != ADI_ADPD_DRV_SUCCESS)
{
while(1);
};
//nRetVal=adi_adpddrv_RegRead(ADPD4x_REG_FIFO_DATA, &nRegValue);
/* Read the fifo data available in the FIFO */
HAL_Delay(5);
nRetValue = adi_adpddrv_ReadFifoData(nAdpdFifoLevelSize, &aFifoDataBuf[0]);
if(nRetValue!=ADI_ADPD_DRV_SUCCESS)
{
while(1);
};
//nRetVal=adi_adpddrv_RegRead(ADPD4x_REG_FIFO_DATA, &nRegValue);
tick=0;
loop = 0U;
adpd_ch1 = 0U;
/* Read the data from the FIFO and print them */
while (nAdpdFifoLevelSize != 0U) {
/* Byte swapping is needed to print ADPD data in proper format */
adpd_ch1 = ((aFifoDataBuf[loop] << 8) + (aFifoDataBuf[loop + 1]) +(aFifoDataBuf[loop + 2] << 24) + (aFifoDataBuf[loop + 3] << 16));
sprintf((char *)tx_buffer,
"%u,%u\r\n", tick, adpd_ch1);
tx_com(tx_buffer, strlen((char const *)tx_buffer));
if(nAdpdFifoLevelSize>=oAdiAppInst.oAdpdSlotInst.nTotalSlotSz)
{
nAdpdFifoLevelSize -= oAdiAppInst.oAdpdSlotInst.nTotalSlotSz;
loop += oAdiAppInst.oAdpdSlotInst.nTotalSlotSz;
tick += 1;
}
else
nAdpdFifoLevelSize = 0U;
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
Error_Handler();
}
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief SPI2 Initialization Function
* @param None
* @retval None
*/
static void MX_SPI2_Init(void)
{
/* USER CODE BEGIN SPI2_Init 0 */
/* USER CODE END SPI2_Init 0 */
/* USER CODE BEGIN SPI2_Init 1 */
/* USER CODE END SPI2_Init 1 */
/* SPI2 parameter configuration*/
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 7;
hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI2_Init 2 */
/* USER CODE END SPI2_Init 2 */
}
/**
* @brief USART2 Initialization Function
* @param None
* @retval None
*/
static void MX_USART2_UART_Init(void)
{
/* USER CODE BEGIN USART2_Init 0 */
/* USER CODE END USART2_Init 0 */
/* USER CODE BEGIN USART2_Init 1 */
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
HAL_PWREx_EnableVddIO2();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_14, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
/*Configure GPIO pin : PG9 */
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
/*Configure GPIO pin : PF14 */
GPIO_InitStruct.Pin = GPIO_PIN_14;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
/*Configure GPIO pin : PB13 */
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
}
/* USER CODE BEGIN 4 */
static void tx_com(uint8_t *tx_buffer, uint16_t len)
{
HAL_UART_Transmit(&huart2, tx_buffer, len, 5000);
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
//gnAdpdTimeCurVal=HAL_GetTick();
if(GPIO_Pin==GPIO_PIN_9)
{
gnAdpdDataReady=1;
//adi_adpddrv_ISR(gnAdpdTimeCurVal);
}
/* Prevent unused argument(s) compilation warning */
UNUSED(GPIO_Pin);
/* NOTE: This function should not be modified, when the callback is needed,
the HAL_GPIO_EXTI_Callback could be implemented in the user file
*/
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
Edit Notes
I attached also the main code[edited by: Gloi at 8:23 AM (GMT -5) on 15 Feb 2021]
