I need the C libraries to do a I2C comunication with a mi...

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I need the C libraries to do a I2C comunication with a mi...

1,757 Views
Nico_elect
Contributor I
I need the C libraries to do a I2C comunication with a microcontroller that hasn't the hardware. Can someone get me it?
Thanks.
Labels (1)
0 Kudos
Reply
3 Replies

629 Views
JimDon
Senior Contributor III
Processor Expert will generate the code for you for this task.

Create a PE project, then in the Add Bean dialog, look under "CPU External Devices"/"COmmunication"/ SW_IC2. This bean is a software I2C driver, that just uses GPIO bits.
You will have to select the bits for Data Pin and Clock Pin.

Here is a link to a project that does this. There is also some other handy code in it.
You can add a CPU bean for your processor.

0 Kudos
Reply

629 Views
fabio
Contributor IV
Hi Nico,

The bean Jim mentioned is a master-only software-emulated I2C interface. If you need an I2C slave device, it will be slightly more difficult. You will need to used the keyboard interrupts (or GPIO interrupts) to detect the clock as well as START and STOP conditions.

Of course, the I2C bus speed will be limited by the speed of your slave MCU. Your slave code could use the "clock-stretching" feature to slow-down the I2C bus.

Best regards,
0 Kudos
Reply

629 Views
JimDon
Senior Contributor III
You could do it polled. Just better be a tight loop.

0 Kudos
Reply