Driver library to interface with XENSIV™ PAS CO2 Carbon Dioxide sensor in ModusToolbox™
XENSIV™ PAS CO2 sensor

Overview

This library provides functions for interfacing with the XENSIV™ PAS CO2 sensor.

The sensor features a small form factor with accurate and robust performance at ppm level (±30 ppm ±3% of reading). The XENSIV™ PAS CO2 sensor integrates a photo-acoustic transducer and a microcontroller which runs ppm calculations as well as compensation and configuration algorithms on the PCB.

Quick start

For the hardware setup, check the "Quick start with the PSoC™ 6 Wi-Fi Bluetooth® pioneer kit" section of the Programming guide for XENSIV™ PAS CO2 sensor.

Figure 1. XENSIV™ PAS CO2 Sensor2Go kit I2C interface connection to the PSoC™ 6 Wi-Fi Bluetooth® pioneer kit

Alternatively you can use the CYSBSYSKIT-DEV-01 Rapid IoT Connect Developer Kit together with the XENSIV™ PAS CO2 Wing Board.

Do the following to create a simple application which outputs the CO2 ppm data from the sensor to the UART.

  1. Create an empty ModusToolbox application for your board, e.g. CYSBSYSKIT-DEV-01.
  2. Add this library, i.e. sensor-xensiv-pasco2, to the application using the Library Manager.

    Figure 2. Library Manager

  1. Add the retarget-io library using the Library Manager.
  2. Place the following code in the main.c file.
  3. Define I2C SDA and SCL as appropriate for your hardware configuration. Note If using CYSBSYSDEV-DEV-01 kit and PAS CO2 wingboard, define macro USE_CYSBSYSDEV_KIT_01_WINGBOARD
  4. Connect the board to your PC using the provided USB cable through the KitProg3 USB connector.
  5. Open a terminal program and select the KitProg3 COM port. Set the serial port parameters to 8N1 and 115200 baud.
  6. Build the application and program the kit. After programming, the application starts automatically.

    Figure 3. Terminal output on program startup

Use the library in your own platform

The library can be used in your own platform copying following files to your project:

  • xensiv_pasco2.c
  • xensiv_pasco2.h
  • xensiv_pasco2_platform.h
  • xensiv_pasco2_regs.h.

The library depends on platform-specific implementation of functions declared in xensiv_pasco2_platform.h:

/* Target platform-specific function to perform I2C write/read transfer. Only needed if using I2C sensor interface */
int32_t xensiv_pasco2_plat_i2c_transfer(void * ctx, uint16_t dev_addr, const uint8_t * tx_buffer, size_t tx_len, uint8_t * rx_buffer, size_t rx_len);
/* Target platform-specific function to read over UART. Only needed if using UART sensor interface */
int32_t xensiv_pasco2_plat_uart_read(void *ctx, uint8_t * data, size_t len);
/* Target platform-specific function to write over UART. Only needed if using UART sensor interface */
int32_t xensiv_pasco2_plat_uart_write(void *ctx, const uint8_t * data, size_t len);
/* Target platform-specific function that waits for a specified time period in milliseconds */
void xensiv_pasco2_plat_delay(uint32_t ms);
/* Target platform-specific function to reverse the byte order (16-bit) */
uint16_t xensiv_pasco2_plat_htons(uint16_t x);
/* Target platform-specific function that implements a runtime assertion; used to verify the assumptions made by the program and take appropiate actions if assumption is false */
void xensiv_pasco2_plat_assert(int expr)
Target platform-specific function that implements a runtime assertion; used to verify the assumptions...
uint16_t xensiv_pasco2_plat_htons(uint16_t x)
Target platform-specific function to reverse the byte order (16-bit) A sample implementation would lo...
int32_t xensiv_pasco2_plat_uart_read(void *ctx, uint8_t *data, size_t len)
Target platform-specific function to read over UART.
void xensiv_pasco2_plat_delay(uint32_t ms)
Target platform-specific function that waits for a specified time period in milliseconds.
int32_t xensiv_pasco2_plat_i2c_transfer(void *ctx, uint16_t dev_addr, const uint8_t *tx_buffer, size_t tx_len, uint8_t *rx_buffer, size_t rx_len)
Target platform-specific function to perform I2C write/read transfer.
int32_t xensiv_pasco2_plat_uart_write(void *ctx, uint8_t *data, size_t len)
Target platform-specific function to write over UART.

See an implementation for the platform-specific functions in xensiv_pasco2_mtb.c using the PSoC™ 6 HAL.

More information


© Infineon Technologies AG, 2021-2022.