2020-05-20 04:26 AM
In Group 1 G1_IO4 is a sampling capacitor and G1_IO3 is a sheild and in Group 2 G2_IO2 is sampling capacitor and G2_IO1 is input touch key. In Group 3 G3_IO4 is a sampling capacitor and G3_IO2 is a input touch key. so when i programmed with this configuration it detect touch from the shield not from the touch keys.
My touch key code is this
if(MyTKeys[0].p_Data->StateId == TSL_STATEID_DEB_RELEASE_DETECT)
{
HAL_GPIO_WritePin(LED2_GPIO_Port,LED2_Pin,RESET);
HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,SET);
}
if(MyTKeysB[1].p_Data->StateId == TSL_STATEID_DEB_RELEASE_DETECT)
{
HAL_GPIO_WritePin(LED2_GPIO_Port,LED2_Pin,SET);
HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,RESET);
}
Please give me the solution why the touch detect from shield not form Touch keys.
2020-07-03 06:54 AM
Hello,
You can not get StateID from what we call Active-Shield. See AN5105.
Find below sw example matching your setup; 2 keys + active shield:
file stm32wbxx_it.c:
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
extern int TSCidxGroup;
extern int TSCAcqDone;
/* USER CODE END TD */
void TSC_IRQHandler(void)
{
/* USER CODE BEGIN TSC_IRQn 0 */
/* USER CODE END TSC_IRQn 0 */
HAL_TSC_IRQHandler(&htsc);
/* USER CODE BEGIN TSC_IRQn 1 */
TSL_acq_BankGetResult(TSCidxGroup, 0, 0);
TSCidxGroup++;
if (TSCidxGroup > TSLPRM_TOTAL_BANKS-1)
{
TSCidxGroup=0;
// Start process to handle all results, we can do after each interrupt but... No.
TSCAcqDone++;
}else{
// We restart bank acquisition only if we have mode than 1 bank (this is a choice....)
TSL_acq_BankConfig(TSCidxGroup);
TSL_acq_BankStartAcq_IT();
}
/* USER CODE END TSC_IRQn 1 */
}
file tsc.c:
void MX_TSC_Init(void)
{
/** Configure the TSC peripheral
*/
htsc.Instance = TSC;
htsc.Init.CTPulseHighLength = TSC_CTPH_16CYCLES;
htsc.Init.CTPulseLowLength = TSC_CTPL_16CYCLES;
htsc.Init.SpreadSpectrum = DISABLE;
htsc.Init.SpreadSpectrumDeviation = 1;
htsc.Init.SpreadSpectrumPrescaler = TSC_SS_PRESC_DIV1;
htsc.Init.PulseGeneratorPrescaler = TSC_PG_PRESC_DIV4;
htsc.Init.MaxCountValue = TSC_MCV_16383;
htsc.Init.IODefaultMode = TSC_IODEF_OUT_PP_LOW;
htsc.Init.SynchroPinPolarity = TSC_SYNC_POLARITY_FALLING;
htsc.Init.AcquisitionMode = TSC_ACQ_MODE_NORMAL;
htsc.Init.MaxCountInterrupt = DISABLE;
htsc.Init.ChannelIOs = TSC_GROUP2_IO1|TSC_GROUP3_IO2;
htsc.Init.ShieldIOs = TSC_GROUP1_IO3;
htsc.Init.SamplingIOs = TSC_GROUP1_IO4|TSC_GROUP2_IO2|TSC_GROUP3_IO4;
if (HAL_TSC_Init(&htsc) != HAL_OK)
{
Error_Handler();
}
}
file main.c:
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "touchsensing.h"
#include "tsc.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "tsl.h"
#include "tsl_user.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
int TSCidxGroup=0;
int TSCAcqDone=0;
extern __IO TSL_tTick_ms_T ECSLastTick;
#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)
#define TKEY_MEAS(NB) (MyTKeys[(NB)].p_ChD->Meas)
#define TKEY_STATEID(NB) (MyTKeys[(NB)].p_Data->StateId)
/* USER CODE END PTD */
....
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_TSC_Init();
MX_TOUCHSENSING_Init();
/* USER CODE BEGIN 2 */
TSCidxGroup=0;
TSCAcqDone=0;
TSL_acq_BankConfig(TSCidxGroup);
TSL_acq_BankStartAcq_IT();
__WFI();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if(TSCAcqDone != 0){
TSCAcqDone = 0;
TSL_obj_GroupProcess(&MyObjGroup);
TSL_dxs_FirstObj(&MyObjGroup);
if (TSL_tim_CheckDelay_ms(TSLPRM_ECS_DELAY, &ECSLastTick) == TSL_STATUS_OK)
{
TSL_ecs_Process(&MyObjGroup);
}
// Get sensor status
if(!TKEY_CAL(0) && !TKEY_CAL(1)){
if(TKEY_DET(0))
{
HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,SET);
}else{
HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,RESET);
}
if(TKEY_DET(1))
{
HAL_GPIO_WritePin(LED2_GPIO_Port,LED2_Pin,SET);
}else{
HAL_GPIO_WritePin(LED2_GPIO_Port,LED2_Pin,RESET);
}
}
TSCidxGroup = 0;
TSCAcqDone = 0;
TSL_acq_BankConfig(TSCidxGroup);
TSL_acq_BankStartAcq_IT();
}else{
//__WFI();
HAL_Delay(1); // Put HAL delay instead of __WFI() to follow measure activities using debuger
}
}
/* USER CODE END 3 */
}