A channel of STM32F051 TouchSensingController works differently from all others
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

