Can't get I2C_DRV_MasterSendData() to work

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

Can't get I2C_DRV_MasterSendData() to work

810 Views
mikewilliams
Contributor I

I'm using a K02 with SDK 1.3.0.  I'm trying to do some basic I2C communication as the Master on bare metal using I2C_DRV_MasterSendData().  I have a breakpoint set in the Master IRQ handler to catch if an ACK wasn't received.

 

If I step into the API call and run to the point where it calls I2C_DRV_SendAddress(), I can see that the slave address is set correctly.  If I try to step into or over this call to send the address, it breaks in the Master IRQ handler saying an ACK wasn't received.  My scope shows that some random byte went out on the bus.  If I delete the breakpoint in the IRQ handler, I can step into the call and again, see that the slave address is correct.

 

I thought maybe the debugger was messing things up so I just let it run past these two lines in my code:

 

ret = I2C_DRV_MasterSendData(I2C_IDX, &I2C_MasterConfig0, NULL, 0, &i2c_data[0], 1);

while (I2C_DRV_MasterGetSendStatus(I2C_IDX, &bytes) == kStatus_I2C_Busy);

 

But that doesn't work either.  This seems like a pretty simple implementation of I2C communication but I can't get it to work. 

 

Any ideas on what to check?

Labels (1)
0 Kudos
2 Replies

494 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Mike,

Looks like you are using I2C non-block mode in your application, so I recommend you referring to the demo in "C:\Freescale\KSDK_1.3.0\examples\frdmk64f\driver_examples\i2c\i2c_non_blocking" for details. The usage of I2C_DRV_MasterSendData() should be like the following:

pastedImage_17.png

Hope that helps,


Have a great day,
Kan

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

0 Kudos

494 Views
mikewilliams
Contributor I

Hey Kan, thanks for the reply.  The example code you listed is what I used in my code.  It just doesn't work. 

If I just run past while loop waiting on the status, it doesn’t work.  I see 0x7f on the scope, or some other random data.  If I step into the API call and run down into I2C_DRV_SendAddress() and stop after the call to I2C_HAL_WriteByte() that sends out the slave address and stop before the call to I2C_DRV_MasterWait(), I see the correct slave address on the scope.  If I run past the call to I2C_DRV_MasterWait(), I see the 0x7f on the scope instead of the correct slave address. 

My guess is that it has something to do with the I2C_DRV_MasterWait() but I don’t know what it could be.  I set up everything using PE for a bare metal board.

0 Kudos