HX711 Load cell with STM32 Doubt.
Hi,
I'm trying to interface the HX711 load cell with an STM32 MCU. The resultant values are varying by a huge margin after every interval so please help. I'm, uploading my code
So PA6 - GPIO Input - DOUT pin
PB9 - GPIO Output - Pulldown - SCLK Pin
#include "load.h"
uint32_t val = 0;
uint8_t dout;
extern TIM_HandleTypeDef htim1;
void delay_us (uint16_t us)
{
__HAL_TIM_SET_COUNTER(&htim1,0);
while (__HAL_TIM_GET_COUNTER(&htim1) < us);
}
void load_init(){
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET);
}
uint32_t load_value(){
for (uint8_t i = 0; i < 24; i++){
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET);
delay_us(1);
dout = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_6);
val = val << 1;
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET);
delay_us(1);
if(dout){
val++;
}
}
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET);
val = val ^ 0X800000;
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET);
return val;
}
In my main function:
HAL_TIM_Base_Start(&htim1);
while (1)
{
while(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_6) == GPIO_PIN_RESET){
res = load_value();// final result of load cell
HAL_Delay(1000);
/* USER CODE END WHILE */
}
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
Thanks!
