• Post author:
  • Reading time:4 mins read
  • Post category:Tutorials

The PCF8591 is a single-chip, single-supply low-power 8-bit CMOS data acquisition device with four analog inputs, one analog output and a serial I2C-bus interface.

The functions of the device include analog input multiplexing, on-chip track and hold function, 8-bit analog-to-digital conversion and an 8-bit digital-to-analog conversion. The maximum conversion rate is given by the maximum speed of the I2C-bus.

Fig: PCF8591

Main Features:

  • Single power supply
  • Operating supply voltage 2.5 V to 6.0 V
  • Low standby current
  • Serial input and output via I2C-bus
  • I2C address selection by 3 hardware address pins
  • Max sampling rate is given by I2C-bus speed
  • 4 analog inputs configurable as single ended or differential inputs
  • Auto-incremented channel selection
  • Analog voltage range from VSS to VDD
  • On-chip track and hold circuit
  • 8-bit successive approximation A/D conversion
  • Multiplying DAC with one analog output.


Here, I2C protocol is used.

Step 1: What You Will Need

  • Arty7 35t/100t board with either pinaka, parashu or vajra programmed
  • PCF8591.
  • Micro USB Cable.
  • Jumper Wires.
  • shakti-sdk and shakti-tools installed or Platform IO installed and ready

Step 2: The Circuit

Connection of PCF8591 sensors:

  • VCC connect to +2.5V to +6.0V
  • GND to GND
  • SCL to SCL
  • SDA to SDA
Fig. Circuit diagram for PCF8591 with arty7 100t board

Here we use Arty100t for instance. Also, the connections are the same in Arty35t boards. For better clarity, Check the device pin mapping for pinaka, parashu and vajra.

Step 3: Code

Please click here to have a look at the code of PCF8591.

Code can be compiled and run using the following ways,

Step 4.1: Manual Method

4.1.1 Compile and build

  • Move to shakti-sdk
cd shakti-sdk
  • Compile using make software PROGRAM=? TARGET=?. Type make list_applns to list all the applications available in the SDK. Target can be either parashu, pinaka or vajra.

For instance, Use target as parashu,

make software PROGRAM = pcf8591 TARGET=parashu

4.1.2 Execution:

Once the application is built, the executable is generated in the output folder. The executable is in ELF file format and they have the extension .shakti. Now, open three terminals, one for each of the following,

  • One terminal for UART terminal display (miniterm)
  • Another for GDB server
  • And the last one for OpenOCD.

Terminal 1: Firstly Connect to serial output by using miniterm or gtkterm with the baud rate of 19200.

For instance,

$ sudo miniterm.py /dev/ttyUSB1 19200


  • “/dev/ttyUSB1” – ttyUSB means “USB serial port adapter”
  • The “1” (“0” or “1” or “2”“here means the USB device number on your system. The FPGA board is connected to that USB device number.

Terminal 2: After that, Connect to the FPGA board by using the OpenOCD provided by shakti-tools and its respective configuration file.  (Read how OpenOCD and RISC-V GDB work together to establish a connection between our PC and the Microprocessor)

For instance, if we use parashu,

$ cd shakti-sdk
$ cd ./bsp/third_party/parashu
$ sudo $(which openocd) -f ftdi.cfg

For pinaka and vajra, Goto cd ./bsp/third_party/<pinaka or vajra>

Terminal 3: Now, open either 32-bit or 64-bit RISC-V GDB based on your architecture i.e riscv32-unknown-elf-gdb or riscv64-unknown-elf-gdb respectively from shakti-tools.

The output executable is created in <path-to-shakti-sdk>/software/examples/i2c_applns/pcf8591/output as pcf8591.shakti.

Load up the .shakti file by following the below steps,

$ riscv32-unknown-elf-gdb
(gdb) set remotetimeout unlimited
(gdb) target remote localhost:3333
(gdb) file path/to/executable
(gdb) load
(gdb) c

4.1.3 Upload to flash

Steps to generate standalone user application:

The SHAKTI-SDK has a uploader tool that is used to load a content (such as ELF) to flash, after building the image.

  • Goto the right directory.
    cd shakti-sdk
  • Use make upload command to build and upload the application to the flash automatically.
make upload PROGRAM = pcf8591 TARGET=parashu

PROGRAM is the new bare metal user application that is created. Type make list_applns to list all the applications available in the SDK.

Step 4.2: Using Platform IO

We can use IDE’s like Platform IO to compile, build, run, upload and debug. Please read the article on Platform IO on SHAKTI to understand the steps.

Miniterm Output

Miniterm Output (Upload):

  • Now press Reset Button on board

Leave a Reply