PIC24f: How to Generate Start condition using SPI for I2C device?
DISCLAIMER: The voltages involved can easily damage your PIC, your programmer and USB hardware. If you use this design, you do so at your own risk and I am not responsible for any damage that may arise.

Instead of trying to find a software solution, I'd recommend a very simple hardware solution that would allow you to use the stock I2C controller in the PIC. Note that, as with your software solution, you probably need a level shifter to raise your pic's output to the module's 0-24V logic levels but with this solution you dont need a level shifter to drop the module's output to you pic's range (because of the blocking diode). 







simulate this circuit &ndash; Schematic created using CircuitLab

The diode can be any blocking diode with sufficiently low Vfwd (that is why I recommend a shotkey diode) and a high blocking voltage ( > 30V ). The BAT41 series seems to be a good fit according to it's specifications (disclaimer, I have never used it in this application).

This works because I2C is an open collector digital communication. That is, any IC on the I2C bus will only ever pull it low, the bus comes back up high because of the resistor pulling it to Vdd. Thus, if the HM DATA OUT goes low, it pulls the SDAx low with it but when it is high, the PIC is free to let it go high or pull it low itself.

If you need to implement your own level shifting hardware, I'd recommend a simple FET based level shifter. Although beware that the FET must be mounted in the right direction. If you reverse the direction, your pic will be exposed to 24V through it's body diode and it (your PIC) likely wont survive.







simulate this circuit