addiing support for i2c communication to RTOS

manusha wrote on Tuesday, February 19, 2008:

im working with MPLAB port of RTOS and it works fine. the device im using is 18f4455. i need to extend the functionality of RTOS with i2c support for this (or for whole 18F devices) device. however im not exactly sure how this kind of kernal level functionality should be added to RTOS. So im looking for some advice/tutorials on how to get started.
and also please let me know if there are already written extensions for i2c for MPLAB port and 18F devices.


davedoors wrote on Tuesday, February 19, 2008:

You should find a demo UART driver for each port in the download that can be used as a model for all drivers. Also take a look at the WIZNET demo source code as this includes an I2C driver, although the syntax will be different as its running on an ARM it will give you the basics.

anuradha123 wrote on Tuesday, January 11, 2011:


Am not clear in what you have meant as “WIZNET”  :-Q

jakbird wrote on Tuesday, January 11, 2011:

A few years ago I added I2C to FreeRTOS for an STR750 (ARM7TDMI).  The concept was a device driver that ran a “transaction” with a peripheral device: send command, wait for response.  I used a mutex flag to serialize access to the device driver, and a completion semaphore to block the originating task until the transaction completed (or timed out).  The data transfer was handled in an interrupt service routine which set the completion flag when the I2C was done.

The mutex was needed because I had two devices on the I2C bus, with a separate task for each device.  The mutex ensured that commands and responses were in serial order and data went to the right task.  Both tasks used the same completion flag but since the mutex blocked the second task while the first was using I2C there was no conflict.

The other trick on I2C is being able to recover from a fault.  In my case I had to shut off the I2C logic, switch to bit bang mode, and manually clock out 9 bits to clear the I2C bus if a peripheral hung (it happens, don’t expect perfection).  Without the timeout if a peripheral fails to respond to a command the bus hangs forever waiting for the response.
  Jack Peacock