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

Post Reply
User avatar
Jay Dee
Posts: 397
Joined: Tue Aug 18, 2009 6:42 pm
Contact:

Simple i2C - Single Byte read and Write

Post by Jay Dee »

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 257 times
J.

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

Re: Simple i2C - Single Byte read and Write

Post by derfleznew »

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: 14929
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Simple i2C - Single Byte read and Write

Post by Benj »

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?

Post Reply