HX711 digitalRead into uint32_t

Hi,

I would like to read out the data of the HX711 in a uint32_t variable directly. But it does not work. I step into the code of the HX711 library (GitHub - bogde/HX711: An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales.) and I saw, that the proper function reads out 3 uint8t variables corresponding to 3 8 bits instead of reading out the whole 24 bits in a uint32_t.
Here is my code segement trying to read 24 bit in a uint32t:

uint32_t dataT = { 0 };

    for (int i = 0; i<24; i++)
    {
        digitalWrite(m_pd_sck, HIGH);
        dataT |= static_cast<uint32_t>(digitalRead(m_dOut)) << (23 - i);
	    digitalWrite(m_pd_sck, LOW);
    }

in comparison the segement of the HX711 library:
data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST);
data[1] = shiftIn(DOUT, PD_SCK, MSBFIRST);
data[0] =shiftIn(DOUT, PD_SCK, MSBFIRST);

Can anybody help me or give me a hint what is wrong with my code?
KR, Cleeee

The read function of the library returns a 32 bit long which may be cast to uint32_t.

I would like to write my own read function. The code sequence which I described in my first post is inside the read()-function. Inside the read-function, the 24 bits coming from the 24-bit-ADC are read by 3 times 8 bits with the shiftIn-function. My attempt is to read the 24 bits at once in an uint32_t and there are the problem that the value is not the same as with the read-function of the HX711 library.

Why don't you just stick with what works?

I would like to understand why something works and others not, respectively.

post expected outcome vs actual

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.