Differences

This shows you the differences between two versions of the page.

tutorials:pic:pic18_i2c_ds1621 [2010/02/23 09:40]
wadef
tutorials:pic:pic18_i2c_ds1621 [2010/02/23 09:44] (current)
wadef
Line 303: Line 303:
First thing we need to do is have a place to put the temperature bytes in our code. I created 2 variables. First thing we need to do is have a place to put the temperature bytes in our code. I created 2 variables.
-<code c>+<code c 4>
 char temperatureHI = 0;  char temperatureHI = 0;
 char temperatureLO = 0;  char temperatureLO = 0;
Line 314: Line 314:
Let’s begin with StartI2C(). Let’s begin with StartI2C().
-//(I’ve removed our previous code from the following examples below. Be sure to continue +<note>I’ve removed our previous code from the following examples below. Be sure to continue 
-this following code after the configuration code and temperature conversion code)//+this following code after the configuration code and temperature conversion code. </note>
-<code c>+<code c 1>
#include <i2c.h> #include <i2c.h>
int main() int main()
Line 333: Line 333:
Next, we want to address the device again. Notice the 8th bit of 0x90 is LOW. Next, we want to address the device again. Notice the 8th bit of 0x90 is LOW.
-<code c>+<code c 1>
#include <i2c.h> #include <i2c.h>
int main() int main()
Line 351: Line 351:
According to page 10 of 16 of the DS1621 datasheet, the TEMPERATURE register is located at address AAh (0xAA). So, let’s access it. According to page 10 of 16 of the DS1621 datasheet, the TEMPERATURE register is located at address AAh (0xAA). So, let’s access it.
-<code c>+<code c 1>
#include <i2c.h> #include <i2c.h>
int main() int main()
Line 371: Line 371:
Next, initiate a restart. Next, initiate a restart.
-<code c>+<code c 1>
#include <i2c.h> #include <i2c.h>
int main() int main()
Line 393: Line 393:
Now, we’re going to read the temperature of the sensor. Notice the 8th bit of the address is now HIGH. Now, we’re going to read the temperature of the sensor. Notice the 8th bit of the address is now HIGH.
-<code c>+<code c 1>
#include <i2c.h> #include <i2c.h>
int main() int main()
Line 415: Line 415:
</code> </code>
-At this stage, the PIC will begin to pulse the clock line as usual, however, the DS1621 will take over the data line and begin sending data to the PIC’s I2C receive register. When done, the value will be stored in temperatureHI. When done, it’s the PIC’s turn to acknowledge (ACK) the device, letting the device know it has received the data. This ACK tells the device the PIC is prepared to receive a second byte.+At this stage, the PIC will begin to pulse the clock line as usual, however, the DS1621 will take over the data line and begin sending data to the PIC’s I2C receive register. When done, the value will be stored in ''temperatureHI''. When done, it’s the PIC’s turn to acknowledge (ACK) the device, letting the device know it has received the data. This ACK tells the device the PIC is prepared to receive a second byte.
-<code c>+<code c 1>
#include <i2c.h> #include <i2c.h>
int main() int main()
Line 445: Line 445:
</code> </code>
-Since the DS1621 device is made to send ALL 16 bits, we must run another ReadI2C command again. What I do is store the second set of data into another variable called temperatureLO although I’m not going to use it. I only care about the value in temperatureHI.+Since the DS1621 device is made to send ALL 16 bits, we must run another ReadI2C command again. What I do is store the second set of data into another variable called ''temperatureLO'' although I’m not going to use it. I only care about the value in ''temperatureHI''.
When done, the PIC sends a Not-Acknowledge (NotAck) to tell the device to stop sending data. Finish with a Stop command. When done, the PIC sends a Not-Acknowledge (NotAck) to tell the device to stop sending data. Finish with a Stop command.
-'' + 
-<code c>+<code c 1>
#include <i2c.h> #include <i2c.h>
int main() int main()
Line 484: Line 484:
</code> </code>
-Finally, you have configured the device and have received a temperature (with +/- sign) into a variable called ‘temperatureHI’.  The temperature value will be measured in Celcius.+Finally, you have configured the device and have received a temperature (with +/- sign) into a variable called ''temperatureHI''.  The temperature value will be measured in Celcius. 
 +
===== Entire Code ===== ===== Entire Code =====
duty free alcohol airport duty free cigs uk buy duty free cuban cigars where to buy cosmetics duty free fragrances buy tobacco duty free