Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Help] 8051 interfacing sensirion SHT7X digital sensor

Status
Not open for further replies.

aaron8390

Member level 1
Joined
Aug 23, 2007
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,621
sht7x

I have few question regarding it,

First ,can this sensor be interface by 89c52,using assembly language?

I had design a assembly language to try to interface this digital sensor ,but so far i stucked when using LED to test the output and there is no result , those LED just give me 3 "blinks" and hav no reaction after that.

I attached my assembly language coding here and can guys please give me comment and guide about it? I am really very tension in doing this project now...

And also i attached the data sheet for this sensor

Basically this sensor interfacing :
A) Send a start transmission signal
B) Send a command ,either to meassure temperature or humidty
C) Wait for the sensor to finish the measurement
D) Receive the data in serial form.
 

sensirion no ack

Sorry, i attach my coding here.

I could not post my coding out here because all the spacing and arrangement become very messy, it just squeeze all the things to left .

Anybody please help me with this sensor T.T...
 

interfacing sensirion

Hi,
For the first part of your question, yes, it should be possible to interface the sensor with 89C52 using Assembly Language. For the second part, will get back to you later. In the mean time you also keep trying.
Regards,
Laktronics
 

placement for the sht7x sensor

yah...i am trying too...and asking lecturer as well.

Thank you for willing to help me !! :D
 

sensirion ack problem

Hi,
As a test program it should have worked, except for the end statement, which if you want, should move to the real end of your codes. In the place of End, you can place an ljump to the start.
Also, how did you take care of removing Check sum byte, you may have to read and reject it also. Also you need an sck pulse to generate the last NO ACK bit
Regards,
Laktronics

Added after 2 hours 10 minutes:

Hi,
Please note the following points also:
1. You need to give a minimum delay of 11 msec. in the beginning before sending any command to the sensor, call your delay routine once in the beginning also.
2. The sensor outputs MSB first, but you are storing them into LSB first. Mov p0.6,C code is repeated twice.
3. While the sensor supplies the bytes, the controller has to generate ACK-. After reading the first data byte, you have kept the DATA bit positive for 9th bit, so ACK is +ve and will terminate the command. Change it to -ve. You have kept the ACK +ve after the second byte also, which is one way to tell the sensor that you do not want the checksum byte, which answers my question in the previous post.
But I suppose, at any time the sensor can be brought to its initial state by generating a start of command state and if so, the last SCK corresponding to +ve ACK from master may not be required.
4. You can make your code look very compact if you write subroutines for the following states:
a. Generate start of command.
b. Send Command ( Accumulator holding the command byte)
3. Read Byte ( Accu. returning the byte read)
4. Check for ACK from slave
5. Terminate Command ( Send a +ve ACK)

Regards,
Laktronics
 

sensirion software user manual

HI,thanks

Regarding your guide, i had make changes for 1,2 and 3.

I have few question,
a)If i am not using CRC checksum,is it matter?
b)If i am not using CRC checksum, according to the datasheet,i just need to skip the ACK. This should be ok right? As if i need another measurement, i can just press the reset button. Or still a +ACK needed?

c)I have limited assembly language knowledge,but i willing to try. In making my code look compact ,if i store the byte in accumulator,how to send it in serial(in bit form) to the sensor and with parallel to the SCK pulse?

And also to read Byte,the measurement come in serial form also,but as u say Accumulator could return in a byte form. How should it works?
 

how to store values in lookup table for 8051

Hi,
1. What happened after you made changes as per points 1,2 and 3 ?
I suppose you would have shifted the End directive to the last line after all codes in your program.
Also, I forgot to mention yesterday that it is a good practice to put only an Sjump Main at 0X0000 and start the main program with label Main: after the interrupt vector address space area to leave the interrupt vector address area reserved for any future interrupt usage.

2. As I have already told you, and also as shown in the data sheet, it should be possible to tell the sensor that you do not want CRC byte by sending a +ve ACK after reading the second byte. I am not sure what will happen if you do not terminate the communication sequence with a +ve ACK, this scheme is also used in I2C. Intuitively I feel if you send a start of command condition anytime, the sensor may get restarted with a new command sequence, which you can experiment and let me know. It is also possible that the sensor logic may not accept a start of command unless the current sequence is terminated properly.

But if you are resetting the system using power-on, the sensor should start afresh, though it is not a standard way of execution of a command.

3. You can store the 8 bit command to be sent in accu., call a send routine, the routine will use RLC instruction for 8 times in a loop and each time process the carry as you have done, and lastly check for the ACK- also as the nineth bit and return.
4. While you receive a byte, a similar subroutine will read the data bit into carry, then RLC instruction to shift the byte into accumulator,do it eight times and then transmit a -ve/+ve ACK and return with ACCU. containing the read byte.
Regards,
Laktronics
 

7-segment sensirion

Hey,thank you again

Sorry for late reply, my uni. lab don't open at weekend. So i just finish testing the new code 2day.

Well i still can't get the output after fixing part 1 2 3 also ! :(

I upload the latest code according to your guide. (I did not compact the code yet,as i need study for that and i will do it later, after acquired the test result)



I have few question regarding the hardware.
1)The sensor i just need to connect according to the data sheet right? As pin 1 SCK to P1.0 of microC , pin 2 to a 5v supply, pin 3 to ground and pin 4 DATA to P1.1 of microC and with a external pull up resistor of 10k .

2)I placed 5 LEDs to check the result (at P0.0-P0.4). The LEDs on when without putting on sensor into the circuit . And with sensor, the result stored in each port bit should trigger the LEDs if i obtainied the result right? Now the LEDs dont trigger,so i think there is no result obtain =.=...

3)The 5 LEDs share a same roll of pull up resistor with the DATA line,is it ok? Or should put a independent resistor for the DATA line.

4)Any other way to check if the sensor is function-able? Beside testing like this, maybe the sensor spoiled @@!

Last , for the termination ACK after 2nd byte,i will include it in the code and try it tomorrow in the lab, but if without it now my LEDs should be triggering also right?

Thank you again !!
 

Hi,
I will come back after a while, but in the mean time, you should add an 'LJMP MAIN ' at the end of your main routine, before label CLR DATA: ,else your code will will run through CLR DATA after one time doing MAIN. Also I would like to place MAIN: label after ORG 0000X directive, though it may not matter.

Regarding your points,

1. Yes, you should connect the sensor as per data sheet, as you explained.

2. Yes, the LEDs should show the five LSBs of the reading.

3.LEDs will do the function of pullup also, no need for separate pull up.

4. Only way to test the sensor is like this only, unless you have done some wrong supply connection etc, you can expect the sensor is ok to start with.

5. I also would expect LEDs to work once, but without the LJMP mentioned above, your CPU can go out of control. And when you put LJMP, you may need to terminate the command with a positive ACK !!

6. I also hope, you have identified the pin numbers correctly on the device, which type you have, flat type or IC type, as I understood, the pin 1 of flat type is the pin near the + mark.

Regards,
Laktronics
 

Hi,
The following corrections are also required:
1. Instead of LJMP to MAIN after the MAIN routine, do LJMP to the first Delay Call
after MAIN: .
2. You have to SETB DATAA after ACK- of receipt of the first Byte. Always default state of Data line should be high and that of SCK should be low.

I have attached here your code with those corrections.

Regards,
Laktronics
 

    aaron8390

    Points: 2
    Helpful Answer Positive Rating
Sorry for late reply again, having mid-term exam papers. Will inform u as soon as possible !
 

Halo, thank you.

I think i had successfully testing this sensor. It gave me trigger on my LEDs !!
For the code u guide me,it is keep repeating taking reading,so my leds trigger every about 1sec.

And i edit the code from LJMP STRT to SJMP $. Which i only wan it to measure once,and it did give me one times trigger on LEDs.

But i want to ask one question, why can't i take another reading by pushing my reset button? I could only get a new reading with swtiching on and off the power supply.

Okie,i think now is the time for me to change the bits data to physical value.

a)As u said store it in Accumulator? Den only convert to a deximal number?
Any guide or information about this code as i want to study it,i can't find it in my text book.

b) with and without temperature compensation,what is the different?Do I need temperation compensation?

c)As i seen in the datasheet, the formula part, how can i equat a "value" like that in 8051? Any guide or information can let me to study?

Thank you for your help again!!
 

Hi,
Nice to know your code is working.
It should be possible to take a reading by pushing the RESET button. Why is the RESET not working? You have to connect the RESET switch across the RESET capacitor through a current limitting resistor, about 1K.
You can now store the working copy of your software safely and work with a copy to make some minor improvements like, reducing some NOPs from the Clock cycles , remove CLR C instructions etc.

Being in assembler, the toughest portion of the software is Engineering Unit Conversion. How do you propose to display the reading? What about those interfaces?

Regards,
Laktronics
 

Abit confuse here.

Removing some nops will make the duty cycle not 50%. Is this alright?
The CLR C command is not necessary?

What is Engineering Unit Conversion?
Meaning from now the bits result i received, to convert and pack in a register(such as Accumulator).And apply the formula by the sensor data sheet to get the physical value?

This is the tough part?

Okie i had research abit on internet, 8051 assembly language can't work with float number representation? Then how should i carry out the formula....

I have no idea how to start yet, but i had ask my lecturer, he said every mathematical value can be "EQU" at starting of my code. Like 10 power of 5, something like that. And he ask me to search on internet of how it should be going on.

Hmm Hmm...
 

Hi,
1. I do not think 50% duty cycle is necessary, is it mentioned like that somewhere? As far as I know, only minimum clock 1 and 0 level periods are mentioned, please check. Even if you want symmetry, I thought you can still remove some NOPs from from both 0 and 1 states of clock. In any case whenever you try such things make only one type change at a time and test it after that. always keep a copy of each working code under a seperate version number.

2. When you are moving a bit to C you need not clear it.

3. Engineering unit conversion means to get the actual physical values from the sensor readings using the eqations given in the catalogue. You can try the following logic to overcome the floating point calculation in assembler:

A. Calculation of 14 bit temperature:
The temperature in centigrade T = -40 +0.01(Rdt) where Rdt is temp.reading from the sensor.

So, T = 0.01[ - 4000D + Rdt] ; where D stands for Decimal and Rdt is in binay format.

By a first approximation, 4000D can be taken as a high bit in the 13th bit position. So subtract a 1 from the 13 th bit of the reading.. This approximation introduces an error of about 1degree centigrade which can be added to the final reading as follows:
So now the temperature in BCD T = 0.01[ BCD of ( Rdt - 1 in 13 th bit) +100D]
the 100D is added to correct for the error due to approximation and the 0.01 multiplication can be taken care of in the placement of decimal point in the display.

B. 12 bit Relative Humidity Calculation:
The equation for Rh = - 4 +0.04( Rdh) - 2.8 *10^-6 (Rdh)^2 , Rdh is the
reading from the sensor.
Calculation steps:
a) Neglecting the squared term for the time being,
Rh = 0.01[4 (-100D + Rdh)] ; D stands for Decimal.
Now do first a binary arithmetic of the terms within the square bracket and convert it to BCD.
Multiplication with 0.01 can be done by setting the decimal point in the display.

b) For the balance term, take only the MS nibble of Rdh keeping lower bits to zero and calculate the value of the expression
b0 = 2.8*10^-6(Rdh)^2 and store in a 16 byte look up table against the MS nibble , after converting into BCD. While calculating the final value,add a correction factor of bc = 0.01( 2.n1*n2 ) to the table values, where n1 is the MS nibble and n2 is the middle nibble of Rdh. So, b= b0+bc

c) Subtract b) from a) considering the scaling factor of 0.01 for a). Display the result as Rh in %


Regards,
Laktronics
 

Hi,
I think for more accurate results, you should also try 16 bit integer arithmetic for your calculations, leaving the decimal exponents to be finally adjusted for locating the decimal point for display purposes. In this case for humidity calculations, you can leave the LSB and take only 11 bit precision so that when you multiply by 28 the value will still be a 16 bit number.

Regards,
Laktronics
 

VAn any one send me 7 segment display codes????

Added after 34 minutes:

hi to everyone
 

Sorry, most of it i understand except this

b) For the balance term, take only the MS nibble of Rdh keeping lower bits to zero and calculate the value of the expression
b0 = 2.8*10^-6(Rdh)^2 and store in a 16 byte look up table against the MS nibble , after converting into BCD. While calculating the final value,add a correction factor of bc = 0.01( 2.n1*n2 ) to the table values, where n1 is the MS nibble and n2 is the middle nibble of Rdh. So, b= b0+bc

Why only take MS nibble and neglect the Middle nibble and LS nibble?

A 16byte (bit?) look up table ? What is this?

Not so understand how u got the correction factor for this part b?
 

Hi,
You do not have to follow the approximation given, you can do 16 bit integer arthmetic and since the CPU gives 8 bit multiply instruction, you can calculate the term more accurately with out using shortcuts.
Any how I will explain what I had in mind:
The term to be computed is 2.8*10^-6 (Rdh)^2, where Rdh is a 12 bit number.
Let us say you make the lower 8bits all to zero and take values of only the MS nibble n1 , which has an address range of 0 to F, 16 Values. You create a look up table corresponding to these 16 values of MS nibble. For example, you compute using your calculator, the value of 2.8(0X F00)^2*10^-6 =41.28D and store this value into the table corresponding to address 0XF. You do the same calculation changing 0XF to 0XE ....0X0 and get the look up table ready.
Now let us correct for the damages done by neglecting the lower 8bits to some extent.
If we consider the 12 bit number for Rdh as a sum of the MS nibble n1 and an 8bit LS byte b1, you get value of Rdh as:
Value of Rdh = (n1*1024/4 + b1)
So, (Rdh)^2 = (n1*1024/4 + b1)^2
= [(n1*1024/4 )^2 + 2 (n1*1024/4 )b1 +b1^2]
And the term in humidity calculation will be 2.8*10^-6 [(n1*1024/4 )^2 + 2 (n1*1024/4 )b1 +b1^2]

You have already computed 2.8*10^-6(n1*1024/4)^2 and kept in your table.
So the remaining error tearm is 2.8*10^-6[ 2 (n1*1024/4 )b1 +b1^2 ]
Of the error term, the max value of b1 being 256D, the max of term 2.8*10^-6*b1^2 works out to
2.8*10^-6(256)^2 = 0.18 and is coolly neglected since an error of 0.18 in humidity is not important.
Now we are left with the only error term Er = 2.8*2*256 n1b1*10^-6
If we further split b1 as n2*16 + n3 , where n2 and n3 are respectively the middle and LS nibbles of Rdh,
we get Er = 2.8*2*256 n1(n2*16 + n3 )*10^-6
Now if we consider the max value of n3 as 0X 0F and the max value of n1 as 0XF, the contribution due to n3 will be
2.8*2*256*0Fh*0Fh *10^-6 = 0.32 which is also neglected.
So you get Er = 2.8*2*256*16 n1n2*10^-6
= 2.29*n1n2*10^-2 to be precise, which you can calculate using MPY instruction of CPU.
This value of Er to be added to the byte from the 16 byte lookup table, selected based on value of n1, for each reading taken, and finally subtracted from the first term already calculated, to arrive at the % humidity value.
Regards,
Laktronics
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top