HX711 icon indicating copy to clipboard operation
HX711 copied to clipboard

Errors

Open ghost opened this issue 7 years ago • 3 comments

you have some errors in your library. I resolve them.

//====== //hx711.h //====== #ifndef HX711_H_ #define HX711_H_

#include "stm32f3xx_hal.h"

typedef struct _hx711 { GPIO_TypeDef* gpioSck; GPIO_TypeDef* gpioData; uint16_t pinSck; uint16_t pinData; int offset; int gain; // 1: channel A, gain factor 128 // 2: channel B, gain factor 32 // 3: channel A, gain factor 64 } HX711;

void HX711_Init(HX711 data); HX711 HX711_Tare(HX711 data, uint8_t times); int HX711_Value(HX711 data); int HX711_AverageValue(HX711 data, uint8_t times);

#endif /* HX711_H_ */

//====== //hx711.c //====== #include "hx711.h"

void HX711_Init(HX711 data) { GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.Pin = data.pinSck; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(data.gpioSck, &GPIO_InitStruct);

GPIO_InitStruct.Pin = data.pinData;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(data.gpioData, &GPIO_InitStruct);

HAL_GPIO_WritePin(data.gpioSck, data.pinSck, GPIO_PIN_SET);
HAL_Delay(50);
HAL_GPIO_WritePin(data.gpioSck, data.pinSck, GPIO_PIN_RESET);

}

int HX711_AverageValue(HX711 data, uint8_t times) { int sum = 0; for (int i = 0; i < times; i++) { sum += HX711_Value(data); }

return sum / times;

}

int HX711_Value(HX711 data) { int buffer; buffer = 0;

while (HAL_GPIO_ReadPin(data.gpioData, data.pinData)==1)
;

for (uint8_t i = 0; i < 24; i++)
{
	HAL_GPIO_WritePin(data.gpioSck, data.pinSck, GPIO_PIN_SET);

    buffer = buffer << 1 ;

    if (HAL_GPIO_ReadPin(data.gpioData, data.pinData))
    {
        buffer ++;
    }

    HAL_GPIO_WritePin(data.gpioSck, data.pinSck, GPIO_PIN_RESET);
}

for (int i = 0; i < data.gain; i++)
{
	HAL_GPIO_WritePin(data.gpioSck, data.pinSck, GPIO_PIN_SET);
	HAL_GPIO_WritePin(data.gpioSck, data.pinSck, GPIO_PIN_RESET);
}

buffer = buffer ^ 0x800000;
	buffer -= data.offset;

return buffer;

}

HX711 HX711_Tare(HX711 data, uint8_t times) { int sum = HX711_Average_Value(data, times); data.offset = sum; return data; }

ghost avatar Jun 04 '17 17:06 ghost

And here hx711.c:

HX711 HX711_Tare(HX711 data, uint8_t times) { int sum = HX711_AverageValue(data, times); data.offset = sum; return data; }

ghost avatar Jun 04 '17 17:06 ghost

Hi there! I would like to know if you have any example about the implementation of this lib, since it was made for a experience programmer it is not possible for me to use these files. Thank you!

OmarAgundis avatar Nov 24 '20 23:11 OmarAgundis

I would like to know if you have any example about the implementation of this lib, since it was made for a experience programmer it is not possible for me to use these files.

That's probably for the best. Since the library is totally buggy and incomplete. And the creator didn't care to fix those bugs in 4 years.

zorgoban avatar Mar 21 '21 09:03 zorgoban