Hello,
I am learning about CMSIS functions and started with I2C application. I have some issues that I couldn't overcome. I stucked at the beginning.
I am using TWR-KE18F board with MCUXpresso IDE and SDK2.0. I am trying to reach the WhoAmI register of onboard accelerometer.
my piece of example code is:
EXAMPLE_I2C_MASTER.Initialize(lpi2c_master_callback); EXAMPLE_I2C_MASTER.PowerControl(ARM_POWER_FULL); EXAMPLE_I2C_MASTER.Control(ARM_I2C_BUS_SPEED,ARM_I2C_BUS_SPEED_STANDARD); g_master_txBuff[0] = 0x0D; //WhoAmI register = 0x0D EXAMPLE_I2C_MASTER.MasterTransmit(SLAVE_ADR,g_master_txBuff,1,true); while(!ARM_I2C_EVENT_TRANSFER_DONE) {} while(EXAMPLE_I2C_MASTER.GetStatus().busy) {} EXAMPLE_I2C_MASTER.MasterReceive(SLAVE_ADR,g_master_rxBuff,1,false); PRINTF("0x%2x", g_master_rxBuff[0]);
and I see 0xff.
As I said I am new to this topic and any help will be appreciated.
Thanks,
Onur
Hello Onur Demirel ,
I recommend you first have a look at the demo "read_accel_value_transfer" under SDK (SDK_2.3.0_TWR-KE18F\boards\twrke18f\driver_examples\lpi2c\read_accel_value_transfer),
there is a function about read Who AM I register of FXOS8700 on board :
also the readme.txt tell you how to run this demo on your TWR-KE18F board.
Hope it helps
Have a great day,
TIC
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Alice_Yang,
I am trying to use CMSIS library and I am trying to write a basic code fusing with two example code which are cmsis_lpi2c_edma_b2b_transfer_master under CMSIS examples and the one you attached. I realized I am checking the busy status in a wrong way.
Instead of
while(!ARM_I2C_EVENT_TRANSFER_DONE) {} while(EXAMPLE_I2C_MASTER.GetStatus().busy) {}
I need to check for
while(!g_masterCompletionFlag) {}
which is set upon a completion event. That is used in the CMSIS example of I2C.
One other thing, after calling --.MasterRecieve function I need to wait for busy flag:
EXAMPLE_I2C_MASTER.GetStatus().busy
Well the main point I am struggling is the examples are too complicated for a simple I2C operation. A single write or read operation is declared in 2-3 functions concatenated. I am familiar with assembly language but it become confusing for debugging these high level example codes.
Now I am working on reading sensor data using again CMSIS libraries. I have still some problems but I am working on them
If I feel desperate I will ask for your help again.
Thanks a lot
Onur