Hello,
I am writing an I2C master transmitter object. The problem I am having is that the IRQ Handler for I2C1 is not firing. According to the manual, it should fire after the start condition is sent and the status register is 0x08. When I step through the code with the debugger, the status code is 0x08. I am using an MCB1700 development board. Why is it not firing? Did I not configure something properly? For tests, All I am doing is toggling an LED on when the interrupt fires. Once I solve this problem, I will write the rest of the code.
#include <stdio.h> #include <LPC17XX.h> #include "GPIO1Output.h" GPIO1Output out(P1_28); __irq void I2C1_IRQHandler(void) { if (LPC_I2C1->I2STAT == 0x08) { out.Set(); } } int main(void) { // Initialize I2C. LPC_PINCON->PINSEL0 = 0x0F; LPC_PINCON->PINMODE_OD0 = 0x03; NVIC_EnableIRQ(I2C1_IRQn); LPC_I2C1->I2CONSET = 0x40; LPC_I2C1->I2CONSET = 0x20; int status = LPC_I2C1->I2STAT; }
It always helps if you explicitly state what processor you're using. Don't just leave us to infer it from other details.
The MCB1700 comes in two versions - with different processors! Which one, exactly, do you have?
http://www.keil.com/mcb1700/
"I am writing an I2C master transmitter object"
Before you do that, have you looked at supplied examples - from Keil and NXP ?
__irq void I2C1_IRQHandler(void)
One of the "key features" claimed by ARM for the new Cortex-M3 was that it didn't require special interrupt handlers - so why are you adding the __irq here...?
I am using the LPC1768. Yes, I have looked at the examples, and according to them and what I did, in my mind, the interrupt should fire.
Mr Andrew Neil. I am just curious what is your day job? I find it hard to believe that you have time to actually do any work, given the number of posts you have made to various forums (Keil and ST to name just two). You seem to have an answer/opinion about everything. I can only hope that you're self employed so you're not doing all this on your employer's time :)
I am just curious what is your day job?
He's a carpenter, of course! I think Andy is indeed self-employed - he once posted a link to his company's website (or was it the good old captain?).
I forgot to post a :-)
Come on, does anyone have a solution to this issue I am having?
In main, I'm missing a
for (;;) { }
don't have time look in more detail right now...
The infinite loop does not make a difference.
"I can only hope that you're self employed so you're not doing all this on your employer's time :)"
now you have scared him off.
When I run this code with the debugger, the program quits running after it hits the line where the command LPC_I2C1->I2CONSET = 0x20; (see code) is. The debugger t1 time just keeps increasing and nothing happens. The same thing happens even when I am not debugging. Does this give anyone a clue?
#include <stdio.h> #include <LPC17XX.h> #include "GPIO1Output.h" GPIO1Output out(P1_28); void I2C1_IRQHandler(void); int main(void) { // Initialize I2C. LPC_PINCON->PINSEL0 = 0x0F; LPC_PINCON->PINMODE_OD0 = 0x03; NVIC_EnableIRQ(I2C1_IRQn); LPC_I2C1->I2CONSET = 0x40; LPC_I2C1->I2CONSET = 0x20; // Program does not get beyond this line. while(1); } void I2C1_IRQHandler(void) { if (LPC_I2C1->I2STAT == 0x08) { LPC_I2C1->I2CONCLR = 0x20; out.Set(); } }
Did you set any breakpoint in your ISR?
Are you making sure that whatever reason you get into the ISR are resulting in the interrupt source being cleared?
I did put breakpoints in the ISR. They are never reached.
Did you power the i2c peripheral?
In the configuration wizard for the system_LPC17xx.c there is a check by the I2C1 in the Power Control for Perepherials Register (PCONP), so yes, power is enabled here. Is there something else? I disabled power to all perepherials I am not using.
Where in the ISR did you set your breakpoint?
If an interrupt doesn't happen, then the single-stepping would normally continue as normal. If the processor does not continue to single-step, then you have to consider problems with stack space for the interrupt, or that you do reach the interrupt but get jumped to another place than you thought. Or that you reach the ISR again and again and again because you don't clear the interrupt.