I2C, basic question

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How does one decide which versions (polled or interrupt) of an I2C library to use? I know that "polled" means that the processor is tied up handling the I2C comms and excludes everything else going on.

What other factors are there to consider?

I have noticed that when I use the AVRlib NI(non-interrupt) version of I2C that unless I enclose these functions with a cli()/sei() pair that I get occasional data errors. Seems to happen when handling the RX info, where there is a call to i2cMasterSendNI followed by a call to i2cMaster ReceiveNI.

cli(); // needed to stop receive data errors??

// reset register pointer at RTC_ADDR
   i2cMasterSendNI(RTC_ADDR, 1, 0x00);
// get data
   i2cMasterReceiveNI(RTC_ADDR, 7, rx_data);

sei();

Thank you for your comments.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i got the same problem with I2C
i am using NI to send data
can you tell me why cli and sei are required to be used?
and what is the length in I2C function?
//i2cMasterSendNI(RTC_ADDR, 1, 0x00);
what is the value of 1?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I needed to disable all interrupts so that my receive data did not get corrupted and/or to stop the uP from locking up. The NI versions just disable the TWI interrupt.

I have found that the non-NI versions work just fine, hence my question regarding "how do you choose which one to use"??

length is the number of characters you are trying to send or receive

The value of 1 in your last question will just send 1 character. Probably used to address a small EEPROM.

If you have a look at Pascal's i2ctest example, where he tests a 24xxyy EEPROM he sends 2 characters with a i2cMasterSendNI call to find the correct address in EEPROM memory then requests 16 data bytes in the i2cMasterReceiveNI call.

davef

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

for my project, i use a IO epander IC to control LED.
I send a I2C to control 8 output.
So, do i need to send length of 8 ?
and, the sample output LED should be , 1 0 1 0 1 0 1 0. 1 is on, 0 is off
the data should be "0b10101010" ?
am i correct?
thx for ur reply

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

and, would you mind post your code here?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One of my next projects is to use the PCF8574 IOexpander, so I don't know much about them yet. I suspect you will only be sending one character to turn a specific LED on so my guess is length equals 1.

My code really only consists of the snippet at the top of the post as I am using other people's I2C libraries.

Good luck

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

good luck