cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F765VIT6 and ADS131E08 code

Azer
Associate
Hello All, 


I hope you are all doing well !

I m writing to ask help, I have problem with my STM32f765vit6 and an  ADS131e08 .

My the ADS131E08 stops communicating over SPI in continuous mode after a few seconds and block the SPI communication again. But with a Hardware reset and During this,It works Fine but abnormal values are recorded, and the periode to read values is limited due to the hardware reset. 

Issue: The ADS131E08 stops communicating over SPI in continuous mode after a few seconds without a reset before blocking SPI communication. However, it operates in discontinuous mode with a hardware reset and delay. During this, either abnormal values are recorded, or it works continuously for approximately one hour .

Could anyone please provide insights or suggestions on resolving this issue where the device stops working in continuous mode? 
is there any chance to be a frequence configuration issue or is it a hardware issue ?

there any guidance to configure the clock correctly 

Any guidance on troubleshooting this behavior would be highly appreciated.


best regards,
Azer.

 

/**
 * @brief System Clock Configuration
 * @retval None
 */
void SystemClock_Config(void)
{
	RCC_OscInitTypeDef RCC_OscInitStruct = {0};
	RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

	/** Configure the main internal regulator output voltage
	 */
	__HAL_RCC_PWR_CLK_ENABLE();
	__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

	/** Initializes the RCC Oscillators according to the specified parameters
	 * in the RCC_OscInitTypeDef structure.
	 */

	RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
	RCC_OscInitStruct.HSIState = RCC_HSI_ON;
	RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
	RCC_OscInitStruct.LSIState = RCC_LSI_ON;
	RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
	RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
	RCC_OscInitStruct.PLL.PLLM = 8;
	RCC_OscInitStruct.PLL.PLLN = 216;
	RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
	RCC_OscInitStruct.PLL.PLLQ = 2;
	RCC_OscInitStruct.PLL.PLLR = 2;
	if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
	{
		Error_Handler();
	}

	/** Activate the Over-Drive mode
	 */
	if (HAL_PWREx_EnableOverDrive() != 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_PLLCLK;
	RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
	RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
	RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

	if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
	{
		Error_Handler();
	}
}


/**
 * @brief SPI1 Initialization Function
 * @PAram None
 * @retval None
 */
static void MX_SPI1_Init(void)
{

	/* USER CODE BEGIN SPI1_Init 0 */

	/* USER CODE END SPI1_Init 0 */

	/* USER CODE BEGIN SPI1_Init 1 */

	/* USER CODE END SPI1_Init 1 */
	/* SPI1 parameter configuration*/
	/* USER CODE END SPI1_Init 1 */
	/* 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_2EDGE;
	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 = 7;
	hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
	hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
	if (HAL_SPI_Init(&hspi1) != HAL_OK)
	{
		Error_Handler();
	}
	/* USER CODE BEGIN SPI1_Init 2 */

	/* USER CODE END SPI1_Init 2 */

	/* USER CODE BEGIN SPI1_Init 2 */

	/* USER CODE END SPI1_Init 2 */

}


HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{

	if(GPIO_Pin == GPIO_PIN_5)
	{
		ads13_read_data(channel_value);
	}
	else
	{
		__NOP();
	}
}


/**
 * @brief  TxRx Transfer completed callback.
 * @PAram  hspi: SPI handle
 * @note   This example shows a simple way to report end of DMA TxRx transfer, and
 *         you can add your own implementation.
 * @retval None
 */
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
{
	/* Check Rx data coming from SPI1 ? */
	if(hspi->Instance == SPI1)
	{
		//HAL_GPIO_WritePin(cs_pin_GPIO_Port, cs_pin_Pin, GPIO_PIN_SET);  // CS high
		is_data_ready = true ;

		// Convert received data
		for(int i = 0; i < 8; i++)
		{
			//int rawData = (int32_t)((rx_data[3 + i * 3] << 16) | (rx_data[4 + i * 3] << 😎 | rx_data[5 + i * 3]);

			// Reconstitution des données de 24 bits
			int32_t rawData = rx_data[3 + i * 3];
			rawData = (rawData << 😎 | rx_data[4 + i * 3];
			rawData = (rawData << 😎 | rx_data[5 + i * 3];

			// Si rawData est négatif en format 24 bits, étendre le signe à 32 bits
			if (rawData & 0x800000)
			{
				rawData |= 0xFF000000;
			}

			channel_value[i] = ads_convert_to_mVolt(rawData);
		}
	}
	else
	{
		/* SPI xxx */
	}
}


/**
 * @brief GPIO Initialization Function
 * @PAram None
 * @retval None
 */
static void MX_GPIO_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStruct = {0};
	/* USER CODE BEGIN MX_GPIO_Init_1 */
	/* USER CODE END MX_GPIO_Init_1 */

	/* GPIO Ports Clock Enable */
	__HAL_RCC_GPIOE_CLK_ENABLE();
	__HAL_RCC_GPIOH_CLK_ENABLE();
	__HAL_RCC_GPIOC_CLK_ENABLE();
	__HAL_RCC_GPIOA_CLK_ENABLE();
	__HAL_RCC_GPIOB_CLK_ENABLE();
	__HAL_RCC_GPIOD_CLK_ENABLE();

	//  /*Configure GPIO pin Output Level */
	//  HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_RESET);
	//
	//  /*Configure GPIO pin Output Level */
	//  HAL_GPIO_WritePin(GPIOB, SPI1_START_Pin|SPI1_PWRD_Pin, GPIO_PIN_RESET);
	/*Configure GPIO pin Output Level */
	HAL_GPIO_WritePin(cs_pin_GPIO_Port, cs_pin_Pin, GPIO_PIN_SET);
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);

	/*Configure GPIO pin Output Level */
	HAL_GPIO_WritePin(RST_PIN_GPIO_Port, RST_PIN_Pin, GPIO_PIN_SET);

	/*Configure GPIO pin Output Level */
	HAL_GPIO_WritePin(GPIOB, Start_Pin, GPIO_PIN_SET);
	HAL_GPIO_WritePin(GPIOB, Pwrd_Pin, GPIO_PIN_SET);

	/*Configure GPIO pin : cs_pin_Pin */
	GPIO_InitStruct.Pin = cs_pin_Pin;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(cs_pin_GPIO_Port, &GPIO_InitStruct);

	/*Configure GPIO pin : RST_PIN_Pin */
	GPIO_InitStruct.Pin = RST_PIN_Pin;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(RST_PIN_GPIO_Port, &GPIO_InitStruct);

	/*Configure GPIO pin : redy_Pin */
	GPIO_InitStruct.Pin = GPIO_PIN_5;
	GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

	/*Configure GPIO pins : Start_Pin Pwrd_Pin */
	GPIO_InitStruct.Pin = Start_Pin|Pwrd_Pin;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

	/*Configure GPIO pins : Start_Pin Pwrd_Pin */
	GPIO_InitStruct.Pin =  GPIO_PIN_12;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

	/* EXTI interrupt init*/
	HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
	HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);

	/*Configure GPIO pin Output Level */
	HAL_GPIO_WritePin(GPIOD, RS485_SLR2_Pin|IS2_EN_RS2_Pin|IS2_EN_RS3_Pin|RS485_TERM_2_Pin
			|RS485_SLR2D1_Pin|IS1_EN_RS2_Pin|IS1_EN_RS3_Pin|IS1_EN_RS4_Pin
			|RS485_TERM_1_Pin, GPIO_PIN_RESET);

	/*Configure GPIO pins : Adr_3_Pin Adr_4_Pin Adr_5_Pin Adr_6_Pin
                           Adr_1_Pin Adr_2_Pin */
	GPIO_InitStruct.Pin = Adr_3_Pin|Adr_4_Pin|Adr_5_Pin|Adr_6_Pin
			|Adr_1_Pin|Adr_2_Pin;
	GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

	/*Configure GPIO pins : RS485_SLR2_Pin IS2_EN_RS2_Pin IS2_EN_RS3_Pin RS485_TERM_2_Pin
                           RS485_SLR2D1_Pin IS1_EN_RS2_Pin IS1_EN_RS3_Pin IS1_EN_RS4_Pin
                           RS485_TERM_1_Pin */
	GPIO_InitStruct.Pin = RS485_SLR2_Pin|IS2_EN_RS2_Pin|IS2_EN_RS3_Pin|RS485_TERM_2_Pin
			|RS485_SLR2D1_Pin|IS1_EN_RS2_Pin|IS1_EN_RS3_Pin|IS1_EN_RS4_Pin
			|RS485_TERM_1_Pin;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
	HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

	/*Configure GPIO pin : IS2_EN_RS4_Pin */
	GPIO_InitStruct.Pin = IS2_EN_RS4_Pin;
	GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	HAL_GPIO_Init(IS2_EN_RS4_GPIO_Port, &GPIO_InitStruct);

	/*Configure GPIO pin : I2C1_Data_Temp_alrt_Pin */
	GPIO_InitStruct.Pin = I2C1_Data_Temp_alrt_Pin;
	GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	HAL_GPIO_Init(I2C1_Data_Temp_alrt_GPIO_Port, &GPIO_InitStruct);

	/*Configure GPIO pin Output Level */
	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_7
			|GPIO_PIN_6|GPIO_PIN_5, GPIO_PIN_RESET);

	/*Configure GPIO pins : PD9 PD10 PD11 PD3
                           PD4 PD5 */
	GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_7
			|GPIO_PIN_6|GPIO_PIN_5;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
	HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_11 ,GPIO_PIN_SET);

	GPIO_InitStruct.Pin = GPIO_PIN_11;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
	HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
	/* USER CODE BEGIN MX_GPIO_Init_2 */
	/* USER CODE END MX_GPIO_Init_2 */
}


void ads_hardware_reset()
{
	HAL_GPIO_WritePin(RST_PIN_GPIO_Port, RST_PIN_Pin, GPIO_PIN_RESET);

	HAL_Delay(500);

	HAL_GPIO_WritePin(RST_PIN_GPIO_Port, RST_PIN_Pin, GPIO_PIN_SET);
}

void ads13_WriteReg(SPI_HandleTypeDef *hspi , uint8_t register_address ,uint8_t data)
{

	uint8_t txdata[3] = {  0x40 | (0x1f & register_address)  , 0 , data} ;

	HAL_GPIO_WritePin(cs_pin_GPIO_Port, cs_pin_Pin, GPIO_PIN_RESET);  // CS low

	HAL_SPI_Transmit(hspi,txdata, 3, HAL_MAX_DELAY);  // Send read command

	HAL_GPIO_WritePin(cs_pin_GPIO_Port, cs_pin_Pin, GPIO_PIN_SET);  // CS high
}

void ads13_WriteReg(SPI_HandleTypeDef *hspi , uint8_t register_address ,uint8_t data)
{

	uint8_t txdata[3] = {  0x40 | (0x1f & register_address)  , 0 , data} ;

	HAL_GPIO_WritePin(cs_pin_GPIO_Port, cs_pin_Pin, GPIO_PIN_RESET);  // CS low

	HAL_SPI_Transmit(hspi,txdata, 3, HAL_MAX_DELAY);  // Send read command

	HAL_GPIO_WritePin(cs_pin_GPIO_Port, cs_pin_Pin, GPIO_PIN_SET);  // CS high
}

HAL_StatusTypeDef exit_RDATAC_mode()
{
	uint8_t SRDATAC_cmd = 0x11 ;

	HAL_GPIO_WritePin(cs_pin_GPIO_Port, cs_pin_Pin, GPIO_PIN_RESET);  // CS low

	HAL_StatusTypeDef status =   HAL_SPI_Transmit(&hspi1,&SRDATAC_cmd, 1, HAL_MAX_DELAY);  // Send read command

	HAL_GPIO_WritePin(cs_pin_GPIO_Port, cs_pin_Pin, GPIO_PIN_SET);  // CS high

	return status ;
}

int ads_exec_command(uint8_t command)
{
	HAL_GPIO_WritePin(cs_pin_GPIO_Port, cs_pin_Pin, GPIO_PIN_RESET);  // CS low

	int ret = HAL_SPI_Transmit(&hspi1,&command, 1, HAL_MAX_DELAY);  // Send read command

	HAL_GPIO_WritePin(cs_pin_GPIO_Port, cs_pin_Pin, GPIO_PIN_SET);  // CS high

	return ret ;
}


/* Configuration register 1 */
void ads13_basic_config()
{
	uint8_t val;

	/* Read Chip ID */
	val = ads13_ReadReg(&hspi1 , 0x00) ;

	//write config 1 register ,24bit 1KBPR
	//0x91  16bit  32  Kbps ----> default mode
	//0x96  24bit   1  kbps
	//0x92  24bit   16 kbps
	val = 0x92; //0x96 ;
	ads13_WriteReg(&hspi1 , 0x01 , val) ;
	val = ads13_ReadReg(&hspi1 , 0x01) ;

	/* Read the test signal generation */

	//khaledtest
	val = 0xC0; //0x96 ;
	ads13_WriteReg(&hspi1 , 0x02 , val) ;
	//khaledtest

	val = ads13_ReadReg(&hspi1 , 0x02) ;

	//config 4v internal ref
	val = ads13_ReadReg(&hspi1 , 0x03) ;
	//val = val | (0x01 << 5) ;//set VREF_4V bit to 1
	val = 0xEC;//0x60;//set VREF_4V bit to 1
	ads13_WriteReg(&hspi1, 0x03, val) ;

	val = ads13_ReadReg(&hspi1 , 0x03) ;


	val = ads13_ReadReg(&hspi1 , 0x17) ;
	val = 0x02;
	ads13_WriteReg(&hspi1, 0x17, val) ;
	val = ads13_ReadReg(&hspi1 , 0x17) ;

	//config channel1
	val = 0x10 ;
	val = 0x10;//val | 0x0; //4 for temp sensor , 1 for  avdd;
	//val = (0x1 << 7) ;//power down all channel

	//set channel 1 input temperature sensor
	ads13_WriteReg(&hspi1, 0x05, val) ;//channel1
	ads13_WriteReg(&hspi1, 0x06, val) ;//ch2
	ads13_WriteReg(&hspi1, 0x07, val) ;//ch3
	ads13_WriteReg(&hspi1, 0x08, val) ;
	ads13_WriteReg(&hspi1, 0x09, val) ;
	ads13_WriteReg(&hspi1, 0x0a, val) ;
	ads13_WriteReg(&hspi1, 0x0b, val) ;
	ads13_WriteReg(&hspi1, 0x0c, val) ;


}

void ads13_read_data(float channel_value[8])
{
	if(HAL_SPI_GetState(&hspi1) == HAL_SPI_STATE_READY)
	{
		HAL_SPI_Receive_DMA(&hspi1, &rx_data[0], 27);
	}

	//HAL_GPIO_WritePin(cs_pin_GPIO_Port, cs_pin_Pin, GPIO_PIN_SET);  // CS high

	EndTxRxTransfert = 0x0;
}

// ADS131E08S Initialisation
ads_hardware_reset();
ads_exec_command( ADS131E08_CMD_RESET) ;
HAL_Delay(ADS131E08_WAIT_RESET_CYCLES) ;
liRetADS131E08status = exit_RDATAC_mode();

ads13_basic_config();
/***************calibration************/
ads_exec_command(ADS131E08_CMD_OFFSETCAL) ;
ads_exec_command(ADS131E08_CMD_START)     ;
HAL_Delay(ADS131E08_WAIT_OFFSETCAL_MS)    ;
ads_exec_command(ADS131E08_CMD_STOP)      ;
/**************************************/
ads_exec_command( ADS131E08_CMD_RDATAC);

 

 

2 REPLIES 2
Andrew Neil
Evangelist III

Duplicate of:

https://community.st.com/t5/stm32-mcus-products/stm32f765vit6-and-ads131e08-ads131e08-stop-in-continuous-mode/td-p/669291

That was a couple of weeks ago - what investigation/debugging have you done in that time?

Do you have an oscilloscope or logic analyser to see what's happening on the wires?

Have you used the debugger to see what's happening in your code?

You ignore HAL return codes; try checking them - they may be telling you something:

https://community.st.com/t5/stm32-mcus-boards-and-hardware/hal-rcc-oscconfig/m-p/674455/highlight/true#M19028

 


@Azer wrote:

the ADS131E08 stops communicating over SPI in continuous mode after a few seconds ... 


How do you know that it's the ADS131E08 which stops?

Maybe it's your code which gets stuck somewhere?

 


@Azer wrote:

... and block the SPI communication 


What do you mean by that?

Azer
Associate

Hello Andrew,

Thank for your Response ,
 
I have tried a lot of Tests , and Here are some details about my Tests :
I] Shematic : 
This the shematic of the ads131e08 with the Stm32

05218.Capture.PNG

and  the ADC is powered via this two blocks  with 500ma Capabilities, normally the ADC consumes less than 10mA

 

pastedimage1712175910458v1.png

II] MX configuration
mx configuration.png


III] oscilloscope : 

trame 1.pngtrame 4.pngtrame 5.pngtrame2.pngtrame3.png


ads blocked when i put it in continous mode without reset:

ads bloqué.png

IV ] Software sequence :
I m using interruption on (pin 5) for the DRDY  

 

issue description with the debugger Mode: 
 - The issue happen every time we set the Continuions Mode (0x10) and occur after a few seconds.

- We have fixed this issue by putting the ADS131E08S IN discontinuions  mode(0x12) and a software reset.
 
- Without the reset the communication with the ads is blocked and when we try to read the config registers , the returned values of the configs regs is 0x0 and the ads readed values :
           +  before the stop ==> values  correct for a few seconds 
           + after the stop ==> value  0 for the 8 channels


there is a Hardware reset using the software command and it is mandatory to get data from ADS ,and If I don't perform the reset, the ADS131E08 works for 3 read cycles and then stops the read process, making no SPI communication possible with the ADS. and due to this reset i m losing 20ms to reset the ads131e08.

V] in the electronic conception, we have found some issue with the emprunt of the board with our oscillateur so we configured our board on the internal oscillateur, does this can make a problem ?