0
\$\begingroup\$

I am trying to communicate with the device having internal communication as I2C while externally it has two different pin for Input & Output along with a separate pin for Clock. Here is the link.

I am using SPI to communicate with this device. But I am unable to generate START/STOP condition to communicate with I2C device.

Can I get some suggestion to overcome this issue ???

I am using C Coding.


I Tried Bit Banging as follow

Dont know if any logical error.

Here is the Start Condition I m trying to implement :

bool generateStartSeq()
{
    SPI1STATbits.SPIEN      = 0;    // disable SPI port
//    SPI1CON1bits.DISSCK       = 1;    // Internal SPIx clock is enabled
//    SPI1STATbits.SPIEN        = 1;    // enable SPI port, clear status

    AD1PCFG = 0xFFFF;               // Convert IO pin to Digital
    TRISFbits.TRISF6 = 0;           // Configure RF6 pin as output;
    TRISFbits.TRISF8 = 0;           // Configure RF8 pin as output;

    LATFbits.LATF6 = 1;             // Make RF6 pin high

    LATFbits.LATF8 = 1;

    Nop;
    Nop;
    Nop;
    Nop;
    Nop;

    LATFbits.LATF8 = 0;

    //    writeSPI1(0xFF);                // SDO send data High
    //    
    //    Nop;
    //    Nop;
    //    Nop;
    //    Nop;
    //    Nop;
    //    
    //    writeSPI1(0x00);

    SPI1Init();

    return true;

}

Any suggestion will really help me to correct the logic.

\$\endgroup\$
13
  • \$\begingroup\$ You've thoroughly confused me. Are you trying to use I2C or SPI? Pick one - they're not compatible. \$\endgroup\$
    – brhans
    Jul 16, 2015 at 11:47
  • 2
    \$\begingroup\$ Use Bit banging. Draw the schematics \$\endgroup\$
    – User323693
    Jul 16, 2015 at 11:54
  • \$\begingroup\$ @brhans.. Please check the link. In this Module, Internal communication is using I2C while externally It had provided 2 separate Pin for Input/Output. So, I am trying to communicate with it via SPI. \$\endgroup\$
    – skg
    Jul 16, 2015 at 11:54
  • \$\begingroup\$ Maybe you need to edit your question to provide more details - specifically: which PIC you're using, how you've got it connected, what its connected to and you're trying to communicate with, etc ... \$\endgroup\$
    – brhans
    Jul 16, 2015 at 12:03
  • \$\begingroup\$ @brhans, I have Hans ID Module.I need to design a communication library with Pic24f128GA010.If you check th manual of ID module in the link. It has 3 pins for communication DATA OUT, DATA IN, CLK. Its internal design uses I2C. Can you suggest me how to design communication between two. I decided to use SPI since its an Synchronous communication. I cant use I2C directly as it uses only 2 pin SDA & SCLK. \$\endgroup\$
    – skg
    Jul 16, 2015 at 12:08

1 Answer 1

1
\$\begingroup\$

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).

schematic

simulate this circuit – 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.

schematic

simulate this circuit

\$\endgroup\$
2
  • \$\begingroup\$ thanks for your answer. I m not good at circuits. Can you suggest me Schottky diode (D1) part number. Also Han Module works at 24v logic level only.So, i guess implementing a level shifter is essential. If this circuit is possible then my life will be really easy. Do guide me bit more about the circuit or share me the link to gain more information to make it work more accurately. thanks alot for sharing very important knowledge with me. \$\endgroup\$
    – skg
    Jul 17, 2015 at 6:02
  • \$\begingroup\$ See update above. \$\endgroup\$
    – Mathieu L.
    Jul 17, 2015 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.