Skip to main content

PSoC™ 4 code examples

Getting Started

Example

Description

Blinky

This code example blinks an LED using the PSoC™ 4 device. For more details, see the README on GitHub.

Empty PSoC4 App

This empty application provides a template for creating applications using PSoC™ 4 devices. For more details, see the README on GitHub.

Hello World

This code example demonstrates simple UART communication by printing a "Hello world" message on a terminal and blinks an LED using PSoC™ 4 devices. For more details, see the README on GitHub.

Power Modes

This code example shows how to enter system Sleep and Deep Sleep modes. After entering Deep Sleep or Sleep mode, the example also shows how to wake up from these low-power modes and return to normal Active mode. For more details, see the README on GitHub.

Peripherals

Example

Description

CAN FD

This example demonstrates how to use CAN FD in Infineon's PSoC™ 4 MCU devices. In this example, the CANFD Node-1 sends a CAN FD frame to CANFD-Node-2 on pressing the user button and vice versa. Both the CAN FD nodes log the received data over UART serial terminal. Each time a CAN FD Frame is received, the user LED toggles. For more details, see the README on GitHub.

Class-B Safety Test Analog Peripherals

This code example demonstrates the use of the Class-B Safety Test Library to test the Analog peripherals like, Comparator, OpAmp, and ADC in the PSoC™ 4 MCU. The example verifies the proper operation and accuracy of these peripherals. For more details, see the README on GitHub.

Class-B Safety Test Communication Protocol

This code example demonstrates the use of the Class-B Safety Test Library to test the Communication Protocol using the PSoC™ 4 MCU. The example conducts a communication test by configuring two SCB instances as UART and connecting their TX and RX pins to the corresponding RX and TX pins of other blocks. The objective is to detect any potential data corruption during transit. For more details, see the README on GitHub.

Class-B Safety Test Core Peripherals

This code example demonstrates the use of the Class-B Safety Test Library to test the core peripherals of the PSoC™ 4 MCU, which are critical for ensuring safety. The example includes tests such as CPU registers, Program Counter, WDT, clock, interrupt, Input/Output, Flash (Fletcher's test + CRC test), and config registers. For more details, see the README on GitHub.

Class-B Safety Test I2C

This code example demonstrates the use of the Class-B Safety Test Library to test the I2C interface in the PSoC™ 4 MCU. The example tests the I2C interface by configuring one SCB instance as an I2C master and another SCB instance as an I2C slave. It then verifies the communication between the two SCB blocks by connecting external jumper wires between these two SCB blocks. For more details, see the README on GitHub.

Class-B Safety Test SPI Loopback

This code example demonstrates the use of the Class-B Safety Test Library to test the SPI loopback in the PSoC™ 4 MCU. The example performs the SPI loopback test by configuring one SCB instance as SPI master and connecting its MOSI and MISO pins internally using Smart-IO. For more details, see the README on GitHub.

Class-B Safety Test UART Loopback

This code example demonstrates the use of the Class-B Safety Test Library to test the UART loopback Test in the PSoC™ 4 MCU. The example performs the UART loopback test by configuring one SCB instance as UART and connecting its TX and RX pins internally using Smart-IO. For more details, see the README on GitHub.

Clock Buffer with Smart IO

This example shows how to use a Smart I/O Peripheral in PSoC™ 4 to implement a clock buffer that can operate in chip low power modes. It can also be used to drive a heavier load than one GPIO is rated for by replicating the signal and driving two pins. For more details, see the README on GitHub.

Comparing two external voltages using LPComp

This code example demonstrates the voltage comparison functionality using the LPComp peripheral in PSoC™ 4. For more details, see the README on GitHub.

Cryptography SHA Demonstration

This code example shows how to generate a 20-byte hash value or message digest for an arbitrary user input message using the SHA2 algorithm using the Cryptographic hardware block in PSoC™ 4. The example further shows that any change in the message results in a unique hash value for the message. The hash value generated for the message is displayed on a UART terminal emulator. For more details, see the README on GitHub.

Cryptography TRNG Demonstration

This code example demonstrates generating a One-Time Password (OTP) using the True Random Number generation feature of PSoC™ 4 cryptography block. For more details, see the README on GitHub.

Direction Detection Using Quadrature Decoder

This code example demonstrates how to use the TCPWM peripheral configured as a quadrature decoder in PSoC™ 4. For more details, see the README on GitHub.

Emulated EEPROM

This example demonstrates how to use the Em_EEPROM middleware in PSoC™ 4 MCU devices. In this example, a counter is read from the Emulated EEPROM (Em_EEPROM), incremented, written back to the Em_EEPROM and printed on a serial terminal. This occurs on every device reset or power cycle. As a result, an incrementing value is printed on every reset. For more details, see the README on GitHub.

Frequency measurement using TCPWM

This code example demonstrates how to use the TCPWM peripheral in PSoC™ 4 device to measure the frequency of a periodic digital signal. For more details, see the README on GitHub.

GPIO Interrupt

This code example demonstrates the use of a GPIO configured as an input pin to generate interrupts on PSoC™ 4. The GPIO signal interrupts the CPU and executes a user-defined Interrupt Service Routine (ISR). The GPIO interrupt acts as a wakeup source to wake the CPU from Deep Sleep. For more details, see the README on GitHub.

GPIO Pins

This example demonstrates multiple methods of configuring, reading, writing, and generating interrupts with PSoC™ 4 General Purpose Input/Output (GPIO) pins. For more details, see the README on GitHub.

I2C Master EzI2C Slave

This example demonstrates the operation of I2C resource for PSoC™ 4 in Master mode with an EzI2C slave. For more details, see the README on GitHub.

I2C Slave Using Callbacks

This example demonstrates the operation of the I2C block for PSoC™ 4 in Slave mode using callbacks. For more details, see the README on GitHub.

LIN Slave

This code example shows how to implement a basic LIN 2.2 slave using the LIN Middleware in PSoC™ 4. PSoC™ 4 responds to an external LIN Master's commands to either turn on the corresponding color LED on PSoC™ development kit or report the current LED color status. For more details, see the README on GitHub.

Non-blocking Flash Write Using Interrupt

This example uses a non-blocking Peripheral Driver Library (PDL) API function to write a flash row. This is done using interrupt method. For more details, see the README on GitHub.

Non-blocking Flash Write Using Polling

This example uses a non-blocking Peripheral Driver Library (PDL) API function to write a flash row. This is done using polling method. For more details, see the README on GitHub.

Periodic Interrupt Using TCPWM

This example uses the TCPWM Component in the Timer/Counter mode to generate a periodic interrupt. An LED toggles whenever the interrupt occurs. For more details, see the README on GitHub.

PSoC 4 Basic device firmware upgrade

This example demonstrates how to create a field upgradable project for PSoC™ 4 using the DFU middleware. For more details, see the README on GitHub.

PSoC 4 Device firmware upgrade host

This example demonstrates how to create an I2C-based DFU Host on PSoC™ 4100S Max Pioneer Kit CY8CKIT-041S-MAX and flash the PSoC™ 4000T DFU target device. For more details, see the README on GitHub.

PWM Triggering a DMA Channel

This example demonstrates how to route trigger signals on a PSoC™ 4 device.The trigger signal, in this code example, is routed from the PWM to the DMA, using Device Configurator. For more details, see the README on GitHub.

SAR ADC BASIC

This example demonstrates how to use the SAR ADC in PSoC™ 4 MCU devices. In this example, the ADC is configured to measure inputs from different sources and display results through a uart terminal. For more details, see the README on GitHub.

SCB UART Transmit and Receive with DMA

This code example demonstrates the UART transmit and receive operation in PSoC™ 4 using DMA. The application uses a serial terminal to read data and echoes what is received. For more details, see the README on GitHub.

Segment LCD

This example project demonstrates the basic operation of the PSoC™ 4 Segment LCD peripheral. For more details, see the README on GitHub.

SPI Master

This example demonstrates the use of a SPI resource for PSoC™ 4 in master mode using high level APIs. The SPI master is configured to send command packets to control a user LED on the slave. For more details, see the README on GitHub.

SPI Slave

This example demonstrates the use of a SPI Serial Communication Block (SCB) resource for PSoC™ 4 in slave mode using high-level API. This example is intended to be used with PSoC™ 4 SPI Master project For more details, see the README on GitHub.

SPI Slave Select Inversion with Smart IO

This example demonstrates how to use the Smart IO Peripheral in PSoC™ 4 MCU to invert the output of the serial communication block (SCB) SPI slave select signal. This method can be used for any of the SCB unidirectional signals to invert the signal polarity. For more details, see the README on GitHub.

TCPWM event counter

The example shows how to use the TCPWM to count a number of external events and display the results over UART. For more details, see the README on GitHub.

TCPWM square wave

This code example demonstrates how to generate a square wave using the TCPWM peripheral configured as a PWM on a PSoC™ 4 device. For more details, see the README on GitHub.

UART Transmit and Receive

This example demonstrates the UART transmit and receive operation in PSoC™ 4 device. The application uses a serial terminal to read data and to echo back the received data. For more details, see the README on GitHub.

Wakeup from deepsleep using Low-Power Comparator

This code example demonstrates how low-power comparator (LPComp) is calibrated and how the peripheral generates an interrupt signal. This example also shows how the LPComp peripheral can be operated in low-power modes. For more details, see the README on GitHub.

Watchdog Counter Interrupts

This example demonstrates the use of PSoC™ 4 Watchdog Counters in cascaded mode. The user LED is toggled every time the Counter2 interrupt occurs. The match values of all the counters are set to toggle the LED every 1 second. For more details, see the README on GitHub.

Watchdog timer interrupt and reset

This code example features the watchdog timer and its usage in interrupt mode, reset mode and how to wake up the device from deepsleep using watchdog interrupt. For more details, see the README on GitHub.

Sensing

Example

Description

CAPSENSE Buttons and Slider RTT

This code example demonstrates how to monitor self-capacitance (CSD) based buttons and slider widgets using the CAPSENSE™ tuner through RTT in PSoC™ 4 devices. For more details, see the README on GitHub.

CAPSENSE CSD Button Tuning

This code example demonstrates how to manually tune a self-capacitance (CSD) based button widget in PSoC™ 4 devices using CAPSENSE™ Tuner GUI. For more details, see the README on GitHub.

CAPSENSE CSD Slider Tuning

This code example demonstrates how to manually tune Self Capacitance (CSD) based slider widget in PSoC™ 4 devices using CAPSENSE™ Tuner GUI. For more details, see the README on GitHub.

CAPSENSE CSX Button Tuning

This code example demonstrates how to manually tune a mutual capacitance (CSX)-based button widget in PSoC™ 4 devices using CAPSENSE™ Tuner GUI. For more details, see the README on GitHub.

CAPSENSE Liquid tolerant proximity

This code example demonstrates to tune the proximity sensors on CY8CKIT-024 proximity shield for liquid tolerance. This code example is tuned for a proximity-sensing distance of 3 cm with liquid tolerance. The proximity of the user hand is indicated by turning ON the LEDs (LED1-LED5). For more details, see the README on GitHub.

CAPSENSE liquid-tolerant hybrid scan

This code example demonstrates the self-capacitance scanning technique to implement liquid tolerance on mutual-cap sensors. CAPSENSE™ senses the self-capacitance of Tx and Rx nodes of a mutual-capacitance sensor. This ability of scanning the sensor using both self-capacitance (CSD) and mutual-capacitance (CSX) sensing modes is used to avoid false triggers due to the presence of liquid drops on a mutual-capacitance sensor. For more details, see the README on GitHub.

CAPSENSE Multi-frequency Scan

This example demonstrates the use of the Multi-Frequency Scan (MFS) for PSoC™ 4 CAPSENSE™ applications to prevent false touch detection in the presence of external noise. This code example demonstrates this feature for both CSD (self-capacitance) and CSX (mutual-capacitance) designs. For more details, see the README on GitHub.

CAPSENSE Pipeline scan and process

This code example demonstrates how to implement pipeline scanning in CAPSENSE™ to improve performance. When a particular widget is being processed, the next widget in line can be scanned in parallel, and the device remains in Deep Sleep mode until the scan is complete. The WDT (Watchdog Timer) is used to wake up the device periodically from Deep Sleep mode. This is better than the traditional method of scanning all the widgets and then processing the scanned data later. This reduces the sensor scan time and minimizes power consumption. For more details, see the README on GitHub.

CAPSENSE proximity gestures

This code example demonstrate how to detect swipe gestures in the X-axis and Y-axis using the proximity sensors on CY8CKIT-024 using the PSoC™ 4 device. For more details, see the README on GitHub.

CAPSENSE SmartSense buttons slider

This code example demonstrates how to tune self-capacitance (CSD)-based buttons and slider widgets with SmartSense in PSoC™ 4 devices using the CAPSENSE™ tuner. For more details, see the README on GitHub.

CY8CPROTO-040T Demo

This example demonstrates the CAPSENSE™ features of the PSoC™ 4000T device on the CY8CPROTO-040T Kit including recommended power states and transitions, tuning parameter adjustments, and the method of tuning of a MSCLP self capacitance (CSD)-based button and slider widgets and a MSCLP mutual capacitance (CSX)-based button widget for low power operation. For more details, see the README on GitHub.

MSC CAPSENSE CSD Button Tuning

This code example demonstrates how to manually tune a self capacitance-based button widget in PSoC™ 4 devices using the Multi Sense Converter (MSC) CSD-RM sensing technique and CAPSENSE™ Tuner GUI. For more details, see the README on GitHub.

MSC CAPSENSE CSD Slider Tuning

This code example demonstrates how to manually tune a self capacitance-based slider widget in PSoC™ 4 devices using the Multi Sense Converter (MSC) CSD-RM sensing technique and CAPSENSE™ Tuner GUI. For more details, see the README on GitHub.

MSC CAPSENSE CSD Touchpad Tuning

This code example demonstrates how to manually tune a self capacitance-based touchpad widget in PSoC™ 4 devices using the Multi Sense Converter (MSC) CSD-RM sensing technique and CAPSENSE™ Tuner GUI. For more details, see the README on GitHub.

MSC CAPSENSE CSX Button Tuning

This code example demonstrates how to manually tune a mutual capacitance-based button widget in PSoC™ 4 devices using the Multi Sense Converter (MSC) CSX-RM sensing technique and CAPSENSE™ Tuner GUI. For more details, see the README on GitHub.

MSC CAPSENSE Liquid tolerant touchpad

This code example demonstrates how to use the CAPSENSE™ middleware to detect a finger touch position with gestures on a self-capacitance-based touchpad widget in PSoC™ 4 devices with multi sense converter (MSC). For more details, see the README on GitHub.

MSC Multi-Touch CSX Touchpad Tuning

This code example demonstrates how to manually tune a mutual capacitance-based touchpad widget in PSoC™ 4 devices using the Multi Sense Converter (MSC) CSX-RM sensing technique and CAPSENSE™ Tuner GUI. For more details, see the README on GitHub.

MSCLP CAPSENSE LOW POWER

This code example demonstrates an implementation of a low-power application including recommended power states and transitions, tuning parameter adjustments, and method of tuning.This example uses a single self-capacitance-based button in MSCLP (5th-generation low-power CAPSENSE) to demonstrate different considerations to implement a low-power design. For more details, see the README on GitHub.

MSCLP CAPSENSE Low-Power Proximity Tuning

This code example demonstrates how to manually tune a Proximity widget and a low power widget for low power proximity detection in PSoC™ 4 device using MSCLP (5th-generation low-power CAPSENSE™) and CAPSENSE™ Tuner. For more details, see the README on GitHub.

MSCLP Low Power CSD Button

This code example shows how to manually tune a MSCLP self capacitance (CSD)-based button widget in PSoC™ 4000T device for low power operation. For more details, see the README on GitHub.

MSCLP Low Power CSD Slider

This code example shows how to manually tune a MSCLP self capacitance (CSD)-based slider widget in PSoC™ 4000T device for low power operation. For more details, see the README on GitHub.

MSCLP Low power CSX button

This code example shows how to manually tune a MSCLP mutual capacitance (CSX)-based button widget in PSoC™ 4000T device for low power operation. For more details, see the README on GitHub.

MSCLP Low power CSX slider

This code example shows how to manually tune a MSCLP mutual capacitance (CSX)-based slider widget in PSoC™ 4000T device for low power operation. For more details, see the README on GitHub.

MSCLP Low Power Proximity

This code example shows how to manually tune a proximity widget in PSoC™ 4000T device for low power operation. For more details, see the README on GitHub.

MSCLP Robust Low-Power Liquid-Tolerant CAPSENSE

This code example demonstrates a low-power, liquid-tolerant application including different CAPSENSE™ states and transitions, with recommended tuning parameters. This example demonstrates the advanced features of MSCLP (5th-generation low-power CAPSENSE™) by using all the sensors on the CY8CKIT-040T CAPSENSE™ evaluation kit. The on-board LEDs are used in this example to indicate different touch operations. For more details, see the README on GitHub.

MSCLP Self Capacitance Button Tuning

This is a code example demonstrating the tuning procedure of CAPSENSE™ self-capacitance button along with gestures using PSoC™ 4 device using MSCLP (5th-generation low-power CAPSENSE™) and CAPSENSE™ Tuner. For more details, see the README on GitHub.

PSoC 4 CAPSENSE liquid-level sensing

This code example demonstrates how to use PSoC™ 4 MCU, CAPSENSE™ technology, and capacitive sensors to measure the depth or presence of water-based liquids in non-conductive containers. Sensors located on or near the containers exterior provide real-time reporting of liquid levels. There are multiple options available that use low-cost materials to construct and integrate the sensors, while continuing to provide high-precision measurements. For more details, see the README on GitHub.

PSoC 4 CAPSENSE low-power

This code example demonstrates an implementation of a low-power CAPSENSE™ design using the PSoC™ 4 MCU. This example features the CAPSENSE™ slider and the buttons. It scans all the widgets and then processes the scanned data. Here the device is put into Deep Sleep in idle mode and the WDT is used to wake up the device from the Deep Sleep mode. For more details, see the README on GitHub.

PSoC 4 CAPSENSE Proximity Sensing

This code example demonstrates a CAPSENSE™ based proximity sensing design to control the brightness of an onboard LED. It helps to learn how to design a proximity sensor using a PSoC™ 4 device, and see how an approaching hand controls the intensity of an onboard LED. It employs the CAPSENSE™ auto-tuning ability, SmartSense, to tune the proximity sensor for any wire or trace length. For more details, see the README on GitHub.

PSoC 4 MSCLP CAPSENSE Liquid Tolerant Proximity Sensing

This code example demonstrates how to manually tune a Proximity widget for liquid tolerance in PSoC™ 4 device using MSCLP (5th-generation low-power CAPSENSE™) and CAPSENSE™ Tuner. For more details, see the README on GitHub.

PSoC 4 MSCLP multi-phase mutual-capacitance touchpad

This code example demonstrates multi-phase CSX (MPTX) touchpad implemention on the CY8CKIT-040T and showcases the performance improvement over regular CSX. For more details, see the README on GitHub.

PSoC 4 MSCLP multitouch mutual-capacitance touchpad tuning

This is a code example demonstrating the tuning procedure of MSCLP (5th-generation low-power CAPSENSE™) mutual-capacitance touchpad along with gestures. For more details, see the README on GitHub.

PSoC 4 MSCLP self-capacitance touchpad tuning

This code example demonstrates how to use the CAPSENSE™ middleware to detect a finger touch position on a self-capacitance-based touchpad widget in PSoC™ 4000T device with multi-sense converter low power (MSCLP™). For more details, see the README on GitHub.

Community Code Examples

Example

Description

CAPSENSE Flanking Sensor Suppression

Disclaimer: This is a community code example (CCE) released for the benefit of the community users. These projects have only been tested for the listed BSPs, tools versions and toolchains documented in the Readme.This code example implements Flanking Sensor Suppression (FSS) in PSoC™ 4 devices. FSS eliminates false touches by distinguishing between signals from closely spaced buttons. In the project, three sensors have been used to demonstrate FSS. Whenever multiple sensors are touched, only the sensor whose touch was detected first remains active, and the other sensors are rendered inactive, i.e., their touch (if any) is rendered invalid until the sensor whose touch was detected first is active. This eliminates sensors, which are closely spaced, from being falsely triggered at the same time. For more details, see the README on GitHub.

PSoC 4 MCU Inter-IC Sound

Disclaimer: This is a community code example (CCE) released for the benefit of the community users. These projects have only been tested for the listed BSPs, tools versions and toolchains documented in the Readme.This example demonstrates how the I2S block can be configured to transmit data for PSoC 4100S MAX devices. For more details, see the README on GitHub.

PSoC4 CAPSENSE with Pipeline Scanning

Disclaimer: This is a community code example (CCE) released for the benefit of the community users. These projects have only been tested for the listed BSPs, tools versions and toolchains documented in the Readme.They are intended to demonstrate how a solution / concept / use-case can be achieved on a particular device. This code example demonstrates how to implement pipeline scanning in CAPSENSE™ to improve performance. When a particular widget is being processed, the next widget in line can be scanned parallelly. This is better than conventional method of scanning all the widgets and then processing the scanned data later altogether. This reduces net scan time for the application. For more details, see the README on GitHub.

PSoC4 MCU CAPSENSE MSC Guard Sensor

Disclaimer: This is a community code example (CCE) released for the benefit of the community users. These projects have only been tested for the listed BSPs, tools versions and toolchains documented in the Readme.This code example features the CAPSENSE™ guard sensor in PSoC™ 4 devices with Multi sense converter (MSC). The on-board LED will glow when touch is detected on trackpad but when the guard sensor is triggered due to liquid stream present on guard sensor surface, the on-board LED will stop glowing. The code example also demonstrates monitoring CAPSENSE™ data using the CAPSENSE™ Tuner GUI tool For more details, see the README on GitHub.

PSoC4 MCU Flash and Chip Protection

Disclaimer: This is a community code example (CCE) released for the benefit of the community users. These projects have only been tested for the listed BSPs, tools versions and toolchains documented in the Readme.This code example demonstrates how to add flash and chip protection settings into the hex file. Flash memory is organized in rows. You can assign one of two protection levels to each row(Unprotected, Full Protection). Flash protection levels can only be changed by performing a complete flash erase For more details, see the README on GitHub.