LPC5410x i2c read from register

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

LPC5410x i2c read from register

670 Views
gossamer69
Contributor III

I have problems trying to read specific register from i2c device. First I transmit address and register to request reading from device, but when I try to send start (repeated start) it still expects new TX data.. I am not sure what should I send to specify I want to read now... 

This is the sample code I am trying to use:

if (!waitForState(MasterStates::Idle)) return false;

m_peripheral->MSTDAT = m_address; //send address of slave and set start

m_peripheral->MSTCTL = MSTSTART;

if (!waitForState(MasterStates::TxRdy)) return false;

m_peripheral->MSTDAT = a_reg;  // send address of register i want to read and send continue

m_peripheral->MSTCTL = MSTCONTINUE;

if (!waitForState(MasterStates::TxRdy)) return false;

m_peripheral->MSTDAT = m_address | 1;  //set read flag on address and send start (i hoped it would be repeated start)

m_peripheral->MSTCTL = MSTSTART;

if (!waitForState(MasterStates::RxRdy)) return false;  //<<<<<<--- this is where I still get TxRdy instead of RxRdy

tmp = m_peripheral->MSTDAT;

m_peripheral->MSTCTL = MSTSTOP;

if (!waitForState(MasterStates::Idle)) return false;

So what should I set after sending the address of register i want to read ?

Thanks

Tags (2)
0 Kudos
1 Reply

461 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi

The LPCOpen software for LPC5410x chip provides the I2C master demo, which located at below folder:

..\lpc5410x_lpcxpresso_54102_keil_iar_3.01.000_9\lpc5410x\prj_lpcxpresso_54102\iar

There shows how to use read data from 3-axis accelerometer (Bosch BMC150) with I2C bus.


Wish it helps.

Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos