Simple i2C - Single Byte read and Write

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

User avatar
Jay Dee
Posts: 352
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 116 times
Been thanked: 134 times
Contact:

Simple i2C - Single Byte read and Write

Postby Jay Dee » Thu Jul 06, 2017 1:30 pm

Hi, I am working with another obscure i2C based chip and made up some generic i2C macros, others may find these helpful, especially if your are new to i2C.

I know there are loads of examples and you can instead use the ReceiveTransaction and Send transaction macros but I have traditionally done it using the discrete i2C macros.

They Only send a single data byte or read a single data byte.
But if, like me, your working on a new chip and want to quickly read/write some test bytes using i2C, this might be a good starting point.
I based it on a ECIO40P, and used B4=Data, B3=Clock. but target chip can be anything, you choose.
Generic_i2C_Test_ECIO.fcfx
Generic i2C macros
(15.36 KiB) Downloaded 185 times

J.
These users thanked the author Jay Dee for the post (total 3):
Benj (Thu Jul 06, 2017 2:58 pm) • medelec35 (Thu Jul 06, 2017 6:28 pm) • jgu1 (Fri Jul 07, 2017 5:41 am)
Rating: 15.79%
 

derfleznew
Posts: 3
Joined: Wed Aug 09, 2017 7:30 pm
Contact:

Re: Simple i2C - Single Byte read and Write

Postby derfleznew » Sat Aug 26, 2017 12:25 am

Thanks for the I2C example code. We have been having fits reliably reading I2C data from an MicroChip MCP9600 thermocouple chip. What we get is around 9 to 10 returns with missing bit 3, then a couple of good readings. Scoping this out shows strange behavior and we think the issue is with the FlowCode7 component. Very frustrating to troubleshoot.

Have you had any random bad readings from the chip you are using?

User avatar
Benj
Matrix Staff
Posts: 14216
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4355 times
Been thanked: 4095 times
Contact:

Re: Simple i2C - Single Byte read and Write

Postby Benj » Tue Aug 29, 2017 4:04 pm

Hello,

Have you seen the blog post here on I2C communications it explains the basics and how to read a device datasheet.
https://www.matrixtsl.com/blog/simplifi ... c-and-spi/

Have you had any random bad readings from the chip you are using?


No it sounds like something is potentially wrong here.

If the blog doesn't help then can you post your program so we can double check the I2C protocol is being followed correctly in your firmware.
Also what value of pull up resistor are you using?