Jump to content
43oh

I2C for beginners


Recommended Posts

Hi all,

 

Is there a fundamental flaw(s) with the attached code. I know it isn't elegant :-). New to this and I'm trying to write the word ABCDh to address location 2004h of an RFID chip with serial EEPROM. The device address is Ah but bits b3-b1 allow for multiple devices on the same bus hence 0xA2. I'm using p1.7 = SDA and P1.6 = SCL and have the necessary pull-ups. Any help/pointers/advice appreciated whilst I still have some hair.

 

 

post-49525-0-08048800-1476794882_thumb.png

Link to post
Share on other sites
#include <Wire.h>
 
void setup()
{
  Wire.begin(); // join i2c bus
}
 
byte val =   0xAB;
byte val_1 = 0xCD;
void loop()
{
  Wire.beginTransmission(0xA2); // transmit to device 0xA2 10100010
  Wire.write(byte(0x20));            // sends address hi byte
  Wire.write(byte(0x04));            // sends address lo byte
  Wire.write(val);               // sends value into memory
  Wire.write(val_1);             // sends value into memory
  Wire.endTransmission();     // stop transmitting
 
}

 

Sorry, found the paste function.

Link to post
Share on other sites

First of all, I2C has this oddity of using 7 bit addresses. When representing 7 bits in an 8 bit byte, it's never clear where to add the extra zero bit.
Your device address is

1001xxx

But does this translate to

01010xxx

or to

1010xxx0

try using 89h instead of A2h, it might just work.

 

Next thing, when writing 16 bit values over an 8 bit bus, make sure you have thew byte order (also called endianness) correct.

Does 00FFh

0000000011111111

translate to 00h, FFh

00000000 11111111

or to FFh, 00h

11111111 00000000

so you could try either (or read back both addresses).

Link to post
Share on other sites

First time I've been able to use this forum for a few days as all I've been getting is an error page.

 

I'm using the 430G2553. I had a look on data and clock pins and they were just sat high. Thought I'd try the code on an Arduino and I had data and clock activity. Sorting the I2C address out form A2h to a 7 bit address which became 51h (cheers for the reminder roadrunner84) I was able to communicate over I2C to my device :-) Out of interest I tried an MSP430FR5969 with my bit of code and that worked fine too. It would seem it there's an issue when using the 2553. I do have another 2553 which I tried and still no joy. I'm using Energia 17 by the way as 18 wouldn't work for me!

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...