cancel
Showing results for 
Search instead for 
Did you mean: 

stm32l4 CubeMX touch sense

Rudas.Robert
Associate II
Posted on August 30, 2016 at 11:56

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.

4 REPLIES 4
slimen
Senior
Posted on August 30, 2016 at 15:28

Hi,

I recommended you to start from the TouchSensing application under the STM32CubeL4 package:

STM32Cube_FW_L4_V1.5.0\Projects\STM32L476G_EVAL\Applications\TouchSensing

You can get inspiration from this example and compare with your code to identify what you have missed. 

Please note that you may find more details on how to use the TSL with this manual 

http://www.st.com/content/ccc/resource/technical/document/user_manual/group0/d6/4c/20/0d/a1/c1/4c/99/DM00210526/files/DM00210526.pdf/jcr:content/translations/en.DM00210526.pdf

 ''Developing applications on STM32Cube with touch sensing''.

and

http://www.st.com/content/ccc/resource/training/technical/product_training/6b/ea/47/06/18/83/43/67/STM32L4_Peripheral_Touchsense.pdf/files/STM32L4_Peripheral_Touchsense.pdf/jcr:content/translations/en.STM32L4_Peripheral_Touchsense.pdf

.

Regards

Rudas.Robert
Associate II
Posted on September 01, 2016 at 12:15

Hi, 

I have already looked at the example, but i got lost in the code. That's the reason I wrote to the forum. As I mentioned i can detect the change of the acquisition value for the group, but i would like to know if there is an easy way to detect on which IO (TSC_GROUP2_IO1, TSC_GROUP2_IO2, TSC_GROUP2_IO3) of the group is responsible for the change.

Rudas.Robert
Associate II
Posted on September 02, 2016 at 12:39

Hi,

i have looked at the

http://www.st.com/content/ccc/resource/training/technical/product_training/6b/ea/47/06/18/83/43/67/STM32L4_Peripheral_Touchsense.pdf/files/STM32L4_Peripheral_Touchsense.pdf/jcr:content/translations/en.STM32L4_Peripheral_Touchsense.pdf

. The reference circuit that i used is shown on the 6-th picture. The STM32L4 Eval is using only 1 touch key. So i have looked at the examples for other eval boards. They all use 1 sampling capacitor for each channel, so they also don't tell me the method.

george farah
Associate
Posted on September 24, 2017 at 13:20

Hi,

I want to ask you on which board are you working?

I want to build a capacitive touch sensor on a Nucleo-64 board, I used the same reference circuit that you have used and I wrote a code but it did not work. I have tried tried to use your code, it did not work either. I am not able to detect any change on any touch buttons! if you have any helpful hint, I will appreciate it.

Thank you.