Download UM10850 LPC5410x User manual

Transcript
UM10850
NXP Semiconductors
Chapter 23: LPC5410x I2C-bus interfaces (I2C0/1/2)
23.4.2.1 Slave read from master
Configure I2C0 as slave with address x:
• Set the SLVEN bit to 1 in the CFG register. See Table 342.
• Write the slave address x to the address 0 match register. See Table 368.
Read data from the master:
1. Wait for the pending status to be set (SLVPENDING = 1) by polling the STAT register.
2. Acknowledge (“ack”) the address by setting SLVCONTINUE = 1 in the slave control
register. See Table 364.
3. Wait for the pending status to be set (SLVPENDING = 1) by polling the STAT register.
4. Read 8 bits of data from the SLVDAT register. See Table 366.
5. Acknowledge (“ack”) the data by setting SLVCONTINUE = 1 in the slave control
register. See Table 364.
Table 337. Code example
Slave read from master
//Slave read 1 byte from master. Address 0x23. Polling mode.
uint8_t data;
I2C->SLVADR0 = 0x23 << 1; // put address in address 0 register
I2C->CFG = I2C_CFG_SLVEN;
I2C->CFG;
while(!(I2C->STAT & I2C_STAT_SLVPENDING));
if((I2C->STAT & I2C_STAT_SLVSTATE) != I2C_STAT_SLVST_ADDR) abort();
I2C->SLVCTL = I2C_SLVCTL_SLVCONTINUE; // ack address
while(!(I2C->STAT & I2C_STAT_SLVPENDING));
if((I2C->STAT & I2C_STAT_SLVSTATE) != I2C_STAT_SLVST_RX) abort();
data = I2C->SLVDAT; // read data
if(data != 0xdd) abort();
I2C->SLVCTL = I2C_SLVCTL_SLVCONTINUE; // ack data
UM10850
User manual
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 5 November 2014
© NXP B.V. 2014. All rights reserved.
288 of 437