Bit Banging I2C

The Freescale ColdFire V2 (MCF52259) is a great communication device: an embedded Processor like a Swiss Army Knife: Great peripherals, USB and Ethernet interface, a lot of flash application space and up to 64 KByte of RAM. I’m using that core in many projects, and there is great community support for it with boards and software. Unfortunately Freescale somehow provides Processor Expert support only half way for it. Support for the I2C bus is missing :-(.

For other cores like the HCS08 Freescale offers a Hardware I2C Processor Expert component. That’s fast and efficient, but requires one or more I2C peripheral on the device. What if you do not have this or if you need to use different pins for your I2C bus to be used? Then I can have the I2C bus protocol using Bit Banging: Instead of using a dedicated hardware, software is changing the signals on the bus.

The good news is: there is such a Bit Banging I2C component available in Processor Expert: SW_I2C.

SW_I2C component, shown with filtering disabled

SW_I2C component, shown with filtering disabled

And now the bad news: this one is not provided for ColdFire V2 (not sure why?):

Filtered for MCF52259: no SW_I2C component any more

Filtered for MCF52259: no SW_I2C component any more

But there is a solution: I have transformed the code generated by the S08 SW_I2C component into a new component which supports as well the ColdFire cores.

GenericSWI2C component

GenericSWI2C component

This GenericSWI2C component does the same thing as SW_I2C, but works as well for the ColdFire V2 using general purpose Bit I/O. It offers the following methods:

GenericSWI2C Projects View

GenericSWI2C Projects View

As properties, it offers to connect to any BitIO pins:

GenericSWI2C Properties

GenericSWI2C Properties

The GenericSWI2C component is available for download here.

That Software (Bit Banging) I2C driver worked well for several projects: it is not as fast as hardware I2C, but good enough to be used for I/O port expansions or Real Time Clocks on the I2C bus.

Happy BitBanging 🙂


9 thoughts on “Bit Banging I2C

  1. Pingback: Bit-Banging I2C with ResetBus() Functionality | MCU on Eclipse

  2. Hi,
    I will be trying to implement I2C by bit banging certain GPIOs on the KE02Z40M board. Are there any pointers that you would suggest for a newbie engineer working on I2C?


      • Hello Erich,
        1. I am using the bitbanging aspect of I2C with the SWI2C driver from here. I am continuously writing on the GPIO i.e I use only the RecvChar method and the Init method from the driver code.
        The GPIO never sends anything , not even acknowledgement.

        2. On receiving data, I go to the event I2C1_OnRxChar(); and try an LED blink. In the future I will use the data received to enable counterclockwise/clockwise motion of BLDC motors.

        The problem that I am facing is I do get the SCL clock pulses and SDA data reception only when I connect the resistors R42 and R45 of the board and if my understanding of the schematic is correct, I should connect the R39 and R47 resistors and look if I am able to receive bits.
        R42 and R45 are connections that go to accelerometer. But I am sending data through my code and checking if I can receive it on the GPIOs(SDA/SCL).

        I am using a KE02z board with MKE02Z64Vqh4 processor.

        I have attached the schematic link and my application code snippet.

        void APP_Run(void)
        uint8_t res=ERR_OK;
        char data[3];
        data[0] = 0x01;

        res = I2C1_RecvChar(data);
        if (res == ERR_OK)


        void I2C1_OnRxChar(void)
        LED2_Neg(); // included the part where I want to see LED toggle

        Am I doing something wrong? Or have I not set/reset something properly? Thanks!


        • For proper I2C operation, you need pull-ups, but the dimension of the pull-ups depends on your bus capacity.
          From your code: you are not supposed to call OnRxChar() from your application directly: that event gets called from the driver when a new character arrives.


What do you think?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.