Coder Social home page Coder Social logo

hx711's Introduction

HX711

Procedural implementation of HX711 library with HAL for STM32

hx711's People

Contributors

freakone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hx711's Issues

HX711_AverageValue naming problem

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

Master branch

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" :)

Errors

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;
}

Example code request

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.