SMBus example code

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

SMBus example code

4,508 Views
MikeJones
Contributor III

AN4342 mentions project i2c_smb_basic project but I can't find it. Does anyone have example code on using i2c for SMBus mode including handling interrupts from ALERT#? I am using the K60 Tower for development and using J5 to get SCL/SDA and I can probably use PTD10 for the interrupt. I am a bit of a newbie on MQX/Kinetis, sorry for that, but anything that helps reduce the learning pain will be appreciated.

0 Kudos
4 Replies

1,906 Views
MikeJones
Contributor III

These are my latest examples. They remove the waits from the last code so they are much faster.

I am updating this with my latest files because the server has lost them. Mike

0 Kudos

1,906 Views
Paul_Kuhn
NXP Employee
NXP Employee

Hello Mike,  when we migrated from our old community platform to this one we lost attachments to post.  Could I both you to reload your lastest examples.

0 Kudos

1,906 Views
MikeJones
Contributor III

Guess I missed your message. I just added them. Note that with a second badly behaving master, these will hang in the driver. There are some fundamental assumptions made by the driver code that don't hold in practice.

0 Kudos

1,906 Views
MikeJones
Contributor III

This code is fairly robust. The clean up at the end of each function is probably no longer needed. I have not retested with multimaster modes after making some changes to NACK handling, but I don't think I messed up loss of arbitration, so it should be ok. If it works properly with multimaster, then the final cleanup can probably be removed. However, one can always replace it with something better if one discovers the driver is not quite perfect or there is some other problem that can't be pinned down.

 

This code depends on a logging task that logs to NVM. I am not giving that up, so replace the log call with a call of your own or an empty function.

 

You may use it without warranty. If you make it better, please post your changes to this entry. It was not easy to close all the loop holes. In particular, a hard to find problem was the write word code. If I did not check the status between the two data bytes, and there was a NACK on the first byte, the task would get lost in the weeds. The symptom was I would halt in the debugger and the task would be off in assembly somewhere with no stack information available.

0 Kudos