High Speed Data Transfer and In-Band Interrupts with I3C® using the PIC18F16Q20 Microcontroller and MCC Melody
This code example demonstrates how to set up the PIC18F16Q20 microcontroller as an I3C Target using MCC Melody. The demonstration shows four types of I3C transactions:
- Broadcast Common Command Code (PIC18F16Q20 receives Dynamic Address Assignment)
- Direct Common Command Code (Controller sets the PIC18F16Q20's Maximum Write Length)
- Private Write (PIC18F16Q20 receives and responds to the message LED On/Off)
- In-Band Interrupt (PIC18F16Q20 generates an interrupt on the I3C bus)
The example demonstrates high speed data transfer (12.5 Mbps) and shows how the PIC18F16Q20 can take advantage of Direct Memory Access (DMA) to reliably move data to and from its I3C buffers without the CPU.
For more details and code examples on the PIC18F16Q20 click on the following links:
- MPLAB® X IDE 6.15 or newer (MPLAB® X IDE 6.15)
- MPLAB® XC8 2.45 or newer compiler (MPLAB® XC8 2.45)
- MPLAB® Code Configurator (MCC) 5.4.1 or newer
- Microchip PIC18F-Q Series Device Support 1.23.425 or newer
- MPLAB Data Visualizer
- Binho I3C Plug-in for Saleae Logic
- PIC18F16Q20 Curiosity Nano Evaluation Kit (EV73T25A)
- Curiosity Nano Base for Click Boards™
- Any I3C Controller
- Saleae Logic Analyzer
Note: The Protocol Analyzer, Controller and PIC18-Q20 are connected to the same ground. Be careful not to create ground loops while doing this as it will interfere with the I3C bus.
The following connections are necessary for this example:
- Connect the I3C Serial Data (SDA) and I3C Serial Clock (SCL) pins of PIC18F16Q20 to the SCL, SDA pins of the Controller.
- Connect the I3C bus SCL and SDA pins to the I3C Protocol Analyzer to observe transactions in the bus.
Microcontroller Pin | Signal Description |
---|---|
RC0 | I3C SCL |
RC1 | I3C SDA |
RC4 | UART TX |
RC5 | UART RX |
RC7 | LED0 |
RA2 | SW0 |
A Curiousity Nano Adapter Baseboard provides convienent pins for connecting to both the Controller and the Protocol Analyzer.
This section explains the peripheral configuration using the MPLAB® X IDE with MCC plug-in required to recreate the project.
Additional Links: MCC Melody Technical Reference
The following peripheral and clock configurations are set up using MPLAB Code Configurator (MCC) Melody:
- Clock Source: HFINTOSC
- HF Internal Clock: 64_MHz
- Clock Divider: 1
- Tx DMA Channel Selection: DMA1
- Rx DMA Channel Selection: DMA2
- I3C PLIB Selector: I3C1
In the Module Level General Interrupt Callback Settings:
- Select Supported CCC Received Interrupt Enable
- Select In-Band Interrupt Done Interrupt Enable
- Baudrate: 9600
- Enable Redirect Printf to UART
- UART PLIB selector - UART1
- Select RC5 for UART1 RX1
- Select RC4 for UART1 TX1
- Select RA2 input for SW0
- Select RA7 output for LED0
- Rename IO_RA2 as SW0, select Weak Pull-up, and enable Interrupt on Change for the negative edge
- Rename IO_RC7 as LED0
For this project, the I3C bus is configured with a Push-Pull frequency of 12.5 MHz and Open-Drain frequency of 2.5 MHz.
Start Data Visualizer and begin capturing on your COM port.
When the PIC18F16Q20 boots up, it is operating in Legacy I2C mode while it awaits a dynamic address assignment. The following is shown in the terminal:
If using, start the protocol analyzer capture.
At this point, the Controller initiates a Dynamic Address Assigment by issuing the Broadcast CCC - ENTDAA. Once the PIC18F16Q20 receives a dynamic address it operates in I3C mode. The event is shown in the terminal:
The transaction can be decoded using the Binho I3C Protocol Analyzer.
Next the demo shows how the PIC18F16Q20 responds a Direct Common Commmand Code sent to set its Maximum Write Length (SETMWL) to 16 bytes.
The decoded signal appears as:
Next, the PIC18-Q20 receives a Private Write message to turn on its LED.
The Controller next sends a Private Write message to turn the LED off.
Decoded anlaysis shows:
In-Band Interrupts are a terrific new feature in I3C, as they eliminate the need for external signal paths, reducing the size and complexity of design. In this example, the PIC18F16Q20 sends an interrupt on the I3C bus when the user presses the on-board button. The interrupt is sent and includes both a Mandatory Byte and the optional payload.
This code example demonstrates how to set up the PIC18F16Q20 microcontroller as an I3C Target using MCC Melody and shows how it handles four common types of transactions. Data transfer to and from the I3C buffers is done using Direct Memory Access (DMA) without requiring the CPU.