MCUXpresso tutorial: I2C using the Pins/Clocks/Peripherals Config tools and lpcxpresso55s69 SDK

I selected the Bosch BME280 environmental sensor as the heart of my OKdo E1-based weather station. It is convenient to use, and I can prototype with the Mikroe Weather Click board MIKROE-1978. But the sensor is accessed over I2C, and that is my least favourite of the communication interfaces. In this short tutorial, I show you how the MCUXpresso Config tools (Pins, Clocks, Peripherals) are used to set up the I2C driver from the MCUXpresso lpcxpresso55S69 SDK. And very quickly, I am able to communicate with the BME280 sensor.

Reading BME280 “ID” register via I2C

The OKdo E1 board has I2C brought to the expansion header, labelled as FC4_SCL and FC4_SDA in the diagram. For reference, note that these signals are multiplexed onto pads named PIO1_20 and PIO1_21.

I2C is available on FlexComm4 signals on expansion header

I created a new project in MCUXpresso IDE v11.1.0 based on SDK lpcxpresso55s69 v2.7.0 using the New SDK project wizard. It was not necessary to make any changes to the project, and I named in LPC55S69_WeatherStation in the wizard.

CLOCKS CONFIG

We can quickly re-use the tutorial from last week to configure the clocks for the project. Running the Clocks tool…:

Open Clocks configuration tool

… allows us to switch to the Clocks Diagram tab, and then use the Functional Groups Properties icon to edit the functional groups in the project. I added a new functional group, named BOARD_BootClockPLL150M_FRO12, and configured the PLL to be referenced from the clock named fro_12m. Refer back to last week’s tutorial for full details, and don’t forget to select your new Functional Group in the dropdown box at the top of the perspective.

All that remains it to enable the clock to FlexComm4, since this is the FC module that we’ll use for I2C. I used the fro_12m as the clock source for I2C.

Enabling fro_12m as clock source for FlexComm4

PINS CONFIG

Well, that completes the clock configuration. We can use the icons in the top right of the Clocks Config perspective to switch to the Pins view:

Switching to Pins Config tool

Recall that the I2C signals are on pads PIO1_20 and PIO1_21. In my tutorials, I’ll always use the word PAD to mean one of the ports (with a name like PIO1_20 in this case). Depending upon the package (BGA, QFN, LQFP…) that pad will be routed to a pin. On the OKdo E1 board the package is LQFP100, and pad PIO1-21 is routed to pin 4. Pin 4 has many possible multiplexed functions. We use the Pins Config tool to select which of these pad functions is brought out to the pin.

We can configure pads PIO1_20 and PIO1_21 for their I2C functions (I2C_SCL and I2C_SDA, respectively) in the Pins Config tool. Simply search for each pad in the Pins view:

Searching for PIO1_20 in Pins view

In the diagram above, I already have PIO1_20 routed for I2C function (it is showing green). However, you’ll want to check the checkbox in the first column to mark the pin for routing. A dialog pops up, offering you all the possible pin multiplex functions for the pad. Scroll down through the list and select FlexComm4’s SCL function:

Routing PIO1_20 for FC4_SCL function.

When you put a checkmark (“tick”) in the FC4_TXD_SCL row, the Pins Config tool routes the pad, and you’ll see a new entry (in yellow) in the Routed Pins view at the bottom of the perspective:

Pin 4, pad PIO1_20 routed for function FC4_SCL function.

Follow the same procedure to route PIO1_21 for function FC4_SDA. That’s already done in the screen-grab above, and so I’m ready to move to the final, Peripherals Config tool.

PERIPHERALS CONFIG

Use the Peripherals icon to switch to the Peripherals perspective:

Switching to Peripherals config tool

The Peripherals Config tool identifies that we’ve set up the pads/pins for FlexComm4 to be used as I2C. But we have not yet set up the I2C peripheral, and so the tool reports a Warning (there is also a warning for the default console UART on FC0 but we can ignore this):

“Peripheral FC4 is not initialised” warning.

There is a very simple fix, proposed by the tool. Select the FC4 warning line, and right-click to bring up a context menu:

“Peripheral FC4 is not initialised” warning and Quick Fix

Selecting “Initialize FLEXCOMM4 peripheral” opens a dialog where we can select the desired function for FlexComm4… in this case we want I2C configuration. So we select I2C and click [OK]:

Quick Fix for I2C.

The Peripherals Config tool displays the Flexcomm Interface I2C configuration screen. This shows all of the ‘top level’ settings for the I2 C module. We have one change to make: we will use the Mode named “Transfer”. At the Mode dropdown box, select “Transfer” and note that further settings are enabled/displayed.

Select FlexComm4 I2C “Transfer” mode

I promise you, that is all we need to do. Configuration is now complete for I2C on the OKdo E1 board. We can click “Update Code” at the top of the screen to generate all of the necessary configuration code, accept the changes, and return to the C/C++ Develop perspective.

SOFTWARE…

We do (of course) need to write some software to make the Bosch BME280 sensor come alive. You can refer to my YouTube video for this tutorial to see the software in action, but here is a quick summary of the changes, and the file is here. All edits are in the “C” source module named LPC55S69-WeatherStation.c that the new project wizard created:

That should all compile and download to the board. Assuming that you connected the OKdo E1 board up to your sensor board, this is the output you’ll get from semi-hosting console view:

Semihosting Console window output from OKdo E1 board.

The tools make it look quite hard, but once you’ve used them, it all becomes obvious and efficient. In my online video tutorial I go through the steps in about 10 minutes. You can watch it here:

Next time we’ll read some more data from the BME280 sensor over I2C and start to get some real environmental data into my Weather Station. See you then, and feel free to let me know how you get on!

1 thought on “MCUXpresso tutorial: I2C using the Pins/Clocks/Peripherals Config tools and lpcxpresso55s69 SDK

  1. Pingback: MCUXpresso SDK Tutorial – using I2C Driver on OKdo E1 board | MCU on Eclipse

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.