Interrupt In prblem
Topic last updated
13 Jan 2011, by
Nitin Bhaskar.
8 replies
Hi,
I am trying to interfacing touchscreen controller ADS7843. I have connected PENIRQ of TS controller to P30 of mbed. Following is the code.....
#include "mbed.h"
SPI spi(p5, p6, p7); // mosi, miso, sclk
DigitalOut cs(p8);
InterruptIn button(p30);
//DigitalIn PI(p30);
Serial pc(USBTX, USBRX); // tx, rx
unsigned short TPReadX(void)
{
unsigned short x=0;
cs = 0;
wait_us(10);
spi.write(0x90);
wait_us(10);
x=spi.write(0x00);
x<<=8;
x+=spi.write(0x00);
wait_us(10);
cs = 1;
x = x>>3;
return (x);
}
unsigned short TPReadY(void)
{
unsigned short y=0;
cs = 0;
wait_us(10);
spi.write(0xD0);
wait_us(10);
y=spi.write(0x00);
y<<=8;
y+=spi.write(0x00);
wait_us(10);
cs = 1;
y = y>>3;
return (y);
}
void flip() {
pc.printf("\rX = 0x%X Y = 0x%X ",TPReadX(),TPReadY() );
wait(0.2);
}
int main() {
unsigned long x_axis;
spi.format(8,3);
spi.frequency(1000000);
cs=1;
pc.printf("\rTS testing\n");
pc.printf("\n");
button.fall(&flip); // attach the address of the flip function to the rising edge
while(1)
{
// while(PI);
//flip();
}
}
The problem is that mbed gets interrupted even if TS is not touched(P30 used as interrupt in). But when I use polling method, I get readings only when I touch the TS.....
Please help on this......
Thanks
Nitin
Replies
Hi Andy,
Thanks ton man. It works fine!!!!!!!!!
Regards
Nitin
Hi,
I got two more problem to deal with. The code I have wriiten above is detecting a continuous touch as single touch. And whenever the touch is released, interrupt is generated and i get some garbage values. This is not seen in polling method.
Thanks
Nitin
Guys!!!! Can anyone help on this????
Thanks
Nitin
Remember, InterruptIn act on rising or falling edges. So a "continuous keyhold" will only present two possible interrupts, once at initial key press and one at release (if configured for both). While holding the key down you won't get more interrupts. If you want you'll need to sample the pins input state but that just brings you back to polling again or using a Ticker to sample the pin.
As for the release producing another interrupt and garbage this sounds like switch bounce causing spurious additional interrupts you are not expecting. So you may need to look at debouncing the input/interrupt. Given that you may have switch bounce problems then it maybe better to not use the InterruptIn but use a Ticker to sample it as a DigitalIn, say every 20ms, and then you can kill the bonce problem and still have the "switch detect on/off" appear as an interrupt (being made by a callback from the Ticker interrupt function). It'll also allow you to detect "switch pressed and held" condition.
#
12 Jan 2011 . Edited: 12 Jan 2011
Hi Andy,
Once again thanks ton for your advice. I am using ticker method now. I got rid of both the problems. It is the better way(though its not the ideal way).
Thanks
Nitin
Nitin,
You believe a ticker is not "ideal". It's really normal practice in situations like this.
To help you out, I just created a library function that you may find usful in your project:-
InterruptIn style DigitalIn debounced with callbacks for pin state change and pin state hold.
It wraps up all the DigitalIn/Ticker/Sampling in a nice easy to use class library that makes implementing this type of input once or more pretty staight forward.
Glad to hear you made progress anyway :) Let me know if you find the library useful and if so I'll add it to my "activly maintained" list of projects (I'm not going to bother maintaining projects no one uses!)
cheers,
Andy
Andy,
Your library is awesome. It helped me great deal. Please bother maintaining it.
Thanks
Nitin
Please log in to post a reply.
Hi,
I am trying to interfacing touchscreen controller ADS7843. I have connected PENIRQ of TS controller to P30 of mbed. Following is the code.....
#include "mbed.h"
SPI spi(p5, p6, p7); // mosi, miso, sclk
DigitalOut cs(p8);
InterruptIn button(p30);
//DigitalIn PI(p30);
Serial pc(USBTX, USBRX); // tx, rx
unsigned short TPReadX(void)
{
unsigned short x=0;
cs = 0;
wait_us(10);
spi.write(0x90);
wait_us(10);
x=spi.write(0x00);
x<<=8;
x+=spi.write(0x00);
wait_us(10);
cs = 1;
x = x>>3;
return (x);
}
unsigned short TPReadY(void)
{
unsigned short y=0;
cs = 0;
wait_us(10);
spi.write(0xD0);
wait_us(10);
y=spi.write(0x00);
y<<=8;
y+=spi.write(0x00);
wait_us(10);
cs = 1;
y = y>>3;
return (y);
}
void flip() {
pc.printf("\rX = 0x%X Y = 0x%X ",TPReadX(),TPReadY() );
wait(0.2);
}
int main() {
unsigned long x_axis;
spi.format(8,3);
spi.frequency(1000000);
cs=1;
pc.printf("\rTS testing\n");
pc.printf("\n");
button.fall(&flip); // attach the address of the flip function to the rising edge
while(1)
{
// while(PI);
//flip();
}
}
The problem is that mbed gets interrupted even if TS is not touched(P30 used as interrupt in). But when I use polling method, I get readings only when I touch the TS.....
Please help on this......
Thanks
Nitin