µTasker Forum
µTasker Forum => NXPTM M522XX, KINETIS and i.MX RT => Topic started by: neil 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
-
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
-
Thanks Mark, cheers
Neil
-
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
-
Hi Neil
There are no receptions from writes so you always know what data is going to come back.
Regards
Mark