Creating a Library for PCA9685 PWM module Part 1: Getting the Required Information

In this guide, we shall see how to build a library to PCF9685.

In this guide, we shall cover the following:

  • Introduction.
  • Getting the datasheet.
  • Gathering the information.
  • Connection.
  • STM32CubeIDE setup.

1. Introduction:

The PCA9685 is a versatile 16-channel, 12-bit PWM controller widely used in applications requiring precise control of servos, LEDs, or other devices. It communicates via the I2C protocol and can independently control up to 16 outputs with a resolution of 12 bits. This makes it ideal for robotics, lighting, and general automation tasks. The module simplifies PWM generation, freeing up the microcontroller for other tasks.

2. Getting the Datasheet:

To work effectively with the PCA9685, it is essential to refer to its datasheet. The datasheet provides detailed information on the module’s features, registers, and electrical characteristics. You can download the datasheet from the official NXP website or from reliable electronics documentation repositories. Familiarize yourself with the following sections:

  • Pin Description: To understand the purpose of each pin.
  • Register Map: For configuring and controlling the module.
  • Electrical Characteristics: To ensure compatibility with your STM32 microcontroller.

You can get the datasheet from here.

3. Gathering the Information:

From the datasheet, we can the find the following data:

Block Diagram:

Feel free to dig deeper into the datasheet for more details.

4. Connection:

The connection of the module as following:

Since the board used in this guide is STM32F411RE Nucleo-64.

The board features Arduino Uno pinout, D14 and D15 features I2C pins as shown below:

These pins can be found in the pinout in the user manual of STM32 Nucleo-64 boards (MB1136) as following:

  • PB8(D15) is SCL which is Serial Clock.
  • PB9(D14) is SDA which is Serial Data.

PCA9685STM32F411 Nucleo-64
Vcc5V
GNDGND
SDAPB9
SCLPB8
OEPA0

5. STM32CubeIDE Setup:

Open STM32CubeIDE after selecting the workspace and create new project as following:

Select the MCU:

Give the project a name:

Make sure the Targeted Project Type is STM32Cube, Language is C and binary type is Executable.

After that, set PB8 and PB9 for I2C1 or I2C3, here we shall use I2C1 as following:

Also, set PA0 as GPIO output.

Next Enable I2C1 as following:

From parameter Settings of I2C1 enable the fast mode as following:

From Clock Configuration tab, set the frequency to maximum of 100MHz as following:

From Project Manager tab, select Code Generation and enable Generate peripheral initialization as pair of .c/.h files per peripheral as following:

Thats all for the configuration.

Save the project and this will generate the project.

In part 2, we start developing the library.

Happy coding 😉

Add Comment

Your email address will not be published. Required fields are marked *