Demonstrating 8-bit I2C Controller Read
Objective
This tutorial shows how to configure the PIC1847Q10 I2C (Inter-Integrated Circuit) feature using Microchip’s MPLAB® Code Configurator (MCC). MCC is used to configure Core Independent Peripherals (CIPs) such as I2C and EUSART (Enhanced Universal Synchronous Asynchronous Receiver Transmitter). It also demonstrates how to leverage Foundation Services to switch to an ATmega4809 MCU without modifying any source code.
Overview
This tutorial makes use of Microchip’s PIC18F47Q10 Curiosity Nano Platform, Curiosity Nano Base for Click boards™ and MikroE’s Thermo J Click to simplify hardware integration. It also showcases the capability of MCC I2C Foundation Services to switch to the ATmega4809 with no changes to the application code. This tutorial will use the ATmega4809 Curiosity Nano board to demonstrate this.
I2C (Inter-Integrated Circuit) is a serial communication protocol used to connect devices to a microcontroller or computer. It allows multiple devices to communicate with each other using only two wires (SDA and SCL) and requires a controller device to initiate communication. I2C supports multiple devices on the same bus, each with a unique address, and allows for multi-controller communication for added flexibility. The protocol uses a Controller-Target relationship, with the Controller initiating data transfer and the Target responding to requests. The I2C protocol is widely used in embedded systems due to its simplicity and low cost.
MPLAB Code Configurator (MCC) is a free graphical programming environment that generates seamless, easy-to-understand C code that is inserted into your project. It enables and configures a rich set of CIPs and functions using an intuitive interface. It is integrated into MPLAB X IDE to provide a powerful and easy-to-use development platform.
In this training, the PIC18F47Q10 I2C CIP will be configured for Controller mode to read temperature from the Thermo J Click. Next, the MCC I2C Foundation Services will be leveraged to change the MCU to the ATmega4809 without modifying the application source code.
Both the PIC18F47Q10 Curiosity Nano Platform (DM182029), Curiosity Nano Base for Click boards (AC164162) and ATmega4809 Curiosity Nano (DM320115) are available from Microchip Purchasing and Client Services. The Thermo J Click (MIKROE-2811) is available from MIKROE and the J-Type Thermocouple is available from a variety of retailers including Digi-Key.
The application regularly queries the temperature stored on Microchip’s MCP9600 Thermocouple EMF to Temperature Converter located on Thermo J Click using the PIC18F47Q10 MSSP (Master Synchronous Serial Port) CIP configured as an I2C Controller. Temperature data is transferred to the EUSART and displayed by MPLAB Data Visualizer via the PIC18F47Q10 Curiosity Nano virtual serial port.
This application utilizes:
- MSSP to read the temperature from the MCP9600 via I2C
- EUSART to send data to MPLAB Data Visualizer
- General Purpose I/O (GPIO) configured for CIP operations
Two Ways to Use This Tutorial
- Create the projects from scratch:
- Follow the step-by-step instruction to create the required software
- Use the solution projects as an example:
- Build the solution projects and program them into the appropriate MCU demonstration board to observe the expected behavior
Lab Objectives
Create an MPLAB X IDE MCC project for a PIC18F47Q10 microcontroller from scratch
- Use MCC to configure and generate peripheral libraries (PLIB) code for the following CIPs:
- MSSP
- EUSART
- GPIO
- Leverage MCC I2C Foundation Services to switch application to ATmega4809
Materials
- PIC18F47Q10 Curiosity Nano Platform (DM182029)
- Curiosity Nano Base for Click boards (AC164162)
- Thermo J Click (MIKROE-2811)
- ATmega4809 Curiosity Nano (DM320115)
Apart from the hardware tools listed above, the following items are required:
- 1 USB Type-A male to Micro-B male cable for programming and debugging
- 2 28-pin 100 mil male header strips
- 2 28-pin 100 mil female header strips
- J-Type thermocouple
Connection Diagram
The application has the J-Type probe connected to the MCP9600, MSSP connected to the MCP9600 and EUSART connected to the Curiosity Nano virtual serial port for USB communication to the MPLAB Data Visualizer
Lab Solutions
This ZIP file contains the completed solution projects for this lab. The contents of this ZIP file can be placed in a folder of your choice. Both files are stored in a single GitHub repository. You will need to create a free account to download the files.
https://github.com/MicrochipTech/dh-8bit-i2c-read-demo
Lab Index
Step 1: Connect PIC18F47Q10 Hardware
- Step 1.1: Complete PIC18F47Q10 Curiosity Nano Board connections
- Step 1.2: Attach Thermo J Click
- Step 1.3: Connect Thermocouple to Curiosity Nano Base for Clicks Board
Step 2: Create and Setup MPLAB X IDE Project for PIC18F47Q10
- Step 2.1: Connect PIC18F47Q10 Curiosity Nano Board to Computer
- Step 2.2: Verify Hardware Setup
- Step 2.3: Create Project
- Step 2.4: Install MCC
Step 3: Configure PIC18F47Q10 Resources with MCC
- Step 3.1: Launch MCC
- Step 3.2: System Module
- Step 3.3: I2C
- Step 3.4: EUSART
- Step 3.5: GPIO
- Step 3.6: Generate MCC Code
- Step 3.7: Update main.c
Step 4: Build and Program PIC18F47Q10
- Step 4.1: Build Project
- Step 4.2: Program MCU
- Step 4.3: Run Project
- Step 5.1: Verify Correct Operation
- Step 5.2: Results
- Step 5.3: Analysis
Step 6: Reconfigure Demo for ATmega4809
- Step 6.1: Complete ATmega4809 Curiosity Nano Board connections
Step 7: Create and Setup MPLAB X IDE Project for ATmega4809
- Step 7.1: Connect ATmega4809 Curiosity Nano Board to Computer
- Step 7.2: Verify Hardware Setup
- Step 7.3: Create Project
Step 8: Configure ATmega4809 Resources with MCC
- Step 8.1: Launch MCC
- Step 8.2: System Module
- Step 8.3: I2C
- Step 8.4: USART
- Step 8.5: GPIO
- Step 8.6: Generate MCC Code
- Step 8.7: Update main.c
Step 9: Build and Program ATmega4809
- Step 9.1: Build Project
- Step 9.2: Program MCU
- Step 10.1: Verify Correct Operation
- Step 10.2: Results
- Step 10.3: Analysis
- Step 10.4: Conclusions
Reference Information
How Thermocouples Work