Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20665

Share your working BASCOM-AVR code here : Si7005 temperature and humidity : NEWTOPIC

$
0
0
The Si7005 is another interesting temperature and humidity chip using I2C. It seems fairly accurate. [code:1:64671e4c23] '>>> Si7005.bas <<< 'READ TEMPERATURE AND HUMIDITY FROM SILICON Labs Si7005 'http://www.silabs.com/Support%20Documents/TechnicalDocs/Si7005.pdf 'USES THE I2C PROTOCOL 'SDA IS PIND.2, SCL IS PIND.4, PINB.O CONNECTS TO A LED TO FLASH DURING PROGRAM RUN 'MAKE SURE OSC OUT IS DISABLED, SINCE OSC OUT USES PIN14 WHICH IS USED HERE AT PB.0 FOR THE LED 'BEWARE!!! THE Si7005 SHOULD RUN AT 3.3 VOLTS; I USED A PCA9306 LEVEL CONVERTER CHIP ' TO CONVERT THE SCA AND SCL LINES FROM the uP RUNNING AT 5.0 volts TO 3.3 VOLTS ' I USED 1K PULL-UP RESISTORS; HIGHER VALUES of Rp APPARENTLY PERMITTED FLICKER ON THE 3.3 VOLT LINE ' AND UNRELIABILITY OF OPERATION WAS THE RESULT ' SPARKFUN SELLS A PCA9306 BREAK-OUT BOARD COMPLETE WITH 1K PULL-UP RESISTORS ' PART NUMBER BOB-10403 'I wrote this after studying Jean-Claude Feltes information on I2C 'http://staff.ltam.lu/feljc/ 'Some of his layout appears in what follows: $crystal = 20000000 $regfile = "m88def.dat" $baud = 2400 Config I2cdelay = 20 'to slow down I2C rate to read pulses on scope Config Sda = Portd.2 'I2C set up Config Scl = Portd.4 Config Pinb.0 = Output 'to flash led Portb.0 = 0 Dim X As Byte 'high byte Dim Y As Byte 'low byte Dim Z As Word 'used to calculate raw value Dim Z1 As Long 'used to adust high byte Dim Z2 As Byte 'used to adjust low byte Dim Tc As Word 'centigrade value Dim Rh As Word 'humidity value '------------------------------------------------------------------------------- Do Gosub I2ctmp Print " " Print "HI = " ; X; 'print high byte of temperature Print " " Print "LO = " ; Y; 'print low byte if temperature Print " " Print "RAW = " ; Z; 'print adjusted raw data, combined X and Y Print " " Print "Degrees centigrade = " ; Tc 'print centigrade value Gosub I2crh Print "HI = " ; X; 'print high byte of humidity Print " " Print "LO = " ; Y; 'print low byte of humidity Print " " Print "RAW = " ; Z; 'print adjusted raw data Print " " Print "Humidity percent = " ; Rh 'print relative humidity Wait 1 Toggle Portb.0 'toggle led Loop '------------------------------------------------------------------------------ 'I2C ROUTINES HERE I2ctmp: I2cstart I2cwbyte &B10000000 'address of chip to receive a write from uP I2cwbyte &B00000011 'select register DEC 3 to receive the write from uP I2cwbyte &B00010001 'data written from uP to to register DEC 3 is HEX 11 = start temp conv. I2cstop Waitms 50 'conversion takes 35ms I2cstart I2cwbyte &B10000000 'address of chip to receive a write to (then a read from) uP I2cwbyte &B00000001 'address of register that has received write in above segment I2cstart I2cwbyte &B10000001 'address of chip that will be read I2crbyte X , Ack 'read Hi byte I2crbyte Y , Nack 'read LO byte I2cstop 'see page 20 in the si7005 data .pdf Z1 = X * 64 Z2 = Z / 4 Z = Z1 + Z2 'raw score Tc = Z / 32 'degrees C Tc = Tc - 50 Return I2crh: I2cstart I2cwbyte &B10000000 'address chip to receive a write from uP I2cwbyte &B00000011 'select register DEC 3 to receive the write from uP I2cwbyte &B00000001 'data written from uP to to register DEC 3 is HEX 01 = start humid conv. I2cstop Waitms 50 'conversion takes 35ms I2cstart I2cwbyte &B10000000 'address of chip to receive a write to (then a read from) uP I2cwbyte &B00000001 'Address of register that has received write in above segment I2cstart I2cwbyte &B10000001 'address of chip that will be read I2crbyte X , Ack 'read Hi byte I2crbyte Y , Nack 'read LO byte I2cstop 'see page 19 in the Si7005 data .pdf Z1 = X * 16 Z2 = Z / 8 Z = Z1 + Z2 'raw score Rh = Z / 16 Rh = Rh - 24 'humidity % Return '------------------------------------------------------------------------------- [/code:1:64671e4c23] Gary

Viewing all articles
Browse latest Browse all 20665

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>