1282|5

166

帖子

1

TA的资源

一粒金砂(高级)

楼主
 

【NUCLEO-U083RC】6.电容触摸按键(TSC) [复制链接]

本帖最后由 电子烂人 于 2024-6-4 21:52 编辑

0.前言

在任务选择的时候看到了“电容触摸”这个小任务,心想着“应该不难”就加进了项目之中,等到真正去做的时候发现,和我想得真不是一回事(笑哭)

市面上的触摸大多数是用TP223之类的芯片做的完整模块,但是在很多低成本要求的产品里,一个芯片和一个按键都有成本限制,STM32U0本身就集成了一个TSC,要做触摸按键的话有点“鸠占鹊巢”的意思。。。没办法,只能硬着头皮试试运气,好在这方面的资料还是不少的。在这里贴一个官方手册指路:

  • AN5105 Getting Started with Touch control
  • UM1913 Developing applications on STM32Cube with STMTouch touch sensing library
  • AN4316 Tuning a STMTouch-based application
  • AN4312 Guidelines for designing touch sensing applications with surface sensors
  • AN4299 Guidelines to improve conducted noise robustness on STM32 series touch sensing applications
  • AN4310 Sampling capacitor selection guide for MCU based touch sensing applications
  • AN3960 ESD considerations for touch sensing applications

另外,对ST触摸开发需要先熟悉以下术语:

 

图源:基于STM32微控制器的触摸感应控制入门 (AN5105)

 

1.电容触摸按键介绍

    电容触摸本质就是一个按键开关,STM32的电容触摸感应特性基于表面电荷转移采集原理,其过程包括将传感器电容充电并将累积电荷转移至采样电容。当传感器被触摸时,由于传感器对地电容增大,达到阈值所需的电荷转移次数减少,从而测量值变小。当测量值低于阈值时,检测到触摸。相较于传统的机械按键,具有更长的寿命和更少的占用空间。

 

图源:Introduction to touch sensing with STM32 - stm32mcu

 

 

另外ST 也有对应的应用手册,刚添加了U0,可以作为设计的参考How to design surface sensors for touch sensing applications on STM32 MCUs - Application note

 

2.PCB设计

    为了设计TSC的电荷测量电路,我这里找到了F051的教程PPT以了解具体电路:

 

来源:stm32触摸感应控制器TSC.pdf_人人文库网 (renrendoc.com)

    可以看到,检测触摸本质上是对触摸部分电容值的测量,测量电路主要由RS和CS组成,要使用TSC触摸至少使用两个IO口,两个通道一个测量待测电容,一个测量采样电容,将两个电容值进行对比。这一点可以类似ADC的待测电压和基准电压的关系。

    待测电容计算公式如下:

来源:AN4312How to design surface sensors for touch sensing applications on STM32 MCUs

 

TOUCHKEY的设计可以参照U083-DK中的原理图:

测量触摸按键的电容需要至少两个通道,一个测量按键,另一个测量shield 屏蔽端,两个通道都有CS和RS,且每一路的数值不同;本次设计取TKEY Cs=39nf, Rs=10k;shield Cs=390nf,Rs=1K。(这个CS不是片选,是采样电容)
要注意的是,原理图中SHIELD不是接公共地,不可以直接整板铺铜,需要单独孤立出来一片铺铜区域,而且不与地平面连接,这一点可以参考U083DK板的触摸按键设计:

 
    通过对PCB工程的分析可以发现,这一片的铜是孤立出来的,且需要优化做立体屏蔽(上下打孔,包括内层但是不包括底层),最后串联电阻R60到PB12引脚上。
3.初始化配置
配置如图:使能G2_IO1为触摸引脚(PB4),G2_IO2为触摸采样电容引脚(PB5),G3_IO2为屏蔽层引脚(PA15),G2_IO2为屏蔽采样电容引脚(PC10)  
 
 
同时在MIDDLEWARE中间件中找到touch sensing 包,使能并配置G2_IO1
 
导入成功后代码结构如图:
 
4.代码编辑
    u083-dk的官方示例中有对应的示例,在TouchSensing_touchkey示例中,ST提供了触摸感应的示例代码,这些代码是基于STM32Cube HAL库编写的。代码的主要功能包括初始化触摸感应控制器(TSC),配置触摸感应通道,以及实现触摸检测和处理逻辑。
 
 

在代码编辑阶段,需要调用和修改以下几个主要部分:

  1. 触摸感应初始化函数【tsl_user_Init()】:这个函数会配置TSC硬件,设置触摸通道,并初始化必要的中断和定时器。
    void tsl_user_Init(void)
    {
      TSL_obj_GroupInit(&MyObjGroup); /* 初始化触摸对象组 */
      TSL_Init(MyBanks); /* 初始化触摸感应模块 */
      tsl_user_SetThresholds(); /* 可选:为每个触摸对象单独设置阈值 */
    }
    这行代码中最重要的是调用了TSL_Init函数,它是STM32Cube STMTouch库中的一个函数,用来初始化触摸感应模块。并在参数Mybanks中指定了哪些触摸通道(banks)将被初始化。
    TSL_Status_enum_T TSL_Init(CONST TSL_Bank_T *bank)
    {
      TSL_Status_enum_T retval;
    
      // 获取触摸通道数组
      TSL_Globals.Bank_Array = bank;
    
      // 初始化用于放电电容的延时
      TSL_Globals.DelayDischarge = (uint32_t)((TSLPRM_DELAY_DISCHARGE_ALL * (uint32_t)(SystemCoreClock/1000000)) / 72);
      
      // 注意:时序配置(Systick)必须在用户代码中完成。
    
      // 初始化触摸感应模块
    #ifdef __TSL_ACQ_TSC_H
      // 注意:TSC外设的初始化必须在用户代码中完成。
      retval = TSL_STATUS_OK;
    #else
      retval = TSL_acq_Init();
    #endif
    
      return retval;
    }

     

  2. 执行触摸感应的采集和处理函数【tsl_user_Exec()】:用户级别的执行函数,它负责配置和启动触摸感应的采集,检查采集结束,读取结果,并处理触摸对象

    tsl_user_status_t tsl_user_Exec(void)
    {
      static uint32_t idx_bank = 0;
      static uint32_t config_done = 0;
      tsl_user_status_t status = TSL_USER_STATUS_BUSY;
    
      /* Configure and start bank acquisition */
      if (!config_done)
      {
    /* USER CODE BEGIN not config_done start*/
    
    /* USER CODE END not config_done start*/
        TSL_acq_BankConfig(idx_bank);
        TSL_acq_BankStartAcq();
        config_done = 1;
    /* USER CODE BEGIN not config_done */
    
    /* USER CODE END not config_done */
      }
    
      /* Check end of acquisition (polling mode) and read result */
      if (TSL_acq_BankWaitEOC() == TSL_STATUS_OK)
      {
    /* USER CODE BEGIN end of acquisition start*/
    
    /* USER CODE END end of acquisition start*/
        STMSTUDIO_LOCK;
        TSL_acq_BankGetResult(idx_bank, 0, 0);
        STMSTUDIO_UNLOCK;
        idx_bank++; /* Next bank */
        config_done = 0;
    /* USER CODE BEGIN end of acquisition */
    
    /* USER CODE END end of acquisition */
      }
    
      /* Process objects, DxS and ECS
         Check if all banks have been acquired
      */
      if (idx_bank > TSLPRM_TOTAL_BANKS-1)
      {
    /* USER CODE BEGIN before reset*/
    
    /* USER CODE END before reset*/
        /* Reset flags for next banks acquisition */
        idx_bank = 0;
        config_done = 0;
    
        /* Process Objects */
        TSL_obj_GroupProcess(&MyObjGroup);
    
        /* DxS processing (if TSLPRM_USE_DXS option is set) */
        TSL_dxs_FirstObj(&MyObjGroup);
    
        /* ECS every TSLPRM_ECS_DELAY (in ms) */
        if (TSL_tim_CheckDelay_ms(TSLPRM_ECS_DELAY, &ECSLastTick) == TSL_STATUS_OK)
        {
          if (TSL_ecs_Process(&MyObjGroup) == TSL_STATUS_OK)
          {
            status = TSL_USER_STATUS_OK_ECS_ON;
          }
          else
          {
            status = TSL_USER_STATUS_OK_ECS_OFF;
          }
        }
        else
        {
          status = TSL_USER_STATUS_OK_NO_ECS;
        }
    /* USER CODE BEGIN Process objects */
    
    /* USER CODE END Process objects */
      }
      else
      {
        status = TSL_USER_STATUS_BUSY;
    /* USER CODE BEGIN TSL_USER_STATUS_BUSY */
    
    /* USER CODE END TSL_USER_STATUS_BUSY */
      }
    
      return status;
    }

    这个函数是触摸感应库的核心执行部分,它不断地循环采集、处理触摸数据,并根据触摸结果更新状态。用户可以在预留的代码块中添加自己的代码,以自定义触摸感应的行为。

  3. 移植TSL库:

    /* USER CODE BEGIN Header */
    /**
     ******************************************************************************
      * File Name          : tsl_user.c
      * Description        : User configuration file for TOUCHSENSING
      *                      middleWare.
      ******************************************************************************
      * @attention
      *
      * Copyright (c) 2023 STMicroelectronics.
      * All rights reserved.
      *
      * This software is licensed under terms that can be found in the LICENSE file
      * in the root directory of this software component.
      * If no LICENSE file comes with this software, it is provided AS-IS.
      *
      ******************************************************************************
      */
    /* USER CODE END Header */
    
    #include "tsl_user.h"
    /* Private includes ----------------------------------------------------------*/
    /* USER CODE BEGIN Includes */
    
    /* USER CODE END Includes */
    
    /*============================================================================*/
    /* Channels                                                                   */
    /*============================================================================*/
    
    /* Source and Configuration (ROM) */
    CONST TSL_ChannelSrc_T MyChannels_Src[TSLPRM_TOTAL_CHANNELS] =
    {
        { CHANNEL_0_SRC, CHANNEL_0_IO_MSK, CHANNEL_0_GRP_MSK },
    };
    
    /* Destination (ROM) */
    CONST TSL_ChannelDest_T MyChannels_Dest[TSLPRM_TOTAL_CHANNELS] =
    {
        { CHANNEL_0_DEST },
    };
    
    /* Data (RAM) */
    TSL_ChannelData_T MyChannels_Data[TSLPRM_TOTAL_CHANNELS];
    
    /*============================================================================*/
    /* Banks                                                                      */
    /*============================================================================*/
    
    /* List (ROM) */
    CONST TSL_Bank_T MyBanks[TSLPRM_TOTAL_BANKS] = {
    /* TOUCHKEYS bank(s) definition*/
       {&MyChannels_Src[0], &MyChannels_Dest[0], MyChannels_Data, BANK_0_NBCHANNELS, BANK_0_MSK_CHANNELS, BANK_0_MSK_GROUPS},
    };
    /*============================================================================*/
    /* Touchkey sensors                                                           */
    /*============================================================================*/
    
    /* Data (RAM) */
    TSL_TouchKeyData_T MyTKeys_Data[TSLPRM_TOTAL_TKEYS];
    
    /* Parameters (RAM) */
    TSL_TouchKeyParam_T MyTKeys_Param[TSLPRM_TOTAL_TKEYS];
    
    /* State Machine (ROM) */
    
    void MyTKeys_ErrorStateProcess(void);
    void MyTKeys_OffStateProcess(void);
    
    CONST TSL_State_T MyTKeys_StateMachine[] =
    {
      /* Calibration states */
      /*  0 */ { TSL_STATEMASK_CALIB,              TSL_tkey_CalibrationStateProcess },
      /*  1 */ { TSL_STATEMASK_DEB_CALIB,          TSL_tkey_DebCalibrationStateProcess },
      /* Release states */
      /*  2 */ { TSL_STATEMASK_RELEASE,            TSL_tkey_ReleaseStateProcess },
    #if TSLPRM_USE_PROX > 0
      /*  3 */ { TSL_STATEMASK_DEB_RELEASE_PROX,   TSL_tkey_DebReleaseProxStateProcess },
    #else
      /*  3 */ { TSL_STATEMASK_DEB_RELEASE_PROX,   0 },
    #endif
      /*  4 */ { TSL_STATEMASK_DEB_RELEASE_DETECT, TSL_tkey_DebReleaseDetectStateProcess },
      /*  5 */ { TSL_STATEMASK_DEB_RELEASE_TOUCH,  TSL_tkey_DebReleaseTouchStateProcess },
    #if TSLPRM_USE_PROX > 0
      /* Proximity states */
      /*  6 */ { TSL_STATEMASK_PROX,               TSL_tkey_ProxStateProcess },
      /*  7 */ { TSL_STATEMASK_DEB_PROX,           TSL_tkey_DebProxStateProcess },
      /*  8 */ { TSL_STATEMASK_DEB_PROX_DETECT,    TSL_tkey_DebProxDetectStateProcess },
      /*  9 */ { TSL_STATEMASK_DEB_PROX_TOUCH,     TSL_tkey_DebProxTouchStateProcess },
    #else
      /*  6 */ { TSL_STATEMASK_PROX,               0 },
      /*  7 */ { TSL_STATEMASK_DEB_PROX,           0 },
      /*  8 */ { TSL_STATEMASK_DEB_PROX_DETECT,    0 },
      /*  9 */ { TSL_STATEMASK_DEB_PROX_TOUCH,     0 },
    #endif
      /* Detect states */
      /* 10 */ { TSL_STATEMASK_DETECT,             TSL_tkey_DetectStateProcess },
      /* 11 */ { TSL_STATEMASK_DEB_DETECT,         TSL_tkey_DebDetectStateProcess },
      /* Touch state */
      /* 12 */ { TSL_STATEMASK_TOUCH,              TSL_tkey_TouchStateProcess },
      /* Error states */
      /* 13 */ { TSL_STATEMASK_ERROR,              MyTKeys_ErrorStateProcess },
      /* 14 */ { TSL_STATEMASK_DEB_ERROR_CALIB,    TSL_tkey_DebErrorStateProcess },
      /* 15 */ { TSL_STATEMASK_DEB_ERROR_RELEASE,  TSL_tkey_DebErrorStateProcess },
      /* 16 */ { TSL_STATEMASK_DEB_ERROR_PROX,     TSL_tkey_DebErrorStateProcess },
      /* 17 */ { TSL_STATEMASK_DEB_ERROR_DETECT,   TSL_tkey_DebErrorStateProcess },
      /* 18 */ { TSL_STATEMASK_DEB_ERROR_TOUCH,    TSL_tkey_DebErrorStateProcess },
      /* Other states */
      /* 19 */ { TSL_STATEMASK_OFF,                MyTKeys_OffStateProcess }
    };
    
    /* Methods for "extended" type (ROM) */
    CONST TSL_TouchKeyMethods_T MyTKeys_Methods =
    {
      TSL_tkey_Init,
      TSL_tkey_Process
    };
    
    /* TouchKeys list (ROM) */
    
    CONST TSL_TouchKey_T MyTKeys[TSLPRM_TOTAL_TOUCHKEYS] =
    {
      { &MyTKeys_Data[0], &MyTKeys_Param[0], &MyChannels_Data[CHANNEL_0_DEST], MyTKeys_StateMachine, &MyTKeys_Methods }
    };
    
    /*============================================================================*/
    /* Generic Objects                                                            */
    /*============================================================================*/
    
    /* List (ROM) */
    CONST TSL_Object_T MyObjects[TSLPRM_TOTAL_OBJECTS] =
    {
      { TSL_OBJ_TOUCHKEY, (TSL_TouchKey_T *)&MyTKeys[0] }
    };
    
    /* Group (RAM) */
    TSL_ObjectGroup_T MyObjGroup =
    {
      &MyObjects[0],        /* First object */
      TSLPRM_TOTAL_OBJECTS, /* Number of objects */
      0x00,                 /* State mask reset value */
      TSL_STATE_NOT_CHANGED /* Current state */
    };
    
    /*============================================================================*/
    /* TSL Common Parameters placed in RAM or ROM                                 */
    /* --> external declaration in tsl_conf.h                                     */
    /*============================================================================*/
    
    TSL_Params_T TSL_Params =
    {
      TSLPRM_ACQ_MIN,
      TSLPRM_ACQ_MAX,
      TSLPRM_CALIB_SAMPLES,
      TSLPRM_DTO,
    #if TSLPRM_TOTAL_TKEYS > 0
      MyTKeys_StateMachine,   /* Default state machine for TKeys */
      &MyTKeys_Methods,       /* Default methods for TKeys */
    #endif
    #if TSLPRM_TOTAL_LNRTS > 0
      MyLinRots_StateMachine, /* Default state machine for LinRots */
      &MyLinRots_Methods      /* Default methods for LinRots */
    #endif
    };
    
    /* Private functions prototype -----------------------------------------------*/
    
    /* Global variables ----------------------------------------------------------*/
    /* USER CODE BEGIN Global variables */
    
    /* USER CODE END Global variables */
    
    __IO TSL_tTick_ms_T ECSLastTick; /* Hold the last time value for ECS */
    
    /**
      * @brief   Initialize the STMTouch Driver
      * @param  None
      * @retval None
      */
    void tsl_user_Init(void)
    {
      TSL_obj_GroupInit(&MyObjGroup); /* Init Objects */
    
      TSL_Init(MyBanks); /* Init acquisition module */
    
      tsl_user_SetThresholds(); /* Init thresholds for each object individually (optional) */
    }
    
    /**
      * @brief  Execute STMTouch Driver main State machine
      * @param  None
      * @retval status Return TSL_STATUS_OK if the acquisition is done
      */
    tsl_user_status_t tsl_user_Exec(void)
    {
      static uint32_t idx_bank = 0;
      static uint32_t config_done = 0;
      tsl_user_status_t status = TSL_USER_STATUS_BUSY;
    
      /* Configure and start bank acquisition */
      if (!config_done)
      {
    /* USER CODE BEGIN not config_done start*/
    
    /* USER CODE END not config_done start*/
        TSL_acq_BankConfig(idx_bank);
        TSL_acq_BankStartAcq();
        config_done = 1;
    /* USER CODE BEGIN not config_done */
    
    /* USER CODE END not config_done */
      }
    
      /* Check end of acquisition (polling mode) and read result */
      if (TSL_acq_BankWaitEOC() == TSL_STATUS_OK)
      {
    /* USER CODE BEGIN end of acquisition start*/
    
    /* USER CODE END end of acquisition start*/
        STMSTUDIO_LOCK;
        TSL_acq_BankGetResult(idx_bank, 0, 0);
        STMSTUDIO_UNLOCK;
        idx_bank++; /* Next bank */
        config_done = 0;
    /* USER CODE BEGIN end of acquisition */
    
    /* USER CODE END end of acquisition */
      }
    
      /* Process objects, DxS and ECS
         Check if all banks have been acquired
      */
      if (idx_bank > TSLPRM_TOTAL_BANKS-1)
      {
    /* USER CODE BEGIN before reset*/
    
    /* USER CODE END before reset*/
        /* Reset flags for next banks acquisition */
        idx_bank = 0;
        config_done = 0;
    
        /* Process Objects */
        TSL_obj_GroupProcess(&MyObjGroup);
    
        /* DxS processing (if TSLPRM_USE_DXS option is set) */
        TSL_dxs_FirstObj(&MyObjGroup);
    
        /* ECS every TSLPRM_ECS_DELAY (in ms) */
        if (TSL_tim_CheckDelay_ms(TSLPRM_ECS_DELAY, &ECSLastTick) == TSL_STATUS_OK)
        {
          if (TSL_ecs_Process(&MyObjGroup) == TSL_STATUS_OK)
          {
            status = TSL_USER_STATUS_OK_ECS_ON;
          }
          else
          {
            status = TSL_USER_STATUS_OK_ECS_OFF;
          }
        }
        else
        {
          status = TSL_USER_STATUS_OK_NO_ECS;
        }
    /* USER CODE BEGIN Process objects */
    
    /* USER CODE END Process objects */
      }
      else
      {
        status = TSL_USER_STATUS_BUSY;
    /* USER CODE BEGIN TSL_USER_STATUS_BUSY */
    
    /* USER CODE END TSL_USER_STATUS_BUSY */
      }
    
      return status;
    }
    
    /**
      * Interrupt TSC management. See below code example for N sensors in main.c:
    while (1)
    {
      #define TKEY_DET(NB) (MyTKeys[(NB)].p_Data->StateId == TSL_STATEID_DETECT)
      #define TKEY_PRX(NB) (MyTKeys[(NB)].p_Data->StateId == TSL_STATEID_PROX)
      #define TKEY_REL(NB) (MyTKeys[(NB)].p_Data->StateId == TSL_STATEID_RELEASE)
      #define TKEY_CAL(NB) (MyTKeys[(NB)].p_Data->StateId == TSL_STATEID_CALIB)
      if(tsl_user_Exec_IT() != TSL_USER_STATUS_BUSY){
        int id;
        for(id=0; id < TSLPRM_TOTAL_CHANNELS; id++){
          if(!TKEY_CAL(id)){
            printf("Sensor%d: Delta %3d Ref %3d Measurement %3d StateId %3d\n"
            ,id
            ,MyTKeys[id].p_ChD->Delta
            ,MyTKeys[id].p_ChD->Ref
            ,MyTKeys[id].p_ChD->Meas
            ,MyTKeys[id].p_Data->StateId);
            if(TKEY_DET(id)){
        // we detect a touch
            }else if(TKEY_REL(id)){
            // No more detection
            }
          }
        }
      }else{
        HAL_Delay(1); //Can be replace by __WFI()
      }
    }
      */
    
    /**
     * Local variable used for interrupt acquisition mode
     */
    uint32_t idx_bank_it = 0; // Bank acquisition number (from 0 to TSLPRM_TOTAL_BANKS-1)
    uint32_t config_done_it = 0; // Start first TSC acquisition done using bank 0
    uint32_t acq_done_it = 0; // TSLPRM_TOTAL_BANKS banks acquisition done
    
    /**
      * @brief  Acquisition completed callback in non blocking mode
      * @param  htsc: pointer to a TSC_HandleTypeDef structure that contains
      *         the configuration information for the specified TSC.
      * @retval None
      */
    void HAL_TSC_ConvCpltCallback(TSC_HandleTypeDef* htsc)
    {
    /* USER CODE BEGIN HAL_TSC_ConvCpltCallback start*/
    
    /* USER CODE END HAL_TSC_ConvCpltCallback start*/
      TSL_acq_BankGetResult(idx_bank_it, 0, 0);
      idx_bank_it++;
      if (idx_bank_it > TSLPRM_TOTAL_BANKS-1)
      {
        // End of all banks acquisition, restart bank 0 in while(1) loop (This is a choice)
        idx_bank_it=0;
        acq_done_it++;
      }else{
        // We restart next bank acquisition
        TSL_acq_BankConfig(idx_bank_it);
        TSL_acq_BankStartAcq_IT();
      }
    /* USER CODE BEGIN HAL_TSC_ConvCpltCallback*/
    
    /* USER CODE END HAL_TSC_ConvCpltCallback*/
    }
    
    /**
      * @brief  Execute STMTouch Driver main State machine using TSC Interrupt
      * @param  None
      * @retval status Return TSL_STATUS_OK if the acquisition is done
      */
    tsl_user_status_t tsl_user_Exec_IT(void)
    {
      tsl_user_status_t status = TSL_USER_STATUS_BUSY;
    
      /* Configure and start bank acquisition */
      if (!config_done_it)
      {
    /* USER CODE BEGIN not config_done start*/
    
    /* USER CODE END not config_done start*/
        idx_bank_it = 0;
        acq_done_it = 0;
        TSL_acq_BankConfig(idx_bank_it);
        TSL_acq_BankStartAcq_IT();
        config_done_it = 1;
    /* USER CODE BEGIN not config_done */
    
    /* USER CODE END not config_done */
      }
    
      /* Check end of all group acquisitions (interrupt mode) */
      if (acq_done_it)
      {
    /* USER CODE BEGIN acq_done_it start*/
    
    /* USER CODE END acq_done_it start*/
    
        /* Process Objects */
        TSL_obj_GroupProcess(&MyObjGroup);
    
        /* DxS processing (if TSLPRM_USE_DXS option is set) */
        TSL_dxs_FirstObj(&MyObjGroup);
    
        /* ECS every TSLPRM_ECS_DELAY (in ms) */
        if (TSL_tim_CheckDelay_ms(TSLPRM_ECS_DELAY, &ECSLastTick) == TSL_STATUS_OK)
        {
          if (TSL_ecs_Process(&MyObjGroup) == TSL_STATUS_OK)
          {
            status = TSL_USER_STATUS_OK_ECS_ON;
          }
          else
          {
            status = TSL_USER_STATUS_OK_ECS_OFF;
          }
        }
        else
        {
          status = TSL_USER_STATUS_OK_NO_ECS;
        }
    
    /* USER CODE BEGIN prepare_acq_done_it */
    
    /* USER CODE END prepare_acq_done_it */
    
        // Restart TSLPRM_TOTAL_BANKS banks acquisition
        idx_bank_it = 0;
        acq_done_it = 0;
        TSL_acq_BankConfig(idx_bank_it);
        TSL_acq_BankStartAcq_IT();
    /* USER CODE BEGIN acq_done_it */
    
    /* USER CODE END acq_done_it */
      }
      else
      {
        status = TSL_USER_STATUS_BUSY;
    /* USER CODE BEGIN TSL_USER_STATUS_BUSY */
    
    /* USER CODE END TSL_USER_STATUS_BUSY */
      }
    
    /* USER CODE BEGIN Process objects */
    
    /* USER CODE END Process objects */
    
      return status;
    }
    
    /**
      * @brief  Set thresholds for each object (optional).
      * @param  None
      * @retval None
      */
    void tsl_user_SetThresholds(void)
    {
    /* USER CODE BEGIN Tsl_user_SetThresholds */
      /* Example: Decrease the Detect thresholds for the TKEY 0
      MyTKeys_Param[0].DetectInTh -= 10;
      MyTKeys_Param[0].DetectOutTh -= 10;
      */
    
    /* USER CODE END Tsl_user_SetThresholds */
      }
    
    /**
      * @brief  Executed when a sensor is in Error state
      * @param  None
      * @retval None
      */
      void MyTKeys_ErrorStateProcess(void)
    {
    /* USER CODE BEGIN MyTKeys_ErrorStateProcess */
      /* Add here your own processing when a sensor is in Error state */
    /* USER CODE END MyTKeys_ErrorStateProcess */
    }
    
    /**
      * @brief  Executed when a sensor is in Off state
      * @param  None
      * @retval None
      */
    void MyTKeys_OffStateProcess(void)
    {
    /* USER CODE BEGIN MyTKeys_OffStateProcess */
      /* Add here your own processing when a sensor is in Off state */
    /* USER CODE END MyTKeys_OffStateProcess */
    }
    
    

     

修改完毕并初始化之后,在主函数中添加循环:

while (1)
  {
    tsl_status = tsl_user_Exec();
    if (tsl_status != TSL_USER_STATUS_BUSY)
    {
      user(tsl_status);
      HAL_Delay(10);
    }
  }

并编辑用户函数:

void USER(tsl_user_status_t status)
{
  switch (status)
  {
    case TSL_USER_STATUS_OK_ECS_OFF:
      BSP_LED_Off(LED4);
      break;
    case TSL_USER_STATUS_OK_ECS_ON:
      BSP_LED_Toggle(LED4);
      break;
    default:
      break;
  }
}
硬件连接如图:当触摸该按键时,板上LED灯变化亮灭情况
此帖出自stm32/stm8论坛

最新回复

感觉U083的意思是想要对于小设计的需求全覆盖,减少外部模块的使用   详情 回复 发表于 2024-6-13 10:00
点赞 关注
个人签名

没用比没有强

 

回复
举报

7044

帖子

11

TA的资源

版主

沙发
 
大佬,这配套可是全套呀,是重新打版还是以前的存货?
此帖出自stm32/stm8论坛

点评

是重新打样的板子,不过屏蔽做的不够好,也没来得及打新一版,就用面包板凑合外围电路了  详情 回复 发表于 2024-6-5 08:39
 
 

回复

166

帖子

1

TA的资源

一粒金砂(高级)

板凳
 
lugl4313820 发表于 2024-6-5 07:56 大佬,这配套可是全套呀,是重新打版还是以前的存货?

是重新打样的板子,不过屏蔽做的不够好,也没来得及打新一版,就用面包板凑合外围电路了

此帖出自stm32/stm8论坛

点评

大佬,你也太强了吧,这试用真是用心用用了呀!  详情 回复 发表于 2024-6-5 09:07
 
个人签名

没用比没有强

 

回复

7044

帖子

11

TA的资源

版主

4
 
电子烂人 发表于 2024-6-5 08:39 是重新打样的板子,不过屏蔽做的不够好,也没来得及打新一版,就用面包板凑合外围电路了

大佬,你也太强了吧,这试用真是用心用用了呀!

此帖出自stm32/stm8论坛
 
 
 

回复

6534

帖子

10

TA的资源

版主

5
 

感觉U083的意思是想要对于小设计的需求全覆盖,减少外部模块的使用

此帖出自stm32/stm8论坛
 
个人签名

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 

回复

166

帖子

1

TA的资源

一粒金砂(高级)

6
 

官方的配套视频有更详细的TSC触摸教程:【STM32U0线上课程】7.1 触摸感应控制外设(TSC)_哔哩哔哩_bilibili

此帖出自stm32/stm8论坛
 
个人签名

没用比没有强

 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/7 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表