DS1631 Temperature chip i2C

General discussion on mikroBasic.
Post Reply
Author
Message
TheRidgeback
Posts: 1
Joined: 18 Apr 2018 04:36

DS1631 Temperature chip i2C

#1 Post by TheRidgeback » 18 Apr 2018 05:23

Morning All.

Im in the middle of writing a boiler control program and i seem to have run into an odd problem which has had me stumped for about a week now.

Ive stripped out all but the temperature code and its listed below.

const Outsidechip as byte = %1001000

main:

dim Temperature_write_address as byte
dim Temperature_read_address as byte
dim chipaddress as byte
dim junk1 as byte
dim junk2 as byte

chipaddress = Outsidechip * 2
Temperature_write_address = chipaddress
Temperature_read_address = chipaddress + 1

trisb = 0
trisa = 0
porta = 0
portb = 0

i2c_init(100000)

I2C_Start()
I2C_Wr(Temperature_write_address) 'send write ddress of chip to write to
I2C_Wr($AC) 'send config address
I2C_Wr(2) 'send config data (constant temp conversion 9 bit. '94ms to convert temp into data )
I2C_Stop()

I2C_Start()
I2C_Wr(Temperature_write_address) 'send tempaddress
I2C_Wr($51) 'send start converting
I2C_Stop()

while true

I2C_Start()
I2C_Wr(Temperature_write_address) 'send address of chip to read
I2C_Wr($AA) ' read temp

I2C_repeated_Start()

I2C_Wr(Temperature_read_address) 'send read address to chip you want to read from

' junk1 = i2c_rd(1) 'ack MSB Temp data
' junk2 = i2c_rd(0) 'nack LSB Temp data

i2c_Stop()
'
' porta = junk1
' portb =junk2
inc(portb)
wend

This is the problem I have
its just not working

I have the chip address as a const as I have more then one chip, the chip address is normal passed to a function and the read and write address are calculated for each chip, the temperature is passed back from the function.
but for ease of following I have removed everything from their sub routines

First part sending config data, all ok , I2c Doesn't hang. All observed on an oscilloscope trace.
2nd part, sending start conversations command all ok. Ditto on the oscilloscope

the third part is giving me the issues.
Ive stuck it in a while loop and I'm using portB as a monitor to observe that things are running.

sending the read temp command all ok
sending the repeated start and the read address for the chip
Again all ok.

I2C has a nice trace on scope

If i uncomment the two I2C read commands
I2C bus Hangs.

The time for a temp conversion on the chip is 94ms in a continuous loop with the read data pulling the last converted temperature

I have stuck various delays in after each and every line ranging from delay_ms(1) through to delay_ms(500)
allowing for the chip to take and convert one temp reading at least.

I've changed the repeated start to a stop and then a start, again with delays in-between the starts and stops.

I have changed the chip so its one shot,
called the start conversion routine,
waited the amount of time needed to do the conversion
and then tried to pull the data, and again I2C bus hangs.

No amount of head banging, coffee, red bull can make this work.

In a nut shell you need to set the chip with the resolution of the temperature and wether its one shot or contious
You then need to tell it to start converting, and thats it.
Two commands to get it going, and they seem to be working..

when you want a temperature you send the temp read command which copies over the last converted temperature
then you read out the MSB & LSB.

trace of I2C working as per the exact program above.
Image

Data sheet for the chip, https://datasheets.maximintegrated.com/ ... DS1731.pdf

Im programming a 18F2525 on an EasyPic5 Board using Mikrobasic v7

Many thanks

Mac.

Post Reply

Return to “mikroBasic General”