top of page

MicroZed Chronicles: PetaLinux I2C in the PS and AXI IIC

The sensors on the smart sensor IoT development board are connected to the programmable logic element of the Zynq-7020 device that is fitted on the board. These sensors are connected with the exact connection shown below using either a I2C or SPI interface as is common for embedded sensors

To begin creating applications on the smart sensor IoT board, I wanted to connect the I2C sensors to the processor system running PetaLinux. To do this, I am going to create a simple application which connects all the I2C sensors.

As the board was designed with minimal latency in mind, each sensor has its own dedicated I2C interface. This means the simplest method of connecting the I2C sensors to the processor system is to implement an AXI IIC controller for each of the interfaces. Note that the magnetic sensor and linear acceleration are contained in the same device and share a single I2C bus.

Once the AXI IIC interfaces have been implemented in Vivado and the XDC set correctly to map each buses SDA and SCL pins, we can generate the bit stream and export the XSA.

We can then use the exported XSA to update the PetaLinux project previously created to provide USB support and support for all the I2C interfaces just implemented.

The first thing we need to do in a terminal window inside the existing PetaLinux project is to import the new hardware definition to the project. This importation will open a new configuration dialog for the PetaLinux system. There is nothing we need to change so it can simply be saved.

We do need to ensure we have included the correct I2C drivers along with the Cadence I2C driver that supports the PS IIC. We need to make sure the kernel configuration also includes the driver for the Xilinx I2C controller which is in the programmable logic. We can enable the AXI IIC driver under the kernel configuration (petalinux-config -c kernel).

Of course, for the PetaLinux kernel to be able to access the AXI IIC IP in the programmable logic, the device tree must include the appropriate nodes. Thankfully, when we imported the updated XSA PetaLinux it also created a PL device tree. This is available under the <project>/components/plnx_workspace/device-tree/device-tree/pl.dtsi. Do not make any changes to this file because they will be lost when the project is built.

We do, however, need to set the clock rate for the IIC link and the AXI IIC status in the device tree. We do this in the system-user.dtsi under the meta-user layer of the project.

Once this is completed, we are nearly ready to build the image, however, first we need to ensure we have the I2C tools included within the root file system (petalinux-config -c rootfs).

We can check this under the file system / base menu in the root file system configuration.

With the I2C tools installed in the root file system, we can build the PetaLinux image (petalinux-build).

Once the image is built, we are able to download the image using PetaLinux and JTAG and log into the Linux session using the root/root settings for username and password.

We can then use the I2C tools to test each of the I2C interfaces in the system. The first thing to do is issue the command i2cdetect -l. This will list the I2C buses in the system.

You will notice there are three AXI IIC interfaces and one PS IIC interface in the list.

To determine which devices are connected on which bus, we can run the command i2cdetect -y-r <I2C bus>. This will scan all the addresses and shows the ones which respond. Scanning the four buses in this system shows the following:

On I2C bus 0 we can see that the magnetic and linear acceleration sensors are present as indicated by the address 0x1D and 0X1E. On bus 2, we can see the responses from the EEPROM connected to the PS IIC controller. We can see the accelerometer on bus 3.

However, you will notice bus 1 shows that nothing is connected to it when the temperature sensor is expected to be present at address 0x70.

We will examine what we do in this situation next time, as issues like this get interesting!

1 comment

1 opmerking

Chris Evers
Chris Evers
15 dec. 2021

Your article on I2C is great, is there a location where I can download the source code files?

bottom of page