cancel
Showing results for 
Search instead for 
Did you mean: 

A channel of STM32F051 TouchSensingController works differently from all others

Willunen
Associate III

The TSC of the STM32F051K4 works fine for all channels except for channel 1 of group 2 (G2_IO1). It does work but gives values much lower than all other channels. Also the delta (when your finger is on the touchpad is way lower than for other channels.

1 - I tried changing the acquiring frequency, pulse high an low times, the IO-default-mode, prescaler values, max-count-values, nothing seems to help.

2 - What I tried was to disconnect the G2_IO1 pin completely, even then the values of it are much below other channels. So it wasn't a problem of the touchpad.

3 - Next I moved the sample capacitor to G2_IO1 and connected the touchpad to G2_IO4 (where the capacitor used to be). Instantly the values returned to normal. But all other groups work fine with the sample-capacitor on Gx_IO4.

4 - Then I build a second board with a fresh STM32F051K4, with exactly the same strange result, G2_IO1 seems not to want to be used as a touch sensor. Why?

I do not use the Touch library from ST and I'm no fan of the HAL either. I use LowLayer for alomost everything. Unfortunately there is no LowLayer configuration for the TSC, so I had to make that myself. So it is very possible that I have made some silly mistake that gives the strange effect, but I cannot find anything odd in my code. Maybe you can?

void TSC_InitController(void)
{
	LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
 
	TSC_DeInitController();
 
	LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
	LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
	LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_TSC);
 
	//TSC sampling capacitor G2
	GPIO_InitStruct.Pin = LL_GPIO_PIN_7;
	GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
	GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
	GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
	GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
	GPIO_InitStruct.Alternate = LL_GPIO_AF_3;
	LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
	//TSC sampling capacitor G3
	GPIO_InitStruct.Pin = LL_GPIO_PIN_1;
	GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
	GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
	GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
	GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
	GPIO_InitStruct.Alternate = LL_GPIO_AF_3;
	LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
	//TSC sampling capacitor G4
	GPIO_InitStruct.Pin = LL_GPIO_PIN_12;
	GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
	GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
	GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
	GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
	GPIO_InitStruct.Alternate = LL_GPIO_AF_3;
	LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
	//TSC touchkeys G2
	GPIO_InitStruct.Pin = LL_GPIO_PIN_4| LL_GPIO_PIN_5 | LL_GPIO_PIN_6;
	GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
	GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
	GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
	GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
	GPIO_InitStruct.Alternate = LL_GPIO_AF_3;
	LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
	//TSC touchkeys G3
	GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
	GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
	GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
	GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
	GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
	GPIO_InitStruct.Alternate = LL_GPIO_AF_3;
	LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
	//TSC touchkeys G4
	GPIO_InitStruct.Pin = LL_GPIO_PIN_9 | LL_GPIO_PIN_10 | LL_GPIO_PIN_11;
	GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
	GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
	GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
	GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
	GPIO_InitStruct.Alternate = LL_GPIO_AF_3;
	LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
	//set tsc control register
	TSC->CR |= (uint32_t)  (TSC_CR_CTPH_1);				//charge transfer pulse high = 3
	TSC->CR |= (uint32_t)  (TSC_CR_CTPL_1);				//charge transfer pulse low = 3
	TSC->CR &= (uint32_t) ~(TSC_CR_SSD);				//SpreadSprectum deviation = 1 (not used)
	TSC->CR &= (uint32_t) ~(TSC_CR_SSE);				//en/dis-able SpreadSpectrum (not used)
	TSC->CR &= (uint32_t) ~(TSC_CR_SSPSC);				//SpreadSpectrum prescaler = 1 (not used)
	TSC->CR |= (uint32_t)  (TSC_CR_PGPSC_1);			//PulseGenerator prescaler HCLK/4
	TSC->CR |= (uint32_t)  (TSC_CR_MCV_2);				//Max count value = 4095
	TSC->CR &= (uint32_t) ~(TSC_CR_IODEF);				//IO default mode: output_pp low
	TSC->CR &= (uint32_t) ~(TSC_CR_SYNCPOL);			//Sync pin polarity: falling edge
	TSC->CR &= (uint32_t) ~(TSC_CR_AM);					//Acquisition mode: normal
	TSC->CR &= (uint32_t) ~(TSC_CR_START);				//Acquisition NOT started
 
	//disable schmitt triggers
	TSC->IOHCR  &= (uint32_t) ~(TSC_IOHCR_G2_IO1 | TSC_IOHCR_G2_IO2 | TSC_IOHCR_G2_IO3 | \
												   TSC_IOHCR_G3_IO2					   | \
								TSC_IOHCR_G4_IO1 | TSC_IOHCR_G4_IO2 | TSC_IOHCR_G4_IO3 );
 
	//set touch input channels
	TSC->IOCCR  |= (uint32_t)  (TSC_IOHCR_G2_IO1 | TSC_IOCCR_G2_IO2 | TSC_IOCCR_G2_IO3 | \
												   TSC_IOCCR_G3_IO2                    | \
								TSC_IOCCR_G4_IO1 | TSC_IOCCR_G4_IO2 | TSC_IOCCR_G4_IO3 );
 
	//enable analog switch's
	TSC->IOASCR |= (uint32_t)  (TSC_IOASCR_G2_IO4 | TSC_IOASCR_G3_IO3 | TSC_IOASCR_G4_IO4);
 
	//sampling capacitors
	TSC->IOSCR  |= (uint32_t)  (TSC_IOSCR_G2_IO4 | TSC_IOSCR_G3_IO3 | TSC_IOSCR_G4_IO4);
 
	//enable groups
	TSC->IOGCSR |= (uint32_t)  (TSC_IOGCSR_G2E | TSC_IOGCSR_G3E | TSC_IOGCSR_G4E);
 
	NVIC_SetPriority(TSC_IRQn, 0);
	NVIC_EnableIRQ(TSC_IRQn);
}

Thanks,

Wilko

1 ACCEPTED SOLUTION

Accepted Solutions

0690X00000Bw3mIQAR.png

This information is present in some of the relevant datasheets, e.g. for the 'L0; but absent from 'F0 DS (as footnote to  Capacitive sensing GPIOs available on XXXX devices table).

@Imen DAHMEN​ , can you please initiate an improvement for the relevant 'F0 DS?

Thanks,

JW

View solution in original post

5 REPLIES 5

Which pin is it? What is connected to it internally? From which VDD is this pin supplied? What else do you have connected to this chip and what does the code do? Try to search for this particular pin in errata, DS, RM, this site.

JW

0690X00000Bw3mIQAR.png

This information is present in some of the relevant datasheets, e.g. for the 'L0; but absent from 'F0 DS (as footnote to  Capacitive sensing GPIOs available on XXXX devices table).

@Imen DAHMEN​ , can you please initiate an improvement for the relevant 'F0 DS?

Thanks,

JW

That's it.

I have it connected to PA4 (G2_IO1). And the description of reduced sensitivity is exactly what I see. But I do not see a reduced sensitivity on PA5 (G2_IO2).

As you mentioned to Imen, there is no mention of it in the DS, RM or Errata. But I had not read the UM...

So, I have to change the PCB.

Thanks !

Wilko

> But I had not read the UM...

No wonder, it's a "library-related" UM - why would anybody who wouldn't want to use "library" read it?

Besides DS, this ought to go to the basic touch AN, presumably AN5105. But that one, instead of giving clean examples or pointers to such, just pursues the idiotic CubeMX clicking method...

It does not even contain links/pointers to https://www.st.com/content/st_com/en/products/embedded-software/mcu-mpu-embedded-software/stm32-embedded-software/stm32-standard-peripheral-library-expansion/32f0-touch-lib.html#resource and the related UM1606.

JW

@Vincent Onde​ , see any room for improvement (besides getting rid of the "modern feel and look")?

Now, that Application Note (AN5105) I had read. And AN4299, AN4310, AN4312 and AN4316. Reading UM1606 now =)

BTW. AN4299 does mention that not all sensors will have the same sensitivity but I didn't think that they meant the port, but the combination of the pads, shielding, groundplane, enclosure, etc.