AnsweredAssumed Answered

stm32l4 CubeMX touch sense

Question asked by kolja111 on Aug 30, 2016
Latest reply on Sep 24, 2017 by george farah
Hi,


I'm trying to figure out, how to use the CubeMX generated project for touch sense aplication. I'm able to detect the change on the 3 touch buttons, but i can't figure out, how to detect on which touch button did the change arrived.


The code:

static void MX_TSC_Init(void)
{


    /**Configure the TSC peripheral 
    */
  htsc.Instance = TSC;
  htsc.Init.CTPulseHighLength = TSC_CTPH_2CYCLES;
  htsc.Init.CTPulseLowLength = TSC_CTPL_2CYCLES;
  htsc.Init.SpreadSpectrum = DISABLE;
  htsc.Init.SpreadSpectrumDeviation = 0;
  htsc.Init.SpreadSpectrumPrescaler = TSC_SS_PRESC_DIV1;
  htsc.Init.PulseGeneratorPrescaler = TSC_PG_PRESC_DIV64;
  htsc.Init.MaxCountValue = TSC_MCV_255;
  htsc.Init.IODefaultMode = TSC_IODEF_OUT_PP_LOW;
  htsc.Init.SynchroPinPolarity = TSC_SYNC_POLARITY_FALLING;
  htsc.Init.AcquisitionMode = TSC_ACQ_MODE_NORMAL;
  htsc.Init.ChannelIOs = TSC_GROUP2_IO1|TSC_GROUP2_IO2|TSC_GROUP2_IO3;
  htsc.Init.SamplingIOs = TSC_GROUP2_IO4;
  if (HAL_TSC_Init(&htsc) != HAL_OK)
  {
    Error_Handler();
  }

}

//main
HAL_TSC_IODischarge(&htsc, ENABLE);
     
 if (HAL_TSC_Start(&htsc) != HAL_OK)
    {
      Error_Handler();
    }

while (1)
  {

    if (HAL_TSC_Start(&htsc) != HAL_OK)
    {
      Error_Handler();
    }
          
   while (HAL_TSC_GetState(&htsc) == HAL_TSC_STATE_BUSY)
    {}
 __HAL_TSC_CLEAR_FLAG(&htsc, (TSC_FLAG_EOA | TSC_FLAG_MCE));

if (HAL_TSC_GroupGetStatus(&htsc, TSC_GROUP2_IDX) == TSC_GROUP_COMPLETED)
    {
      // Store the acquisition value 
      uhTSCAcquisitionValue = HAL_TSC_GroupGetValue(&htsc, TSC_GROUP2_IDX);
               
    }
          HAL_TSC_IODischarge(&htsc, ENABLE);
}

Thanks for any help.

Outcomes