soft i2c does not works

Discussion in 'Embedded Systems and Microcontrollers' started by sumani, Apr 29, 2009.

  1. sumani

    Thread Starter New Member

    Mar 12, 2009
    8
    0
    hi all
    for my project i wrote the following code and simulate through protest.

    void main() {

    int a;
    char txt[10];
    //Soft_I2C_Config(&PORTD, 3, 4); // Initialize full master mode
    lcd_config(&PORTB,1,2,3,7,6,5,4);
    TRISB = 0;
    PORTB=0;

    Lcd_Out(1,2, "Hello");
    Lcd_Cmd(Lcd_CURSOR_OFF);


    // Soft_I2C_Start(); // Issue start signal
    // Soft_I2C_Write(0xA0); // Address PCF8583
    // Soft_I2C_Write(0); // Start from word at address 0 (configuration word)
    // Soft_I2C_Write(0x80); // Write 0x80 to config. (pause counter...)
    // Soft_I2C_Write(0); // Write 0 to cents word
    // Soft_I2C_Write(0); // Write 0 to seconds word
    // Soft_I2C_Write(0x30); // Write 0x30 to minutes word
    // Soft_I2C_Write(0x11); // Write 0x11 to hours word
    // Soft_I2C_Write(0x30); // Write 0x24 to year/date word
    // Soft_I2C_Write(0x08); // Write 0x08 to weekday/month
    // Soft_I2C_Stop(); // Issue stop signal
    //
    // Soft_I2C_Start(); // Issue start signal
    // Soft_I2C_Write(0xA0); // Address of eeprom
    // Soft_I2C_Write(0); // Start from word at address 0
    // Soft_I2C_Write(0); // Write 0 to config word (enable counting)
    // Soft_I2C_Stop(); // Issue stop signal




    }//~!

    the software I2C doesnt works and if i enable Soft_I2C_Config(&PORTD, 3, 4);(uncomment) then the simulations strucks and even the LCD out put didin't come. don't care of the rest of the i2c codes. even still they are disabled and if i just enable only "Soft_I2C_Config(&PORTD, 3, 4);" line then there is no lcd output at simulations.
    hereby i've attached my microc code and protest file.please can any one explore this problem.
     
    Last edited: Apr 29, 2009
  2. CVMichael

    Senior Member

    Aug 3, 2007
    416
    17
    I guess you are using the MikroC compiler ?

    If you look in the help for Soft_I2C_Config, it says: "Note: This library implements time-based activities, so interrupts need to be disabled when using Soft I²C"

    Then if you look for "Lcd_Config", it does not say if it's using interrupts or not, but logically it probably does...

    So, in this case, you probably have a conflict between the two because of this reason
     
  3. sumani

    Thread Starter New Member

    Mar 12, 2009
    8
    0
    yes i'm using microc complier. ok.. i got the point.so now what can i do for make it work? do you have any suggestions? is there are any compliers which overcomes this drawback?
     
  4. jvjtech

    Member

    Jan 26, 2008
    23
    0
    I, too, will look up the MicroC compiler and libraries.
    Sumani: A schematic might help.
    Many problems with I2C come from three areas:
    - sensing the idle state of the two lines: SDA & SCL
    which at Idle should be High; code that waits for
    these lines to be high may hang if these lines
    never go high
    - incorrectly adressing the target device;
    - looking (or waiting) for the ACK or NACK from
    the target device;
    My apologies to MicroC as these issues are most likely addressed in the libraries.
    This information is provided to the forum as gerneralized comments for anyone wanting bit-bang their own I2C code.
    Regards: JJ
     
  5. CVMichael

    Senior Member

    Aug 3, 2007
    416
    17
Loading...