Author Topic: incoming I2C message  (Read 9430 times)

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
incoming I2C message
« on: July 07, 2010, 01:07:36 PM »
Hi Mark,
   I have 2 I2C devices and if I do the following , one after another, what tasks will receive what bytes?

   fnRead(IICPortID, (unsigned char *)&task1, 0);    //1st device will return 10 bytes
   fnRead(IICPortID, (unsigned char *)&task2, 0);    //2nd device will return 20 bytes

Thanks
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: incoming I2C message
« Reply #1 on: July 07, 2010, 01:38:58 PM »
Hi Neil

I would always use one single task to read I2C input. What would happen in your case is that the reception of the first response would schedule task1 and the reception of the second would schedule task 2.  However a single I2C interface has a single handle and there is not necessarily a guaranty that task 1 will not read both responses, or that task 2 will be scheduled first and read the message that is intended for task 1 (it may be scheduled for other reasons too).

What is however guarantied is the order of the receive messages. This will always be in the same order as sent and so reading from the I2C handle will retrieve them in the same order. Since you know the order sent and the order that they will be retrieved in it is usually best to let one task handle the reception and then distribute the content accordingly.

Regards

Mark


Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: incoming I2C message
« Reply #2 on: July 07, 2010, 01:44:24 PM »
Thanks Mark, cheers

Neil

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: incoming I2C message
« Reply #3 on: July 07, 2010, 03:06:49 PM »
Hi mark,
 I will change to one task , as only using one channel. I assume if there are any  fnWrite(IICPortID..) inbetween any read commands there wont be any issues ? As long as the devices dont respond to the command being sent (as I know what commands I am sending I dont expect any replies).

Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: incoming I2C message
« Reply #4 on: July 07, 2010, 03:15:17 PM »
Hi Neil

There are no receptions from writes so you always know what data is going to come back.

Regards

Mark