Hi, this is my code. I have removed #includes and so on. I want the PORTB_IRQHandler() to get called when I press a switch button attached to pin B7. My platform is KL05z_FRDM and I have started by modifying the LED_BLINK example :smileyhappy:
void PORTB_IRQHandler() {
LED1_TOGGLE;
}
void Delay( uint32_t uiCount ) {...}
int main (void)
{
#if(defined(CW))
sysinit();
#endif
gpio_init();
printf("\nRunning the INT project.\n");
while(1)
{
}
}
I modified freedom_gpio.h to contemplate this:
#define SW1_PORT B
#define SW1_BIT 7
However, I'm not getting any success. So my questions are few and simple:
Ok, let me know and have a nice weekend! :smileyhappy:
已解决! 转到解答。
Hi,
Here you find the complete project. In the file kinetis_sysinit.c you find the declaration of the vector table. I found that that the vector table have a mistake, the last declaration is PORTD_IRQHandler instead of PORTB_IRQHandler but this device only support interrupts of the PORTB, but just a little change and this is fixed.
When you enable the interrupts of the PORTB and an interrupt occur the program jump to the routine in the Vector Table, in this case PORTB_IRQHandler. In the file LED_blink.c the interrupt service routine is declared and this is the one that will run each interrupt of the PORTB.
I hope this information can help you.
Regards,
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. It would be nice!
-----------------------------------------------------------------------------------------------------------------------
Hi Kazola,
The gpio_init function performs a basic configuration of the GPIOs. It initializes the LED pins as output and the SW pins as inputs but it does not configure the interrupts.
For doing this, you will need to configure the PORTx_PCRy register, enable the ISR in the NVIC register and set your ISR in the Vector Table. It is simpler than it seems. If you want, let me know which IDE you are using so we can provide a working example.
By the way, if you are using CodeWarrior, you should try with ProcessorExpert. It is a graphical interface that will create the initialization code you need in a few clicks.
Saludos
Santiago Lopez
I'm almost there, Santiago! Now the thing in the debugger jumps to "default_handler", so I think I'm missing the "set your ISR in the Vector Table" part?
Let me know! :smileyhappy:
void PORTB_IRQHandler() {
if (PORTB_ISFR & (1<<7))
{
LED2_TOGGLE;
}
PORTB_ISFR=0xFFFFFFFF;
}
void Delay( uint32_t uiCount )
{
uint32_t i,j;
for( i=0;i<uiCount;i++ )
{
for(j=0;j<100;j++);
}
}
/********************************************************************/
int main (void)
{
#if(defined(CW))
sysinit();
#endif
gpio_init();
EnableInterrupts;
enable_irq(INT_PORTB -16);
PORTB_PCR7 |= PORT_PCR_MUX(1)|PORT_PCR_IRQC(0xA);
printf("\nRunning the INT project.\n");
while(1)
{
}
}
Hi Kazola
As Adrian mentioned, there is an error in the interrupt vector table (this if you are using CodeWarrior). The interrupt vector table is defined in the kinetis_sysinit.c file which is the file where you must register your ISR.
By default, CodeWarrior set some names to the ISR functions so you don´t have to register each function. In this case, for port B, it should be PORTB_IRQHandler (just like you wrote it). Nevertheless, for some reason they forgot to change the name of this ISR, and instead, used PORTD_IRQHandler. To fix this you have two options:
Once again, this will only work if you are using CodeWarrior. If you are using IAR you will actually need to register the function in the vector table. Let me know if this solution works for you, or if you are using IAR so I can provide with the right instructions.
Saludos
Santiago Lopez
Hi Santiago!
its a nice post actually,
i have searching for past one week to replace that kinetics_sysinit.c in iar. so please help me to change the file content suitable for IAR environment.
Thanks in advance....
Thanks Santiago!
I like I have this thing working now :smileyhappy:
If soon Freescale is able to have an example code base as nice as these forums, it will be just great :smileyhappy:
Have a nice day.
Hi,
To make use of the interrupts you need to enable the use of the interrupts. In the attachments you can find the LED_blink.h that I modified to use interrupts. In the freedom_gpio.h I did the same modification you did:
#define SW1_PORT B
#define SW1_BIT 7
Please check the attached file, if you have any question do not hesitate to ask.
Hope this help.
Regards,
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. It would be nice!
-----------------------------------------------------------------------------------------------------------------------
Hi,
Here you find the complete project. In the file kinetis_sysinit.c you find the declaration of the vector table. I found that that the vector table have a mistake, the last declaration is PORTD_IRQHandler instead of PORTB_IRQHandler but this device only support interrupts of the PORTB, but just a little change and this is fixed.
When you enable the interrupts of the PORTB and an interrupt occur the program jump to the routine in the Vector Table, in this case PORTB_IRQHandler. In the file LED_blink.c the interrupt service routine is declared and this is the one that will run each interrupt of the PORTB.
I hope this information can help you.
Regards,
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. It would be nice!
-----------------------------------------------------------------------------------------------------------------------