PIC Curiosity Nano and the TC74 I2C Temp Sensor

Objectives

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.

Resources

Critical Information and Concepts

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.

Steps

Breadboard Preparation

Add the following peripherals:

  1. Open up the Microchip TC74 series datasheet

    1. Start by reviewing the full document.

    2. Bring up the full part number for the TC74 you wrote down earlier.

    3. 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 #

  1. Connect the TC74 Module to the Curiosity Nano

    1. 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

    2. Connect the TC74 power and ground pins to power and ground, respectively.

    3. 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.

MCC Setup

  1. 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.

  2. 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

      • Clock: Configure your system clock to use the HFINTOSC at 4MHz with a clock divider of 4.
      • Clock divider:keep at 4
      • Disable watchdog timer (unused)
      • Disable low-freq programming
    • Pin Manager: Grid View

      • In the Pin Manager, make sure that the Package matches the package of the PIC you are using.
    • Pin Module - N/A

    • System Interrupts Page

      • Ensure the TMRX and IOC receive interrupts are enabled. Make sure the timer subsystem is at the top.
    • 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

      • SCL/SDA: Ensure that “output” is deselected.
    • Pin Manager: Grid View

    • Add a UART component for debugging purposes (optional)

  1. Generate the MCC configuration and compile the project.

New Code

  1. Open “main.c”.

  2. Next to the other include lines, include the i2c example header file, “mcc_generated_files/examples/i2cX_master_example.h”

  3. 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 to 0xA5 or 165 within MPLabX.

  4. 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.

    1. 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.

    2. 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.

  5. 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.

  6. 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       "
  1. Compile and download your code to the Curiosity Nano. Blow on the sensor. Can you make the temperature go up?