LPC82X to be a slave device

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LPC82X to be a slave device

974 次查看
shujunding
Contributor I

I want to make LPC82X to be a slave device.But when I study the the sample code I download,I Can't unstand the API function "Chip_I2CS_SetSlaveAddr".

The following is sample code:

static void setupI2CSlave(void)

{

  /* Some common I2C init was performed in setupI2CMaster(), so it doesn't need to be done again for the slave setup. */

  /* Emulated EEPROM 0 is on slave index 0 */

  Chip_I2CS_SetSlaveAddr(LPC_I2C_PORT, 0, EEPROM0SLVADD);

  /* Disable Qualifier for Slave Address 0 */

  Chip_I2CS_SetSlaveQual0(LPC_I2C_PORT, false, 0);

  /* Enable Slave Address 0 */

  Chip_I2CS_EnableSlaveAddr(LPC_I2C_PORT, 0);

  /* Emulated EEPROM 1 is on slave index 1 */

  Chip_I2CS_SetSlaveAddr(LPC_I2C_PORT, 1, EEPROM1SLVADD);

  /* Enable Slave Address 1 */

  Chip_I2CS_EnableSlaveAddr(LPC_I2C_PORT, 1);

  /* Clear interrupt status and enable slave interrupts */

  Chip_I2CS_ClearStatus(LPC_I2C_PORT, I2C_STAT_SLVDESEL);

  Chip_I2C_EnableInt(LPC_I2C_PORT, I2C_INTENSET_SLVPENDING | I2C_INTENSET_SLVDESEL);

  /* Enable I2C slave interface */

  Chip_I2CS_Enable(LPC_I2C_PORT);

My confusion is that one I2C port can be used as two slave devices?Just only set two different slave addresses?

Original Attachment has been moved to: periph_i2cs_interrupt.zip

0 项奖励
回复
3 回复数

752 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Shujun,

    It is the LPC82X I2C feature, this I2C module can support multiple I2C slave addresses.

  You can find more details from the LPC82X user manual​, page 227.

  It can support 4 slave addresses, if you just want to use one slave address, you can just configure one.

  The slvNum is define the salve address number in the following API.

/**

* @brief    Set a I2C slave address for slave operation

* @param    pI2C    : Pointer to selected I2C peripheral

* @param    slvNum    : Possible slave address number, between 0 - 3

* @param    slvAddr    : Slave Address for the index (7-bits, bit 7 = 0)

* @return    Nothing

* @note    Setting a slave address also enables the slave address. Do

* not 'pre-shift' the slave address.

*/

STATIC INLINE void Chip_I2CS_SetSlaveAddr(LPC_I2C_T *pI2C, uint8_t slvNum, uint8_t slvAddr)

{

    pI2C->SLVADR[slvNum] = (uint32_t) (slvAddr << 1);

}

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复

752 次查看
sirdigbychicken
Contributor II

Hi, I have another question related to Chip_I2CS_SetSlaveAddr

Assuming SetSlaveAddr[0] is for the LPC82x, can SetSlaveAddr[1:3] be linked somehow to I2C2, I2C3 & I2C4 so that an I2C master can talk 'through' the LPC82x to I2C devices connected as slaves to the other 3 I2C ports?

Is that what pI2C is used for?

Thanks,

Mike.

0 项奖励
回复

752 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mike,

  If you have the question, please create the question post for your own question, please don't follow the old post which is closed.

  After you create the question post, we will help you in your own post.

  Thanks a lot for your understanding.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复