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.
And now the bad news: this one is not provided for ColdFire V2 (not sure why?):
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.
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:
As properties, it offers to connect to any BitIO pins:
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 🙂





Pingback: Bit-Banging I2C with ResetBus() Functionality | MCU on Eclipse
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?
Thanks!
LikeLike
Hello,
first, make yourself familiar with the I2C protocol, e.g. starting with https://en.wikipedia.org/wiki/I%C2%B2C.
Then simply have a look at my implementation: for it you only need to have the ability to set the pins as input and to set them LOW or HIGH.
Good luck!
LikeLike
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.
Click to access FRDM-KE02Z_SCH.pdf
//Application.c
void APP_Run(void)
{
uint8_t res=ERR_OK;
I2C1_Init();
char data[3];
data[0] = 0x01;
res = I2C1_RecvChar(data);
if (res == ERR_OK)
I2C1_OnRxChar();
}
//Events.c
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!
LikeLike
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.
LikeLike
Hi Erich, My application worked and I am able to pwm control my motors based on bit banging I2C. Thanks for the help.
LikeLike
Hi, I want to know what the IDE did you using for this project?
LikeLike
I have used CodeWarrior in that post. But the same exists in Kinetis Design Studio or Atollic True Studio.
LikeLike
Thanks.i usually use keil and IAR.
LikeLike