SparkFun Forums 

Where electronics enthusiasts find answers.

Questions &/or issues related to products in the Flex / Force category should be posted in this forum. includes Force Sensitive Resistors, Load Cells & Amplifiers, Pressure Sensors, etc
User avatar
By navy7
Hi, I'm reading data from HX711 with stm32F1 but accuracy of the data are awful. when i read data with arduino the data ten times good if we compare with stm32 results. these are my read functions.

Arduino function:
Code: Select all
long HX711::read() {

// Wait for the chip to become ready.

// Define structures for reading data into.
unsigned long value = 0;
uint8_t data[3] = { 0 };
uint8_t filler = 0x00;

// Pulse the clock pin 24 times to read the data.
data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST);
data[1] = shiftIn(DOUT, PD_SCK, MSBFIRST);
data[0] = shiftIn(DOUT, PD_SCK, MSBFIRST);

// Set the channel and the gain factor for the next reading using the clock pin.
for (unsigned int i = 0; i < GAIN; i++) {
    digitalWrite(PD_SCK, HIGH);
    digitalWrite(PD_SCK, LOW);

// Replicate the most significant bit to pad out a 32-bit signed integer
if (data[2] & 0x80) {
    filler = 0xFF;
} else {
    filler = 0x00;

// Construct a 32-bit signed integer
value = ( static_cast<unsigned long>(filler) << 24
        | static_cast<unsigned long>(data[2]) << 16
        | static_cast<unsigned long>(data[1]) << 8
        | static_cast<unsigned long>(data[0]) );

return static_cast<long>(value);

STM32F1 Function:
Code: Select all
long hx711_read(){

    unsigned long Count;
        unsigned char i;

        while( HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)==SET);

        for (i=0;i<24;i++){ 
            if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)==SET){ Count++;}


        return Count;

what could be the reason why these two functions give different accuracy?
User avatar
By TS-Mark
Hi navy7,

I am not sure I fully understand your issue here. The HX711 is working correctly on an Arduino using the library we provide, correct? If so, I'm afraid SparkFun Tech Support cannot assist you with this issue with the STM32F1 as we do not carry that board and cannot help with custom code. We would be happy to help you troubleshoot any issues using the HX711 and our code and guide but cannot help with boards SparkFun does not carry.