0
\$\begingroup\$

I'm posting the Code here:

    //***************************************************
    void main(void)
    { TRISCbits.TRISC2=0;// configures it as Output
      OpenI2C(MASTER, SLEW_ON); // Initialize I2C module
      SSPADD = 9;               //400kHz Baud clock(9) @16MHz
                                 //100kHz Baud clock(39) @16MHz


    EEByteWrite(0xA0, 0x30, 0xA5);
    PORTCbits.RC2=1;       

}

I happen to Burn this Code that i found on I2c App note and Tried to port the Code in to PIC18f. Well when i burned the code.The SDA and SCL are showing Pulses with 8bits seen on SCL with the help of oscilloscope.Well the Transmission is supposed to End after a Byte Write Function but it shows pulses on both pins even after getting the Byte Write Function is done.

Well as far as from what i learned the I2cBus must be Idle after Writing Bytes!. Well I cross checked whether the ACKSTAT(ACKNOWLEDGEMENT STATUS IS RECIEVING ) and found it recieving from the slave which is an eeprom chip.

Why is this Strange behavior happening on the I2C? Or is it that because of not so clarity in I2c concepts.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Try adding: while(1){} to the end to keep your program from resetting. \$\endgroup\$ – Tut Dec 4 '13 at 12:05
  • \$\begingroup\$ "found on I2c App note" - please provide a link. \$\endgroup\$ – Mels Dec 4 '13 at 12:24
  • \$\begingroup\$ Well it worked :) Well.Can you explain what happens if 'while{}' is not there? \$\endgroup\$ – Rookie91 Dec 4 '13 at 12:37
  • \$\begingroup\$ Thank you.It is a modified Code found from mplab c18 doc @ page no 38 \$\endgroup\$ – Rookie91 Dec 4 '13 at 13:18
2
\$\begingroup\$

Try adding: while(1){} to the end to keep your program from resetting.

Unlike running a PC application, microcontrollers have nowhere to exit to from main(). Generally you need to have an infinite loop or the processor or code will reset and get executed over and over.

For more complete explainations, see:

Who receives the value returned by main()?

or:

What happens when an embedded program finishes?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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