Inputs: Dynamic based on I2C sequence configuration
| Port Name | Data Type | Description | Optional |
|---|---|---|---|
| Addr N | uint8/uint16 | Slave address (when using block input) | Yes |
| Write N | uint8 (vector) | Data to write to slave device | Yes |
Outputs: Dynamic based on I2C sequence configuration
| Port Name | Data Type | Description | Optional |
|---|---|---|---|
| Seq Completed | boolean | Indicates sequence completion (non-blocking mode) | Yes |
| Out N | uint8 (vector) | Data read from slave device | Yes |
Block inputs and outputs are created based on the I2C sequence you configure:
| I/O Type | Data Type | Range | Description |
|---|---|---|---|
| Address (7-bit) | uint8 | 0-127 | Standard I2C slave address |
| Address (10-bit) | uint16 | 0-1023 | Extended I2C slave address |
| Write Data | uint8 | 0-255 | Byte data to write |
| Read Data | uint8 | 0-255 | Byte data read from slave |
| Seq Completed | boolean | 0/1 | Sequence completion status |
| Family | Series | I2C Modules | Notes |
|---|---|---|---|
| dsPIC30F | All | I2C1 | Legacy I2C peripheral |
| dsPIC33F/E | All | I2C1-2 | Standard I2C with enhancements |
| dsPIC33C | CK, CH, CDV | I2C1-3 | Multi-module support |
| dsPIC33A | AK | I2C1-4 | Latest I2C peripheral (DOS-05155) |
| PIC32 | MK, MZ, MX | I2C1-5 | 32-bit I2C (DOS-01441) |
| SAM | E5x, C2x, D2x | SERCOM0-7 | I2C via SERCOM peripheral |
| SAM | E70, S70, V71 | TWIHS0-2 | Two-Wire High Speed interface |
| Parameter | Description | Options |
|---|---|---|
| I2C Module | Hardware I2C peripheral to use | I2C1, I2C2, … (device dependent) |
The I2C block uses a graphical sequence builder accessed by double-clicking the block. Available actions:
| Action | Description | Parameters |
|---|---|---|
| Initial Configuration | Set I2C clock speed and mode | Frequency, mode bits |
| Update Configuration | Change settings mid-sequence | Same as initial |
| Start | Generate I2C start condition | None |
| Re-Start | Generate repeated start | Auto-rethrows address if followed by R/W |
| Stop | Generate I2C stop condition | None |
| Write Address | Send slave address | 7/10-bit, R/W bit, constant or block input |
| Write Data | Send data bytes | Byte count, constant or block input |
| Read Data | Receive data bytes | Byte count, output port name |
| Set Pin | Control GPIO during sequence | Pin, state (0/1/toggle) |
| Delay | Insert timing delay | Delay in seconds |
| Interrupt | Trigger user interrupt | Interrupt name |
| Parameter | Options | Description |
|---|---|---|
| Blocking Mode | On/Off | On: Block waits for sequence completion. Off: Non-blocking with completion output |
| Sequence Completed | On/Off | Enable output port showing sequence status (non-blocking only) |
| Parameter | Description |
|---|---|
| SDA Pin | I2C data pin (bidirectional) |
| SCL Pin | I2C clock pin (output in master mode) |
Note: I2C pins are typically not remappable via PPS - they are fixed to specific pins or selectable via fuses.
| Parameter | Range | Description |
|---|---|---|
| Interrupt Priority | 1-7 | I2C interrupt priority level |
Clock speed is configured in the Initial Configuration action. Available frequencies depend on the peripheral clock:
| Mode | Typical Speed | Use Case |
|---|---|---|
| Standard | 100 kHz | General purpose, longer wires |
| Fast | 400 kHz | Common sensor communication |
| Fast+ | 1 MHz | High-speed peripherals |
The block automatically calculates the optimal I2CBRG register value for the requested frequency based on FCY.
The I2C sequence is executed as a state machine:
| Buffer Type | Description |
|---|---|
| Input Buffer (8-bit) | Stores data to write from block inputs |
| Input Buffer (16-bit) | Stores 10-bit addresses from block inputs |
| Output Buffer | Stores data read from slave devices |
Buffer sizes are automatically calculated from sequence configuration.
| Architecture | Peripheral | Register Naming |
|---|---|---|
| dsPIC30F/33F | Standard I2C | I2CCON, I2CSTAT, I2CBRG |
| dsPIC33E/C | Enhanced I2C | I2CxCONL, I2CxSTAT, I2CxBRG |
| dsPIC33A | New I2C (DOS-05155) | I2CxCONL, 24-bit BRG |
| PIC32 | 32-bit I2C (DOS-01441) | I2CxCON, 16-bit BRG |
| SAM E5x/C2x | SERCOM I2C | SERCOM.I2CM registers |
| SAM E7x | TWIHS | TWIHS.CWGR, TWIHS.CR |
Typical sequence for reading a temperature sensor like TMP102:
1. Initial Configuration (400 kHz)
2. Start
3. Write Address: 0x48 (Write)
4. Write Data: 0x00 (temperature register)
5. Re-Start
6. Write Address: 0x48 (Read)
7. Read Data: 2 bytes → Output "Temperature"
8. Stop
Write data to an I2C EEPROM:
1. Initial Configuration (400 kHz)
2. Start
3. Write Address: 0x50 (Write)
4. Write Data: [HighAddr, LowAddr] (memory address)
5. Write Data: [Data1, Data2, ...] (from block input)
6. Stop
Read from multiple sensors in one sequence:
1. Initial Configuration (400 kHz)
2. Start
3. Write Address: Device1
4. Read Data → Output "Sensor1"
5. Re-Start
6. Write Address: Device2
7. Read Data → Output "Sensor2"
8. Stop
Problem: No data on I2C bus.
Solutions:
Problem: Slave returns NAK (no acknowledge).
Solutions:
Problem: Slave stretches clock too long.
Solutions:
Problem: “I2C Port SCL/SDA not available” warning.
Solutions: