CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Questions regarding HX711 [SOLVED]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
S1gnature



Joined: 28 Apr 2020
Posts: 22

View user's profile Send private message

Questions regarding HX711 [SOLVED]
PostPosted: Fri Nov 06, 2020 7:15 am     Reply with quote

Hi everyone,

I have a few questions about the HX711 loadcell amplifier and I would like to ask for your help.

From the datasheet: https://github.com/sparkfun/HX711-Load-Cell-Amplifier/blob/master/datasheets/hx711F_EN.pdf

On page 4, it said that "By applying 25~27 positive clock pulses at the PD_SCK pin, data is shifted out from the DOUT output pin". Does that mean the data only come out after the pulses is applied on PD_SCK pin?

I take a look at this topic: https://ccsinfo.com/forum/viewtopic.php?t=56954
but I do not quite understand those line from MikeW:
Code:
Output_low(HX711_CLK);
Count=0;

while(Input(HX711_DAT));
for (i=0;i<24;i++)
{

Output_High(HX711_CLK);
(some more lines below)
...
}


On line:
Code:
while(Input(HX711_DAT));

Does that mean Data pin is already at logic high without applying pulse on PD_SCK? Also, the loop's counter starts from 0 to less than 24, it only has 24 pulses in this loop which makes me quite confusing. So we no need to apply 25th pulse (or 26, 27 based on input and gain selection we choose?) as this pulse only pull the DOUT pin to high?



Also on the datasheet, may I ask how to get the DOUT signal from high to low for the next conversion as it is an input to the PIC?

Thank you very much for your help!


Last edited by S1gnature on Sat Nov 07, 2020 8:40 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri Nov 06, 2020 8:19 am     Reply with quote

The data out pin sits high when data is not ready. So, yes the data pin is
high before you apply SCK. It drops when the conversion has completed.
Once this happens, you can then clock the data out.
Each time you clock SCK, one bit of data is output.
In the code, the count loop does one more pulse than the number of loops.
It goes high for each loop, but is then raised again after the loop (so a
25th clock).
S1gnature



Joined: 28 Apr 2020
Posts: 22

View user's profile Send private message

PostPosted: Fri Nov 06, 2020 9:00 am     Reply with quote

Thank you for your reply. It's very clear easy to follow! Very Happy
I am writing the code for HX711 before the delivery of this part comes so it might be unclear someway.

Also, may I ask you about your code in the same topic here: https://ccsinfo.com/forum/viewtopic.php?t=56954

Code:
#USE SPI (FORCE_SW, DI=YOUR_DATA_PIN, CLK=YOUR_CK_PIN, MODE=1, stream = HX)

//Then use
   while (YOUR_DATA_IN==1)
       ; //wait for chip
   val32=spi_xfer(HH,0,26); //select 26, 27 or 28 for what you want
//This will switch the chip to the specified mode.
//Default on wake up is CHA gain 128

//Then when you want to read:
   while (YOUR_DATA_IN==1)
       ; //wait for chip
   val32=spi_xfer(HX,0,24);

//val32 will now contain the 24bit reading from the chip


On line
Code:
val32=spi_xfer(HH,0,26); //select 26, 27 or 28 for what you want

1. Is that a typo mistake there? I think it should be "HX" instead of "HH".
2. force_sw means force software is that correct. Since I don't find any reference to this parameter in CCS Help file (version 5.015).
For two lines:
Code:
val32=spi_xfer(HH,0,26);
val32=spi_xfer(HX,0,24);

According to reference:
spi_xfer(stream, data, bits)
data is the variable or constant to transfer via SPI. The pin used to transfer data is defined in the DO=pin option in #use spi.

3. May I ask why don't need to declare the "DO pin" in the header and why we need to send data 0 there?

Thank you very much.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri Nov 06, 2020 12:20 pm     Reply with quote

Yes, HX versus HH.

You don't need a DO pin. The chip only clocks data out, nothing back in.
Why waste a pin?. With software SPI you can setup one direction only
if you want.
Yes it has to be a software port to allow you to do an odd number of clocks
like 25. It should be documented. In my manual, under #use spi, it
says:
Quote:

FORCE_SW - Use a software implementation even when hardware pins are
specified.
FORCE_HW - Use the pic hardware SPI.


An SPI transfer is fundamentally always two way, even when you only
setup one way in the #use. So I'm clocking 'out' a dummy value to
the undefined pin (so nothing is actually sent). And receiving what is
clocked 'back'. You can put any value you want for what is to be sent.
S1gnature



Joined: 28 Apr 2020
Posts: 22

View user's profile Send private message

PostPosted: Sat Nov 07, 2020 8:39 am     Reply with quote

Thank you Ttelmah, you clarify all my ambiguities. Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group