How to set I2C correctly?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to set I2C correctly?

1,794 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Mon Dec 16 04:25:35 MST 2013
Hi,

Can someone describe in detail the procedure to correctly calculate and set the registers for I2C? The chip (lpc812) run at 12 Mhz crystal and I need to set the I2C clock to 400 kHz. I do not understand what is written in UM.
Labels (1)
0 Kudos
Reply
3 Replies

1,638 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vijay_nav on Wed Jan 29 05:04:35 MST 2014
Hai

I am working on I2c and i my device is acting act as slave and my address is matched with other device.But i have a dought  how to send acknowledgement to the other device.This is the code for slave.
0 Kudos
Reply

1,638 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vijay_nav on Tue Dec 31 23:31:45 MST 2013
Hai
        I am Working on i2c project while building&Debugging i am facing the  error that undefined reference to `I2CMonBuffer',I2CSlaveRXBuffer,I2CSlaveTXBuffer. please find the below attachments for the program and screen shot for bugs.
Please help how to fix it.


0 Kudos
Reply

1,638 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rocketdawg on Mon Dec 16 09:50:35 MST 2013

something like this.  Straight from LPCOpen source code.

#ifdef __USE_LPCOPEN
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();

    // Set up and initialize all required blocks and functions
    // related to the board hardware
    Board_Init();

    // Set the LED to the state of "Off"
    Board_LED_Set(0, false);

/* Setup I2C pin muxing */
Init_I2C_PinMux();

/* Allocate I2C handle, setup I2C rate, and initialize I2C
   clocking */
setupI2CMaster();


/* Enable SysTick Timer */
SysTick_Config(SystemCoreClock / TICKRATE_HZ);

#endif


/* Initializes pin muxing for I2C interface - note that SystemInit() may
   already setup your pin muxing at system startup */
static void Init_I2C_PinMux(void)
{
#if defined(BOARD_NXP_XPRESSO_812)
/* Enable the clock to the Switch Matrix */
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);

/* Connect the I2C_SDA and I2C_SCL signals to port pins(P0.10, P0.11) */
Chip_SWM_MovablePinAssign(SWM_I2C_SDA_IO, 10);
Chip_SWM_MovablePinAssign(SWM_I2C_SCL_IO, 11);

#if (I2C_BITRATE > 400000)
/* Enable Fast Mode Plus for I2C pins */
Chip_IOCON_PinSetI2CMode(LPC_IOCON, IOCON_PIO10, PIN_I2CMODE_FASTPLUS);
Chip_IOCON_PinSetI2CMode(LPC_IOCON, IOCON_PIO11, PIN_I2CMODE_FASTPLUS);
#endif

/* Disable the clock to the Switch Matrix to save power */
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);

#else
/* Configure your own I2C pin muxing here if needed */
#warning No I2C pin muxing defined
#endif
}


/* Setup I2C handle and parameters */
void setupI2CMaster()
{
/* Enable I2C clock and reset I2C peripheral - the boot ROM does not
   do this */
Chip_I2C_Init();

/* Perform a sanity check on the storage allocation */
if (LPC_I2CD_API->i2c_get_mem_size() > sizeof(i2cMasterHandleMEM)) {
/* Example only: this should never happen and probably isn't needed for
   most I2C code. */
errorI2C();
}

/* Setup the I2C handle */
i2cHandleMaster = LPC_I2CD_API->i2c_setup(LPC_I2C_BASE, i2cMasterHandleMEM);
if (i2cHandleMaster == NULL) {
errorI2C();
}

/* Set I2C bit rate */
if (LPC_I2CD_API->i2c_set_bitrate(i2cHandleMaster, Chip_Clock_GetSystemClockRate(), I2C_BITRATE) != LPC_OK) {
errorI2C();
}
/* Enable the interrupt for the I2C */
NVIC_EnableIRQ(I2C_IRQn);
}


0 Kudos
Reply