The goal of this tutorial is to introduce you to the timer subsystem, implement a timer using an interrupt-based design, and use that timing to perform some I$^{\text{2}}$C communication with the TC74 Temperature Sensor.
Critical Information and Concepts | Importance |
---|---|
Clock Frequency: ensure compatibility with the Microchip TC74 series datasheet | If the clock frequency is not within the specifications, it may not work |
Find the TC74 Series temperature sensor in your kit. Note (and write) down the full part number for reference. | The part number determines the address you need to program into I$^{\text{2}}$C code. |
Find the address for your specific TC74 chip in “Section 5: Packaging markup” of the TC74 series datasheet. The address is different for each package #, and is represented as a binary number. Note (and write) down the address (in binary) for reference later in the project. | You can communicate with many different devices on the same I$^{\text{2}}$C bus, but each device needs to be numbered differently |
Note: Don’t just use the default address without checking against your part # | |
In the DC Characteristics section of the TC74 series datasheet, note the minimum and maximum value for the I2C Clock Frequency. | Make sure you do not exceed this range in your MCC setup. |
Select the proper pins for SDA and SCL according to the PIC18F47Q10 Hardware User Guide | You may only use certain pins for I$^{\text{2}}$C communication, so plan ahead. |
Add the following peripherals:
Open up the Microchip TC74 series datasheet
Start by reviewing the full document.
Bring up the full part number for the TC74 you wrote down earlier.
Find the address for that specific device in “Section 5: Packaging markup”. This will be given as a binary number. Note (and write) down the address (in binary) for reference later in the project.
Note: Don’t just use the default address without checking against your part #
Connect the TC74 Module to the Curiosity Nano
Look at the Hardware User Guide to find compatible pins for I2C SDA and SCL pins that do not conflict with other peripherals you will need
Connect the TC74 power and ground pins to power and ground, respectively.
Connect the Curiosity Nano and TC74 SDA pins.
Note: this line should be pulled high by a resistor. Please see this TI I$^{\text{2}}$C Pullup Calculation Application Report to understand the decision-making process. Practically speaking, a 10kOhm resistor should work.
d. Connect the Curiosity Nano and TC74 SCL pins.
Note: this line should be pulled high by a resistor. Please see this TI I$^{\text{2}}$C Pullup Calculation Application Report to understand the decision-making process. Practically speaking, a 10kOhm resistor should work.
Launch MPLAB® X and create a new project for your PIC IC. Note: Please remember that this is an individual assignment. The only way to learn to code independently is to work through coding problems and figure them out.
Open MCC and update the following settings:
Please use MCC Classic. We can support it better, it has more advanced configuration options, but is also still relatively easy to use.
System
Pin Manager: Grid View
Pin Module - N/A
System Interrupts Page
MSSPX
Taking a look at the PIC18F47Q10 Hardware User Guide, pick the MSSP system that enables you to also use the other MSSP peripheral for SPI communication next week.
Select “Interrupt Driven”.
Clock Frequency: ensure compatibility with the Microchip TC74 series datasheet
Slew Rate Control
Pin Module
Pin Manager: Grid View
Add a UART component for debugging purposes (optional)
Open “main.c”.
Next to the other include lines, include the i2c example header file, “mcc_generated_files/examples/i2cX_master_example.h”
define a macro (using #define) to declare the address for the 74 temperature sensor you found earlier
Note: you can directly write binary or hexadecimal numbers directly by beginning a number with “0b” or “0x”
Example:
0b10100101
is equivalent to0xA5
or165
within MPLabX.
Open up the “mcc_generated_files/examples/i2cX_master_example.h” and review it. Identify within this header file the 7 example functions given for reading or writing data over i2c.
Next, eliminate some of those functions by going over the TC74 series datasheet. Will you be reading, writing or both? Will you be reading/writing 1 byte or two bytes?
Note: upon reviewing the TC74 datasheet, if you set up MCC as suggested above, you should not have to worry about defining custom timing sequences or accessing MSSP-specific register bits. This is handled internally by the I$^{\text{2}}$C library.
Select one or more of the functions not eliminated and implement it. Note that some of these functions require the use of pointers. You will need to create new variables in order to get this function to work. More than one of these functions will work.
Note: You will need to review the TC74 series datasheet for information about which registers to read/write, and the number of bytes of each value.
Note: With regard to constructing the right I$^{\text{2}}$C address, The MPLabX I$^{\text{2}}$C library handles all register bit-shifting and read/write bit conventions.
Review the TC74 series datasheet. It specifies the format by which to convert the received temperature data into a positive/negative value. Implement a function that performs this conversion.
Update your print to the LCD to include the current temperature, including the code necessary to correctly compute temperatures in the negative Celsius range. Print the temperature on the second line of the LCD
Example:
"t= 45.34s "
"temp= 32C "