Hello I am trying to a pic 16F628 to read a ds1621 temperature device with the i2c library in gcbasic Version 0.9 14/2/2010. After fiddeling around with ports to figure out which are neutral on the velleman board as well as setting pull up resistors it works almost perfectly. But only each second time when reading the temperature. The other reading is a constant (3). When looking closer with the oscilloscope it seems to there is a stop bit missing after reading the LSB of the temperature. The SDA line is keept LOW. The stopcommand doesn't seem to go through, not even when I add another stopcommand after the first, or a 50us pulse on the SDA port (see code below). There seems to be no response, thus somebuddy is already pulling there.
One reason could be that the pic keeps the bit low after reading due to some timeout in the read code, Could it be that DS1621 doesn't understand the NACK bit sent from the PIC and waiting on that?. I thought a stop command and a start command would override the ACK NACK handshaking. Tthe DS1621, can read commands and send the correct temperature each second time. In the non correct reading a high bit is set in the middle of all clockpulses, thus it seem that the communication is waking up and sends a constant after that. Putting in waits up to 5 seconds doesn't make and difference. I have changed the DS1621 with another one, and also implementent the circuit on a breadboard without any change.
'sends address to the device this all pin ground
I2CSend 0xAC
'Send control to access config register
I2CSend 0x02
'Send config continuois conversion and active high polarity
I2CStart
I2CSend 0x90
'sends address to the device this all pin ground
I2CSend 0xEE
I2CStop
Do Forever
'Start reading temperature
I2CStart
I2CSend 0x90
Wait 100 us
I2CSend 0xAA
Wait 100 us
I2CStart
I2CSend 0x91
Wait 100 us
I2CReceive TEMPERATURE
Wait 100 us
I2CReceive Tempfraction
'Tempfraction is not used
Wait 100 us
I2CStop
' Send an extra high bit on SDA to simulate the stop bit when doesn't seem to be send
PulseOut I2C_DATA, 50 us
'Pulse Leds for temperature Long flash for decades of celsius short other led for last digit temp
Tendeg = TEMPERATURE / 10
Deg = TEMPERATURE - Tendeg * 10
For i = 1 To Tendeg
PulseOut Dig10, 1 s
Wait 500 ms
Next
For i = 1 To Deg
PulseOut Dig, 500 ms
Wait 500 ms
Next
Loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No I haven't. I put the project on the shelf, aftter trying different ways, since I wasn't able to figure out this peculiar behavoiur. Hav sometimes look into Gbasic to see if something has changed. Do you have any ideas?
Ulrik
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello I am trying to a pic 16F628 to read a ds1621 temperature device with the i2c library in gcbasic Version 0.9 14/2/2010. After fiddeling around with ports to figure out which are neutral on the velleman board as well as setting pull up resistors it works almost perfectly. But only each second time when reading the temperature. The other reading is a constant (3). When looking closer with the oscilloscope it seems to there is a stop bit missing after reading the LSB of the temperature. The SDA line is keept LOW. The stopcommand doesn't seem to go through, not even when I add another stopcommand after the first, or a 50us pulse on the SDA port (see code below). There seems to be no response, thus somebuddy is already pulling there.
One reason could be that the pic keeps the bit low after reading due to some timeout in the read code, Could it be that DS1621 doesn't understand the NACK bit sent from the PIC and waiting on that?. I thought a stop command and a start command would override the ACK NACK handshaking. Tthe DS1621, can read commands and send the correct temperature each second time. In the non correct reading a high bit is set in the middle of all clockpulses, thus it seem that the communication is waking up and sends a constant after that. Putting in waits up to 5 seconds doesn't make and difference. I have changed the DS1621 with another one, and also implementent the circuit on a breadboard without any change.
I supply a picture on a almost corrects reading with the missing stopbit http://picasaweb.google.com/lh/photo/Yrnid5FBUhhNTObBgyGCJA?feat=directlink
and a picture with the following erronous reading.
I would appreciate help or advice to find how to deal with this.
Ulrik
Here is the code:
;Chip Settings
#chip 16F628,4
;Defines (Constants)
#define I2C_MODE Master
#define I2C_DATA PORTA.2
#define I2C_CLOCK PORTA.3
#define Dig10 PORTB.4
#define Dig PORTB.5
'Setup DS1621 device--------------------------
I2CStart
I2CSend 0x90
'sends address to the device this all pin ground
I2CSend 0xAC
'Send control to access config register
I2CSend 0x02
'Send config continuois conversion and active high polarity
I2CStart
I2CSend 0x90
'sends address to the device this all pin ground
I2CSend 0xEE
I2CStop
Do Forever
'Start reading temperature
I2CStart
I2CSend 0x90
Wait 100 us
I2CSend 0xAA
Wait 100 us
I2CStart
I2CSend 0x91
Wait 100 us
I2CReceive TEMPERATURE
Wait 100 us
I2CReceive Tempfraction
'Tempfraction is not used
Wait 100 us
I2CStop
' Send an extra high bit on SDA to simulate the stop bit when doesn't seem to be send
PulseOut I2C_DATA, 50 us
'Pulse Leds for temperature Long flash for decades of celsius short other led for last digit temp
Tendeg = TEMPERATURE / 10
Deg = TEMPERATURE - Tendeg * 10
For i = 1 To Tendeg
PulseOut Dig10, 1 s
Wait 500 ms
Next
For i = 1 To Deg
PulseOut Dig, 500 ms
Wait 500 ms
Next
Loop
Were you able to solve this problem?
George
Were you able to solve this?
No I haven't. I put the project on the shelf, aftter trying different ways, since I wasn't able to figure out this peculiar behavoiur. Hav sometimes look into Gbasic to see if something has changed. Do you have any ideas?
Ulrik