Please enable JavaScript to view this site.

How this block appears in a Simulink model?

i2c_master_block_1

What can be configured?

i2c_master_block_2

Configuration Parameter

Selectable Option/Value

Description

Mode

Normal -- Continuous

Normal: Initialize & Deinitialize I2C driver every time a I2C block is used.

Continuous: The I2C driver will be initialized only once

I2C driver port

0--1

Select driver port

Clock Frequency (kHz)

100--400

Specify clock speed of selected I2C module configuration.

SDA pin

 

Select pin for I2C SDA, The available list of pins will be adjusted according to the target family selected in the Target Setup Block

SDA internal pullup

 

Enable/disable internal pullup

SCL pin

 

Select pin for I2C SCL, The available list of pins will be adjusted according to the target family selected in the Target Setup Block

SCL internal pullup

 

Enable/disable internal pullup

Bytes write count

 

Specify number of bytes to write to I2C in a transaction.

Bytes read count

 

Specify number of bytes to read from I2C in a transaction.

Enable I2C scan device ESP log message.

 

Enable this to scan all i2c devices connected and display their slave addresses. To use this, feature a serial monitor is required.

Sample time (sec)

-1 (inherited) or specify

Specify sample time for the block

i2c_master_block_3

INPUT/ OUTPUT Port

Port Name

Port Type

Date Type

Description

Slave address

Vector

uint8

Slave device address

Wr(i) (uint8)

Scalar

uint8

Bytes that need to be sent to the above specific slave address

Status

Scalar

uint8

Read or Write byte status. If error = -1 or Ok = 0

Rd (uint8)(i)

Scalar

uint8

Bytes that need to be read by the above specific slave address

When to use this block?

This block can be used to communicate with a device using I2C protocol

Demo

Target module Demo file : esp32_i2c_4_20mA_demo.slx

i2c_master_block_4

 

Subsystem ADS1115

I2C blocks used to read values from aMG ESP32 4-20mA Module

i2c_master_block_5

Description

This demo shows how to use the I2C master block to get the reading from the external I2C ADC module and read the data from CMD console in every 1s.

Hardware Setup

1.aMG ESP32 4-20mA Module

What should be happening?

Once the model is uploaded to the ESP32. It should start the data reading from the ESP32 as shown below.

Note:

Serial Monitor used: Docklight

Baud Rate: 115200

i2c_master_block_6

Copyright 2022 Aimagin Co.,Ltd. Rev.605