Friday, 30 January 2015

microcontroller - Interfacing a four wire resistive touch screen with STM32F429DISCOVERY


I'm trying to interface a 4-wire resistive touchscreen to a STM32F429 Discovery board but I can't figure out how it works. I want the MCU to detect a touch so I configured the 4 pins like this:


X+ --> input w/pullup connected to EXTI external interrupt 
X- --> input floating (tristated)
Y+ --> input floating (tristated)
Y- --> output to GND

in this configuration I should be able to detect a touch and trigger an interrupt on the EXTI line so I can enter a ISR and sample the x and y values with the ADC. But when I connect the X- pin the X+ pin goes to near GND. It seems like current flows between X+ and X- (so the X- is not tristated?). Here's the code I use to configure the GPIO pins:



GPIO_InitTypeDef gpio;
gpio.Pin = GPIO_PIN_2 | GPIO_PIN_1;
gpio.Mode = GPIO_MODE_INPUT;
gpio.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &gpio);

gpio.Pin = GPIO_PIN_0;
gpio.Mode = GPIO_MODE_INPUT;
gpio.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &gpio);


gpio.Pin = GPIO_PIN_5;
gpio.Mode = GPIO_MODE_OUTPUT_PP;
HAL_GPIO_Init(GPIOA, &gpio);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);

/* initialization using registers, works the same as above */

// /* Xr and Yu open (input floating) */

// GPIOA->MODER &= ~(GPIO_MODER_MODE2 | GPIO_MODER_MODE1);
// GPIOA->PUPDR &= ~(GPIO_PUPDR_PUPD2 | GPIO_PUPDR_PUPD1);
//
// /* Xl input with pull-up */
// GPIOA->MODER &= ~GPIO_MODER_MODE0;
// GPIOA->PUPDR |= GPIO_PUPDR_PUPD0_0;
//
// /* Yd to GND (output set to 0) */
// GPIOA->MODER |= GPIO_MODER_MODE5_0;
// GPIOA->ODR &= ~GPIO_ODR_OD5;


I can't understand what I am doing wrong or how to configure the tristated pins correctly so they don't pull down the X+ pin.



Answer



On the STM32F429 Discovery board, PA1 and PA2 are directly connected to the interrupt outputs of the L3GD20 motion sensor chip, which are by default active high. That means, they should output a logic low signal until some (programmable) event occurs. Which, as the part is presumably not initialised, never happens.


The X+ and X- pins of a resistive touchscreen are connected with a resistor, typically with a value below 1kΩ. Connecting X+ to PA0 and X- to a low-level output effectively created a 1kΩ pulldown on PA0.


PA0 is connected to ground through a 220k pulldown resistor (part of the debouncing circuit of the blue pushbutton) on the discovery board as well, so it's not a great choice for an analog connection either.


You can free up PA0 by cutting a solder bridge somewhere, but PA1 and PA2 are apparently directly wired to the motion sensor.


You should consult the User Manual of your board and find 4 unused pins, two of them must be usable as ADC channels. Unfortunately the onboard LCD takes up most of the ADC pins, but there are a few left, namely PA5, PC3, and PF6. Pick two of them for the analog-digital conversion, and find two unused pins for the other two terminals. Opening the predefined STM32F429-Discovery project in STM32CubeMX is perhaps the simplest way to find the usable pins.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...