News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

i2c Slave

Started by TimB, Feb 05, 2023, 09:07 PM

Previous topic - Next topic

TimB

Hi All

In the past I asked about coding an i2c slave and was sent very kindly some code by John D

I revisited the code but its not working for me. I prefer to code my own way and that involves me understanding what is happening inside. Its not much use if the code will not do what I want and cannot see a simple way to convert it.

I need to just be able to have a set of registers that the i2c interrupt can feed out and write to on its own. I did this with a SPI slave. It was all handled inside the interrupt and just flagged when a register had be modified and needed to be actioned on in the main code.

This what I want to do in with i2c. I could use my SPI code as but I like the idea of having just 4 wires to the board not 6 as would be needed with the SPI. I probably have become fixated on the wrong issues :( Why make so much work for just 2 cables?

Anyway I'm asking if anybody can share some basics they have implemented in an i2c slave. Like
Set up the regs
Interrupt will operate like this
etc

I'm not looking for cut and paste code more just well commented code I can see what is going on. I never get on reading the datasheet. I am in aw of the likes of Les who can read the data sheet and write code to make it all work.

Thanks

Tim






Gabi

Here is some tested I2C slave code, based on Microchip AN734, with a simple test. Probably you will need to adapt to your specific Pic device.
GL & 73
YO4WM

TimB


Thanks Gabi

That is pretty much exactly what I wanted. Really really appreciate that :)


Tim