Hi!
I'm working on LPC1857 controller and I required to test the i2c code I wrote. As far as I can see,as per data-sheet I've got all right with code. While the application is run, i2c is disabled.
I debugged and found that while clearing only the i2c-interrupt flag the entire control register for i2c is cleared, thereby disabling i2c.
>LPC_I2C0->CONCLR |= 0X00000008; // clear i2c interrupt only
Hope I made my doubt clear.
Thanks for anyone suggest anything to avoid this problem.
LPC_I2C0->CONCLR |= 0X00000008;
You do a read/modify/write there when you perform a bit-or.
Without using your specific processor I still wonder if you really need to do that.
A register named "CLR" normally don't require any read/modify/write.
Can't you just write the following?
LPC_I2C0->CONCLR = 0X00000008;
No.
I could have done that but for the reason that direct assignment as you suggested will simply clear enable bit for i2c along with the flag.
Anyway, thanks for trying to help, and further help is welcome!
Sorry Pertermark!
I just realised what you said. I mistook it.
I think I'll be able to do it now.
"I could have done that but for the reason that direct assignment as you suggested will simply clear enable bit for i2c along with the flag."
You know that, or you just believe that?
A register with the name CLR normally only clear the bits that you write a one to, and are available specifically to remove the synchronization issues you get with read/modify/write by processor instructions
I.e. the actual modify is performed inside the peripherial instead of requiring a processor instructions to do it. This makes it thread-safe by having the clear be atomic.
Hi again.
I've got the previous problem solved. But i2c is not working as expected, instead goes to an end of session as soon as it starts, but it doesn't go like that while I do Single step debug where it works perfect. I thought of lowering frequency will help, but no.
Can you throw some light on this?
Thanks.
When single-stepping, the I2C controller often still operates at full-frequency.
So if the program works when single-stepping but not when running full-speed, then you might write to an I2C register before the previous operation has finished. When single-stepping, you add extra time between the instructions of your main loop, giving the I2C interface enough time.
Hi, I have the same problem using LPC 1227, while clearing only the i2c-interrupt flag the entire control register for i2c is cleared, disabling i2c. How did you solve that? Thank you!