I am using the KL25Z with code warrior (10.5) for the IDE. I need a external push button that will interrupt my code so that I can have some timers and other bits performed.
Anyone have a simple push button interrupt example I could take a look at? Any help would be appreciated.
Solved! Go to Solution.
Thank you for the reply. I have resolved my problem with the accelerometer. However, I do have a new question.
I want to use a push button switch that i will connect to ground and pin PTA5. i then want to read PTA5 when I press the button and have my program (do something)
Setting are below. Should I set the pull up resistor also? And how do I read PTA5, should I read the memory location?
/* Turn on clock to PortA module */
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;
/* Set the PTB18 pin multiplexer to GPIO mode */
PORTA_PCR5 = PORT_PCR_MUX(1);
/* Set the pins direction to input */
GPIOA_PDDR |= (0<<5);
Hello Anthony ,
You can configure a gpio interrupt , then in the interrupt function you can performed
some actions.
About the example code , you can add Processor Expert component for GPIO, there is
a demo code you can refer to :
Hope it helps
Have a great day,
TIC
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thank you for the reply. I unfortunately am lacking in the skills to pull
this off. Could you please provide some more details? For instance , for
the interrupt do i tie the pin to ground via the button? Is that what
triggers the interrupt?
I am doing a project and need a simple push button that can stop my code I
already have completed.
The idea is the “user” can interact via this simple button and in a sense
communicat with the device. Just a true false situation.
I have tried and tried but not having much luck with it. Any help would be
greatly appreciated.
Hello Anthony Verfaillie,
1. There are five methods can trigger the interrupt , please have a look at Reference manual for your chip:
For example , if you want to connect one pin to ground to trigger an interrupt, you can configure the IRQC to
1000 .
2. Sorry I haven't install CW10.5, I use the latest verion CW11, while it is the same , I create a simple
project , about the pin interrupt, the main initialize code as below:
If you do not want to use Processor Expert ,you can refer to the code write your own code .
If there is problem on your code, you can send it to me .
And add your interrupt code under the below function, or you can also write by yourself.
Hope it helps
Have a great day,
TIC
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
I used what you have sent me with a simple example that evidently at one time worked. My issue is the interrupt handles function. I am not sure how I should read what i assume is a flag that goes high? It looks like in the code fired is the interrupt pin going high? Im just not sure at all.
Hi Anthony,
Sorry I just can't know your question very clearly now.
Do you mean when run your code ,when the PTA0 is high, then run into interrupt function ?
How do you judged ?
If I misunderstood your question , please describe it more detail , thank you .
BR
Alice
Thank you for the reply. I have resolved my problem with the accelerometer. However, I do have a new question.
I want to use a push button switch that i will connect to ground and pin PTA5. i then want to read PTA5 when I press the button and have my program (do something)
Setting are below. Should I set the pull up resistor also? And how do I read PTA5, should I read the memory location?
/* Turn on clock to PortA module */
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;
/* Set the PTB18 pin multiplexer to GPIO mode */
PORTA_PCR5 = PORT_PCR_MUX(1);
/* Set the pins direction to input */
GPIOA_PDDR |= (0<<5);