Hi, I can't get the I2C peripheral to work on an NXP LPC1114/301. I have reduced the code down to a simple test which sets the I2C speed registers I2C0SCLH and I2C0SCLL. This works when run in simulator mode - looking at memory address 0x40000010 and 0x40000014, and the I2C 0 Interface peripheral status box the code works; also the memory here is writable and changing the value changes the I2C peripheral values. However when running the code on the target (actually the processor end of a LPC1114 LPC XPresso board and Keil Ulink 2) both the memory and I2C peripheral status remain unchanged. Changing the memory location 0x40000010, which begins with the default value of 4, just changes back to 4. The same happens if you try to change I2C0SCLL/H in the I2C peripheral box. The target has been running code successfully (UART, timers, capture compare etc.) so seems pretty much alive. Here's the test code:
#include "lpc11xx.h" int main(void) { SystemInit(); LPC_GPIO1->DIR = 0xEBE; LPC_GPIO2->DIR = 0x7FF; LPC_GPIO3->DIR = 0; LPC_IOCON->RESET_PIO0_0 = 0x30; // RESET function LPC_IOCON->PIO0_4 = 0x01; // SCL, Fast mode I2C LPC_IOCON->PIO0_5 = 0x01; // SDA, Fast mode I2C LPC_IOCON->SWCLK_PIO0_10 = 0; // SWD LPC_IOCON->SWDIO_PIO1_3 = 0x80; // I2C LPC_I2C->SCLH = 60; // 400kHz, 50% duty LPC_I2C->SCLL = 60; LPC_I2C->CONCLR = 0xFF; // clear all I2C control bits while (1); }
I look forward to fixing this, it's been bugging me for days :-( I'm wondering if I haven't set up something somewhere. The I2C clock is enabled in system_LPC11xx.c. The chip has a 12MHz crystal and 4x PLL so it's running at 48MHz.
Thanks, John
I haven't checked the datasheet for your processor, but is the I2C peripherial powered? This is a quite common error when writes to registers don't "take". Many modern processors have quite a number of power-enable bits to turn on/off the power to the different UART, ADC, ... to allow adaptive power-save depending on the current needs.
Hi, Found it!!!
LPC_SYSCON->PRESETCTRL = 0x07; // de-assert reset for SPI and I2C modules
Also beware of the supplied system_LPC11xx.c file. I have at least 3 versions, all of which are different, the latest one not initilising loads of stuff the older ones did! My fix for this is to write you own (very much simpler) my_system_LPC11xx.c file, which you can put under version control with everything else!
John