Author Topic: How to use the IIC to get data and send data!  (Read 10539 times)

Offline tr111

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
How to use the IIC to get data and send data!
« on: September 12, 2007, 10:02:57 AM »
  I have #define IIC_INTERFACE,but  I don't how to use the IIC to get data and send data!
  In old use I use IIC as  master , look like this "UINT8 i2c_write(UINT8 slave_address, UINT8 *buffer, int byte_count)" and "UINT8 i2c_read(UINT8 slave_address, UINT8 *buffer, int byte_count)" !
  But how can use in the Utasker! I find the "extern void fnTxIIC(IICQue *ptIICQue, int iChannel)" and the "static __interrupt__ void _IIC_Interrupt(void)"!
   Can use this???
   I don't understand the "static QUEUE_TRANSFER entry_IIC(QUEUE_HANDLE channel, unsigned char *ptBuffer, QUEUE_TRANSFER Counter, unsigned char ucCallType, QUEUE_HANDLE DriverID)"!
   How to use???

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: How to use the IIC to get data and send data!
« Reply #1 on: September 12, 2007, 10:15:51 AM »
Hi

Please use this document as quide to working with the IIC interface:
http://www.utasker.com/docs/uTasker/uTaskerIIC.PDF

In the uTasker demo project there is an example of writing and reading an IIC EEPROM (set TEST_IIC in application.c). An additional example of configuring, setting and reading an IIC RTC has been prepared for the next Service Pack - if you happen to be using the DS1307 RTC I can send you the development file.

See also this thread: http://www.utasker.com/forum/index.php?topic=59.0 which has example of reading IIC data and sending it to a UART.

Note that the demo can be executed in the uTasker simulator - in the file \Hardware\IIC_devices\IIC_dev.c there are various IIC devices which are modelled and so works together with the simulator - it is in fact quite easy to add more if needed.

Good luck

Regards

Mark


Offline tr111

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: How to use the IIC to get data and send data!
« Reply #2 on: September 12, 2007, 10:39:35 AM »
Mark :
     Your answer iis always fast! Thank you!

Offline eduardovra

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to use the IIC to get data and send data!
« Reply #3 on: July 31, 2008, 10:22:59 PM »
Hi

How can I make a read to the I2C bus and wait for a response without use the task message method.
Is there any kind of variable that I can pool for the result ?

I want to be sure that a write/read operation is complete before proceed to the next..

Best Regards

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: How to use the IIC to get data and send data!
« Reply #4 on: August 01, 2008, 12:11:54 AM »
Hi

You can do something like the following:

Example of reading time from an I2C RTC

static void fnGetRTCTime(void)
{
    const unsigned char ucGetTime[] =  {ADDRTC_WRITE, 0};
    const unsigned char ucSlave[] = {7, (ADDRTC_READ), OWN_TASK};        // read 7 bytes from this address

    unsigned char ucTime[7];
    fnWrite(IICPortID, (unsigned char*)ucGetTime, sizeof(ucGetTime));    // set the read address
    fnRead(IICPortID, (unsigned char *)&ucSlave, 0);                     // start the read process of 7 byte

    while (fnMsgs(IICPortID) ==0) {}                                           // wait until read has completed
    fnRead( IICPortID, ucTime, 7);

}


The lines in bold are new in order to wait for the read to complete and then extract the data from the input buffer. The call fnMsgs() polls the state of the input queue and only returns a non-zero value when the complete read has terminated.

Regards

Mark