How to use HX711 module with PIC microcontroller

load cellpic

I'm trying to use the HX711 to capture the weight of a load cell using the PIC18F4520 microcontroller.

According to the datasheet (http://www.dfrobot.com/image/data/SEN0160/hx711_english.pdf) if I put the clock pin (PD_SCK) at GND, the module will activate its internal clock, so simply read what leaving the DOUT pin. Is this right?

If this are correct, I have to connect this output to an analog port?

(Sorry my english)

Best Answer

The datasheet pg.1 says On-chip oscillator requiring no external component with optional external crystal. So apparently it can function driven from the PIC clock, or with it's own clock.

On page 2, it says PD_SCK is for Power down control (high active) and serial clock input. So this is incorrect, as XI is for Crystal I/O or external clock input, 0: use on-chip oscillator. So XI LOW forces it to use it's own oscillator; PD_SCK HIGH forces it into power-down mode.

Page 4 explains how to use internal or external clock, and the timing and speeds available. If you choose to let the HX711 use it's own internal clock, then it will spit out either 10 or 80 samples per second, depending on whether the RATE pin is low or high. If it is happily spitting out 80 samples per second, and the PIC starts looking at that data somewhere in the middle, then it's going to be tough figuring out which bit is being looked at and where the next sample starts. It can be done but would require some elaborate analysis of the incoming data bits.

It would probably be advantageous to run a PIC output pin to PD_SCK and a PIC input pin to DOUT, forget the self-clock, and "bit-bang" responses whenever the PIC code runs. By "bit-bang" I mean write some PIC code that gets each bit, one at a time. Here is some pseudo-code:

is DOUT low? If so, continue, else exit.
    (send 1 clock pulse to the HX711: LOW, HIGH, LOW,
    read the single data bit output into a 24-bit PIC integer,
    rotate the integer one bit, either direction, doesn't matter)
    do this exactly 24 times.
send 1 clock pulse.
DOUT should now be high. If it is not, an error occurred.
(If you want to keep the gain at 128 for the next sample, do nothing.
 If you want to switch the HX711 to Channel B input with gain of 32, send 1 clock.
 If you want to switch to Channel A input with gain of 64, send 1 more clock.)

The timing requirements would still apply; meaning that if the HX711 is set to spit out 80 samples per second, you won't be able to read them in time from a PIC running at 32kHz. The PIC must be fast enough to read a sample before the next one comes in. That shouldn't be a problem if using a fast PIC and the 10 samples/sec setting.