Procedural implementation of HX711 library with HAL for STM32
freakone / hx711 Goto Github PK
View Code? Open in Web Editor NEWProcedural implementation of HX711 library with HAL for STM32
Procedural implementation of HX711 library with HAL for STM32
Hi,
In the header file, there's a prototype for HX711_AverageValue function.
But the implementation has the name HX711_Average_Value in the .c file, with an extra underscore.
You may want to fix that
Your "custom" branch works fine, but your master branch doesn't (problem at the end of the init function). Maybe you should set the "custom" branch "master" :)
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;
}
I am trying to implement this library using Keil uVision on my stm32f3, but I am unable to understand how to implement the functions. Is it possible to add an example of the usage of this library?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.