Changing I2C alternate pin function

We incorrectly mapped the I2C using an alternate pin configuration and therefore cannot use the default base image.

Please find the mapping we have -

I2C1 SCL – pin 96
I2C1 SDA – pin 75

I2C2 SCL – pin 88
I2C2 SDA – pin 86

I2C3 SCL – pin 81
I2C3 SDA – pin 94

When we use the GPIO tool to set Pin 96 and Pin 75 we cannot find any devices using the I2C tool. When we put a scope on the clock line we see the line stay low until it times out then goes high.

Any suggestions?

Thanks,
Matt

Dear @mfratkin

Background

Let me give you some background information to explain why there is a problem:

On the iMX7, the library relies on underlying i2c drivers. The pin configuration can be modified at the driver load time only.
The i2c driver is loaded either

  • on system boot, if the registry is configured to do so, or
  • in the first call to I2c_Open()

Pins 96 and 75 belong to the physical i.mx7-i2c instance i2c4. This is the same instance which is available on pins 194 and 196 by default (The default i2c pins for any Colibri module). The external RTC on the Evaluation Board is connected to these pins.

Because it is the default instance, we call it [HKLM\Drivers\Builtin\I2C 1] in the registry (sorry for the potential confusion).

What Happens

During System Boot, the I2C1 driver is loaded for two reasons:

  1. The registry entry at [HKLM\Drivers\Builtin\I2C1] is configured to load this driver
  2. Due to [HKLM\Init\Launch48], the rtcsync.exe tool is loaded, which would also load the I2C1 driver to communicate with the external RTC.

As the driver is already loaded when your application kicks in, you cannot change the pinout anymore.

Solution

Put the following statements into the registry

[HKLM\Drivers\Builtin\I2C1]
SclPin = dword:96
SclAF = dword:0
SdaPin = dword:75
SdaAF = dword:0

This will cause the system to load the driver with the correct pinout from beginning on, therefore also RtcSync.exe will use these pins to communicate with the RTC.

By the way: to check the pin multiplexing you can launch the Gpio Tool.

Regards,
Andy

Hello @andy.tx ,

Thanks for the information. We made the changes and still see the clock line equally the data line and it cannot find the devices that are attached. We will look into our code again to see if there is anything off.

I am assuming we can make the same registry changes for the other I2C buses?

[HKLM\Drivers\Builtin\I2C3]
 SclPin = 81
 SclAF = 0
 SdaPin = 94
 SdaAF = 0

Thanks,
Matt

Hi @mfratkin

  • Did you connect pull-up resistors to the clk/data signals?
  • Please use the Gpio tool to verify that the alternate function of pins 96 and 75 are changed to i2c4.sda and i2c4.scl.
  • Enabling the debug messages and monitoring them on a terminal program might give some insights, if errors happen
  • Yes, you can change the registry for the other i2c buses too. But then you also need to insert the Dll=... value equal to the I2C1 setting in order to load the driver.
    As an alternative you can define the pinout in your application as we do it in the i2c_Demo application which comes with the libraries. Because these other i2c drivers are not loaded during the boot process, the driver will be loaded on I2c_Open(), after you configured the desired pinout…

Regards, Andy

@andy.tx ,

We made a mistake on our end (set the registry’s to strings not DWORD). We now have both I2C1 and I2C3 working using the I2C demo application.

Thanks,
Matt

Dear @mfratkin

I’m glad to hear that it is working now.
I edited my previous answer and inserted the dword: in order to clarify the required type.

Regards, Andy