Here I have Two Option but both giving me problem any one knows plz help!!!

op_1) make my own c function to read count which is similar to Arduino shiftIn() function but I don't know how to do it ... Actully Arduino have ready made library for hx711 24bit ADC and into that library I get following function which return me adc_count

long read(void) { // wait for the chip to become ready while (!is_ready()) { // Will do nothing on Arduino but prevent resets of ESP8266 (Watchdog Issue) yield(); }

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


here in this function they have used siftin() function how to implement this using c language ?

op_2)I have written my own read() function which return adc count but I get garbage value ....

unsigned long read(void) { unsigned long count,dout; uint8_t i;
count = 0; dout = 0;

if(isready() == 1)
        dout = GPIO_ReadInputDataBit(GPIOC,DOUT);
        count = (count | dout) << 1;

} GPIO_SetBits(GPIOC,PD_SCK); GPIO_ResetBits(GPIOC,PD_SCK); count = count >> 1; return count; }

  • 1
    \$\begingroup\$ Your question is unclear. Are you using a microcontroller? \$\endgroup\$ – Simus994 Jul 26 '17 at 10:36
  • \$\begingroup\$ Yes I am using STM32L1RCT6 MCU !!!! \$\endgroup\$ – mulesandip3 Jul 26 '17 at 11:13

Arduino shiftin() is easy to port so that seems the simplest solution.

I posted a set of hx711 code here https://dannyelectronics.wordpress.com/2017/06/29/hx711-code-available/

It has links to the original work I did with the chip as well as downable code. You should be able to get it going on any chip easily.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.