I'm working with the MK10DN512VLK10.
I'm trying to configure a GPIO pin as an input and to interrupt when the line goes to zero. For some reason the interrupt works but it always hits an I2C interrupt instead of my GPIO interrupt.
I'm setting the PORTx_PCRn register(shown here: https://imgur.com/vl5Tk1X ) to 0x00080100
IRQC = 8, interrupt when logic zero
MUX = 1, Alternative 1 (GPIO)
Alternative 1 is GPIO, shown here: https://imgur.com/OBEzj9u
I also make sure the direction is set to input by writing to a 0 this register, in the corresponding bit position https://imgur.com/9tDGITD
My code looks something like this(obviously simplified a bit):
When I run this and the pin goes to zero, that triggers the interrupt but I hit a I2C handler(which I don't have a function for):
Can anyone tell me why I'm hitting the I2C interrupt and not the PORT C interrupt? One thing I have noticed is that the pin I'm using can be used for I2C (https://imgur.com/OBEzj9u alt function 2). I've also tested other GPIO pins and it seems like it always hits that alt function 2 interrupt, even though I'm configuring the pin as GPIO(alt function 1).
Thanks.
Solved! Go to Solution.
Rick
I made a mistake - since the K10 has more that 63 interrupts the vector table needs to be on a 512 byte boundary (0, 0x200, 0x400, etc.) if not you get the effect that you saw.
This is because the NVIC uses only the lower 9 bits of the address (0x00 .. 0x1ff). Subsequent when using 0x100 as vector base address 0x100 + (105*4) = 0x2a4 (the address of the Port C interrupt) is seen as (0x2a4 & 0x1ff) by the NVIC, which is 0xa4 -> the I2C1 vector address.
Using 0x200 as Vector base offset gives 0x200 + (105*4) = 0x3a4 - seen by the NVIC as 0x1a4 and thus OK (same for 0x000, 0x400, 0x600, 0x800 etc.)
Regards
Mark
Thanks for the response. I think I've found the issue and I would like it if someone could shed some light on it.
It seems like the issue was stemming from where the flash segment was located. I changed the location and it works. You can see below the changes I made.
Can anyone tell me why having the flash segment start at 0x8100 vs 0x8200 makes a difference?
Rick
I made a mistake - since the K10 has more that 63 interrupts the vector table needs to be on a 512 byte boundary (0, 0x200, 0x400, etc.) if not you get the effect that you saw.
This is because the NVIC uses only the lower 9 bits of the address (0x00 .. 0x1ff). Subsequent when using 0x100 as vector base address 0x100 + (105*4) = 0x2a4 (the address of the Port C interrupt) is seen as (0x2a4 & 0x1ff) by the NVIC, which is 0xa4 -> the I2C1 vector address.
Using 0x200 as Vector base offset gives 0x200 + (105*4) = 0x3a4 - seen by the NVIC as 0x1a4 and thus OK (same for 0x000, 0x400, 0x600, 0x800 etc.)
Regards
Mark
Thank you so much! This makes a lot of sense now.
Hi Rick
On the K10 the Port C interrupt has an ID or 89 and I2C1's ID is 25.
I see two possibilities for such a problem:
1. You are using the wrong headers/vectors for the part
2. You have located your VTOR (respectively your interrupt vector table) at an address that is not divisible by 256
Regards
Mark
Complete Kinetis solutions, training and support: http://www.utasker.com/kinetis.html
Kinetis K60/K10:
- http://www.utasker.com/kinetis/TWR-K60N512.html
- http://www.utasker.com/kinetis/TWR-K60D100M.html
- http://www.utasker.com/kinetis/TWR-K60F120M.html
- http://www.utasker.com/kinetis/ELZET80_NET-KBED.html
- http://www.utasker.com/kinetis/ELZET80_NET-K60.html