Intermediate
30 min

Touch the difference with AT42QT1110 and STM32F091RC

The future of interaction!

TouchKey 3 Click with Nucleo-64 with STM32F091RC MCU

Published Feb 26, 2024

Click board™

TouchKey 3 Click

Dev Board

Nucleo-64 with STM32F091RC MCU

Compiler

NECTO Studio

MCU

STM32F091RC

Incorporate capacitive touch into your projects and witness the transformation of user experience

A

A

Hardware Overview

How does it work?

TouchKey 3 Click uses the AT42QT1110, an 11-key QTouch® Touch Sensor IC from Microchip. It can be configured in several different ways, depending on the application: it can be used to support more or less sensor channels, to support direct outputs for an interrupt triggering on a specific channel, to have its #CHANGE output pin used for triggering one global interrupt whenever one of the sensors detects a touch event, or to improve the power consumption by employing the SYNC input signal for triggering sensing bursts in specific time intervals. TouchKey 3 Click uses seven capacitive sensing channels, with the #CHANGE pin routed to the INT pin of the mikroBUS™, so that an interrupt can be triggered if any of the sensors detect a touch event, for example. This can trigger an SPI read cycle only when the key is pressed, avoiding the need for constant polling of the AT42QT1110’s registers. However, the behavior of the #CHANGE pin is programmable and more information about its functionality can be found in the AT42QT1110 datasheet. The SYNC pin is pulled high and not used, allowing the click board™ to run in the Free Run mode, which enables the fastest key press detection times. #RESET pin of the AT42QT1110 is routed to the RST pin of the mikroBUS™, and it is used to reset the device and reinitialize its working parameters - either with values stored in the EEPROM or the default values that are loaded into the RAM, in case the EEPROM does not contain any saved values. SPI will not be available for 160ms after the RESET event has occurred. This pin should be pulled to a HIGH logic level to reset the device. The AT42QT1110 sensor has internal registers that are used for configuring

the working parameters of the device. The device Mode register is one of the important config registers, and it is used to control the overall operation of the click board™. Bit KEY_AC of the Device Mode register is used to set the detection triggering mode: 0 by SYNC pin or 1 by internal timer (should be set to 1, since the SYNC pin is pulled to a HIGH logic level); MODE bit: 0 for 7, or 1 for 11 channels configuration (should be set to 0 for 7 channels operation); SIGNAL bit:  0 for serial, or 1 for parallel; SYNC bit: 0 for rising edge, or 1 for zero level detect (disregarded, since the KEY_AC is set to 1); REPEAT TIME bit field: these four bits set the repeat time between the scanning intervals. If the REPEAT TIME is set to 0, the new scanning cycle will be performed immediately after the previous cycle, allowing for the fastest touch detection. The value of this bitfield is multiplied by 16ms to get the final repeat time. TouchKey 3 click also features signal processing to provide better button detection. Adjacent Key Suppression (AKS®) technology can be configured on each channel. A group of channels with the AKS® enabled will be processed so that only the detected key remains active, while other sensors will be disregarded. The other sensors with the AKS® enabled will be activated only when the currently active key is released. The sensor channels for which AKS® is not selected will retain the ability to sense touch simultaneously. This technology allows better key accuracy and less false detections in applications requiring key press detection precision. Detection Integration (DI) is another technology used to sense the key press better. When the button is first pressed, a counter is started. If the counter expires

and the sensor channel still detects a key press, that keypress will be declared true. Else it will be disregarded as false. This serves as a kind of debouncing and prevents false detections. DI technology is implemented per sensor. The AT42QT1110 IC has EEPROM memory, which can store current RAM settings. All the registers are kept in RAM, and after the power-on reset event (POR), the values stored in the EEPROM memory will be automatically copied to the registers. Else, the registers will be loaded with the default values. All these functions can be accessed and configured via the SPI bus. The SPI communication can be either in Quick SPI mode or full SPI mode. While working in the Quick SPI mode, the device will send a sequence of 7 bytes containing the essential data, such as the detection and error status of the channels. In this mode, no-host MCU commands are required, and this sequence will be clocked out continuously from the AT42QT1110 IC. Quick SPI mode is enabled by setting the SPI_EN bit in the Comms Options setup register. All the SPI pins and the chip select pin are routed to the appropriate pins on the mikroBUS™. Onboard SMD jumper labeled VCC SEL selects the power supply and logic voltage level. This click board can work with both 3.3V and 5V MCUs. The provided TouchKey 3 Click library contains functions used to configure the device and read touch events comprehensively and intuitively. The included example application demonstrates the usage of these functions, and it can be used as a reference for a custom design.

TouchKey 3 Click top side image
TouchKey 3 Click bottom side image

Features overview

Development board

Nucleo-64 with STM32F091RC MCU offers a cost-effective and adaptable platform for developers to explore new ideas and prototype their designs. This board harnesses the versatility of the STM32 microcontroller, enabling users to select the optimal balance of performance and power consumption for their projects. It accommodates the STM32 microcontroller in the LQFP64 package and includes essential components such as a user LED, which doubles as an ARDUINO® signal, alongside user and reset push-buttons, and a 32.768kHz crystal oscillator for precise timing operations. Designed with expansion and flexibility in mind, the Nucleo-64 board features an ARDUINO® Uno V3 expansion connector and ST morpho extension pin

headers, granting complete access to the STM32's I/Os for comprehensive project integration. Power supply options are adaptable, supporting ST-LINK USB VBUS or external power sources, ensuring adaptability in various development environments. The board also has an on-board ST-LINK debugger/programmer with USB re-enumeration capability, simplifying the programming and debugging process. Moreover, the board is designed to simplify advanced development with its external SMPS for efficient Vcore logic supply, support for USB Device full speed or USB SNK/UFP full speed, and built-in cryptographic features, enhancing both the power efficiency and security of projects. Additional connectivity is

provided through dedicated connectors for external SMPS experimentation, a USB connector for the ST-LINK, and a MIPI® debug connector, expanding the possibilities for hardware interfacing and experimentation. Developers will find extensive support through comprehensive free software libraries and examples, courtesy of the STM32Cube MCU Package. This, combined with compatibility with a wide array of Integrated Development Environments (IDEs), including IAR Embedded Workbench®, MDK-ARM, and STM32CubeIDE, ensures a smooth and efficient development experience, allowing users to fully leverage the capabilities of the Nucleo-64 board in their projects.

Nucleo 64 with STM32F091RC MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M0

MCU Memory (KB)

256

Silicon Vendor

STMicroelectronics

Pin count

64

RAM (Bytes)

32768

You complete me!

Accessories

Click Shield for Nucleo-64 comes equipped with two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the STM32 Nucleo-64 board with no effort. This way, Mikroe allows its users to add any functionality from our ever-growing range of Click boards™, such as WiFi, GSM, GPS, Bluetooth, ZigBee, environmental sensors, LEDs, speech recognition, motor control, movement sensors, and many more. More than 1537 Click boards™, which can be stacked and integrated, are at your disposal. The STM32 Nucleo-64 boards are based on the microcontrollers in 64-pin packages, a 32-bit MCU with an ARM Cortex M4 processor operating at 84MHz, 512Kb Flash, and 96KB SRAM, divided into two regions where the top section represents the ST-Link/V2 debugger and programmer while the bottom section of the board is an actual development board. These boards are controlled and powered conveniently through a USB connection to program and efficiently debug the Nucleo-64 board out of the box, with an additional USB cable connected to the USB mini port on the board. Most of the STM32 microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the STM32 Nucleo-64 board with our Click Shield for Nucleo-64, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Nucleo-64 accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PC12
RST
SPI Chip Select
PB12
CS
SPI Clock
PB3
SCK
SPI Data OUT
PB4
MISO
SPI Data IN
PB5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PC14
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

TouchKey 3 Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-64 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo-64 with STM32F091RC MCU as your development board.

Click Shield for Nucleo-64 front image hardware assembly
Nucleo 64 with STM32F401RE MCU front image hardware assembly
EEPROM 13 Click front image hardware assembly
Prog-cut hardware assembly
Nucleo-64 with STM32XXX MCU MB 1 Mini B Conn - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Clicker 4 for STM32F4 HA MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output via Debug Mode

1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for TouchKey 3 Click driver.

Key functions:

  • touchkey3_send_command - This function executes one of the possible commands

  • touchkey3_send_request - This function sends a request command, and returns the response

  • touchkey3_get_data - This function reads from a selected configuration register

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * \file 
 * \brief TouchKey3 Click example
 * 
 * # Description
 * This click uses 7 capacitive sensing channels, with the #CHANGE pin routed to the INT pin of the mikroBUS™, 
 * so that an interrupt can be triggered if any of the sensors detect a touch event. 
 * This can be used to trigger an SPI read cycle only when the key is actually pressed, 
 * avoiding the need for constant polling of the sensor registers.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes click driver and performs a soft reset of the click.
 * 
 * ## Application Task  
 * Reads the status of the keys, and outputs a message if a key is touched.
 * 
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "touchkey3.h"


// ------------------------------------------------------------------ VARIABLES

static touchkey3_t touchkey3;
static log_t logger;

static uint8_t return_data[ 2 ];
static uint8_t counter;
static uint8_t temp;
static uint8_t old_state;
static const uint16_t timeout_state = 1000;
static uint16_t timeout_cnt;

// ------------------------------------------------------ APPLICATION FUNCTIONS

uint8_t calculationt_index ( uint8_t data_in )
{
    uint8_t counter = 2;
    
    if ( data_in <= 2 )
    {
        return data_in;
    }
    
    while ( data_in > 2 )
    {
        data_in /= 2;
        counter++;
    }
    
    return counter;
}

void application_init ( void )
{
    log_cfg_t log_cfg;
    touchkey3_cfg_t cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );

    //  Click initialization.

    touchkey3_cfg_setup( &cfg );
    TOUCHKEY3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    touchkey3_init( &touchkey3, &cfg );

    touchkey3_reset( &touchkey3 );
    touchkey3_send_command( &touchkey3, TOUCHKEY3_CMD_RESET );
    timeout_cnt = timeout_state;
    
    Delay_ms( 300 );
}

void application_task ( void )
{   
    touchkey3_send_request( &touchkey3, TOUCHKEY3_REQ_ALL_KEYS, &return_data );

    for ( counter = 0; counter < 7; counter++ )
    {
        if ( ( return_data[ 1 ] >> counter ) & 0x01 )
        {
            log_printf( &logger, "Touch detected on key %d\r\n", ( uint16_t )(counter+1) );
            Delay_ms( 1000 );
        }
    }
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}


// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.