Bus Pirate Edu Kit Exercise no.4
From DP
Contents |
Overview
Similar to the previous exercise no.3 here we'll read temperature as well. Only this time the TC74A1 device will convert the temperature to a readable digital format and we'll be able to read it using the Bus Pirate I2C protocol.
You can find out more about the I2C protocol here, and on the wikipedia.
The TC74 features two internal registers CONFIG and TEMPERATURE. In the CONFIG register bits 7 and 6 are the only ones functioning. Bit 7 is the 'Stand by' bit. It is set when you want the device to be in stand-by.
Bit 6 is the 'Ready' bit, it is read only, and when it is set it means a temperature value is ready to be read.
The TEMPERATURE register is read only, and holds the value of the latest recorded temperature in 2s complement.
The two registrars are internal addressed as 0 (TEMPERATURE) and 1 (CONFIG). Whether you want to read, or write to them, you always need to write the register address first as per the device protocol.
- Write algorithm: send the I2C write address followed by the register address and finally send the byte to write.
- Read algorithm
- send the I2C write address followed by the register address.
- send the I2C read address and read the byte.
The Circuit
Breadboard legend
| IC Location | Breadboard wiring legend | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
- The (+) and (-) next to PIN1 and PIN2 are intended for devices such as LEDs, where PIN1 should be the anode and connected to a higher potential then PIN2.
Bus Pirate Terminal
The TC74 IC comes in various versions. They are differentiated by the post-fix designations in their part name. The post-fix has the format A'x'-'y.y'VAT, where 'x' is used to designate the 7bit address that is used, and 'y' is used to differentiate 5V and 3.3V versions.
The device we are using is designated 'TC74A1-3.3VAT', meaning that it is calibrated for use with a 3.3V power supply. The address of the device can be found in a table in it's datasheet. 'A1' is the '0x49' 7bit unique I2C address.
When using the I2C protocol there are always two addresses one is write and the other is read. They are both derived form the unique device address, by adding a bit (0 for write, 1 for read) and creating an 8bit address. Here are the write and read 8bit addresses our device will use.
- Write address = 7bit address + 0LSB
- 0x49 = 0b1001001 => Write address = 0b1001001'0' = 0x92
- Read address = 7bit address + 1LSB
- 0x49 = 0b1001001 => Read address = 0b1001001'1' = 0x93
HiZ>m<<<the mode command
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
x. exit(without change)
(1)>4<<<select the I2C mode
Set speed:
1. ~5KHz
2. ~50KHz
3. ~100KHz
4. ~400KHz
(1)>3<<<selsct 100KHz I2C speed
Ready
I2C>W<<<turn ON the power supplies
POWER SUPPLIES ON
I2C>P<<<turn on the Pull-up resistors
Pull-up resistors ON
Once you've connected up your exercise, enter the I2C mode using the commands above. Well be using 100KHz for the I2C speed, and we'll power the device from the Bus Pirate's 3.3V power supply.
The I2C protocol hardware requires that Pull-Up resistors are used, so turn them on using the 'P' command.
I2C>(1)<<<search I2C address space macro
Searching I2C address space. Found devices at:
0x92(0x49 W) 0x93(0x49 R)
First we'll search the I2C address space to see what devices are connected using the '(1)' macro. If everything is fine you should receive '0x92(0x49 W) 0x93(0x49 R)', This means we can write using the '0x92' address, and read using '0x93'.
I2C>[0x92 1]<<<send 1 to address 0x92
I2C START BIT<<<[
WRITE: 0x92 ACK<<<0x92
WRITE: 0x01 ACK<<<0x1
I2C STOP BIT<<<]
To read the config register you need to set the read register address by sending '1' to the device.
I2C>[0x93 r]<<<read one byte from 0x93
I2C START BIT<<<[
WRITE: 0x93 ACK<<<0x93
READ: 0x40read 0x40<<<
NACK
I2C STOP BIT]<<<
Reading a register is done by sending the read address (0x93) followed by the 'r' command. From the config register we read '0x40' meaning that the 6th(ready) bit is set, and the 7th(stand by) is cleared. This means the device is not in the stand by mode, and that a temperature reading is ready.
I2C>[0x92 1 0b10000000]send 0b1000000 to 0x92 at register address 1<<<
I2C START BIT<<<[
WRITE: 0x92 ACK<<<device write address
WRITE: 0x01 ACK<<<device register address (CONFIG)
WRITE: 0x80 ACK<<<sent byte 0b10000000
I2C STOP BIT<<<]
To place the device in the stand-by mode you simply need to set the 7th bit of the CONFIG register (1). This is done by sending the write address (0x92), followed by the register address(0x01), followed by the byte you want to write (0b10000000).
I2C>[0x92 1][0x93 r]<<<select the config register and read it
I2C START BIT<<<[
WRITE: 0x92 ACK<<<device write address
WRITE: 0x01 ACK<<<device register address (CONFIG)
I2C STOP BIT<<<]
I2C START BIT<<<[
WRITE: 0x93 ACK<<<device read address
READ: 0x80<<<byte read from address
NACK
I2C STOP BIT<<<]
To check if the config register was successfully updated we again need to select the config register address (1) by sending 1 to the write address (0x92). We then proceed to read one byte from the read address (0x93).
The read byte is 0x80 which is the same one we sent, which means the device is in stand-by mode.
I2C>[0x92 1 0b00000000]send 0b0000000 to 0x92 at register address 1<<<
I2C START BIT<<<[
WRITE: 0x92 ACK<<<device write address
WRITE: 0x01 ACK<<<device register address (CONFIG)
WRITE: 0x80 ACK<<<sent byte 0b00000000
I2C STOP BIT<<<]
To exit the stand-by mode you simply need to clear the 7th (stand by) bit of the config register. the procedure is the same as when we out it into stand by, only now we send 0b00000000 to it. Repeat the verify process form above to check if the config register returns '0x00' meaning it's out of stand-by, and has a temperature byte ready.
I2C>[0x92 0][0x93 r]<<<select the temperature register and read it
I2C START BIT<<<[
WRITE: 0x92 ACK<<<device write address
WRITE: 0x00 ACK<<<device register address (TEMPERATURE)
I2C STOP BIT<<<]
I2C START BIT<<<[
WRITE: 0x93 ACK<<<device read address
READ: 0x16<<<byte read from address
NACK
I2C STOP BIT<<<]
To read the temperature byte you need to set the register address to 0 (TEMP REGISTER). And read a single byte from the read address (0x93).
The returned byte we got is 0x16 or 0b00010110. The TC74 returns the temperature in Celsius degrees using the 2s complement. When a temperature is positive the 7th bit will be 0, while the other 7 bits will form the temperature in degrees of Celsius. If the temperature is negative, the 7th bit will be 1, while the other 7 bit's complement forms the temperature in Celsius.
In our example the workshop temperature was 0x16 or 0b'0'0010110 or +22C.
I2C>m
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
x. exit(without change)
(1)>1
Ready
HiZ>
Once you're done with the exercise place the Bus Pirate in the HiZ mode. This is done by using the mode change command 'm', and selecting 'HiZ' from the menu.
Not Working?
Taking it further
To check that it really does react to temperature, you could introduce a heat source close to the IC, and look at the temperature rise. Recommended heat sources are your hands, or a cup of hot coffee or tea, Please don't use an open flame.
