0
\$\begingroup\$

Referring [This Link] (I2C: Unable to Read Multiple Byte using Bit-Banging method).

I created an I2C BitBanging library for Pic16f877A. But I am unable to Read/Write the EEPROM.

My Pin Configuration are :

SCK : RB0
SDATA_OUT : RB1
SDATA_IN : RB2

Rest code remains the same.

Possibly, The issue could be of the delay function as I am using OSC = 11.0592 MHZ with Pic16f877A. but tried increasing the delay by 2 times. Issue remains the same.

Also,

#pragma config  FOSC    =   HS

Can any one help me with Possible issues and way to rectify the issue.

Note: Code remains the same as the link says. Only Pin and its required registers are changed for Pic16f877A.

\$\endgroup\$
  • \$\begingroup\$ Have you looked at the SCL and SDA lines with a scope? \$\endgroup\$ – tcrosley Oct 7 '15 at 12:34
  • \$\begingroup\$ I haven't read the datasheet for that EEPROM but isn't ~11MHz a bit fast for I2C? \$\endgroup\$ – Roger Rowland Oct 7 '15 at 12:56
  • \$\begingroup\$ @RogerRowland, thanks for your suggestion. As you suggested, I checked the maximum frequency for I2C is 400KHz. I can't change the Oscillator, so what would be the better way to calculate the delay ?? \$\endgroup\$ – skg Oct 7 '15 at 13:14
  • \$\begingroup\$ @skg Just insert delays into your bit banging code. \$\endgroup\$ – Roger Rowland Oct 7 '15 at 13:18
  • \$\begingroup\$ @RogerRowland, I am already using delay in my code. Just I need to increase the delay time. But How much , that i need to calculate. \$\endgroup\$ – skg Oct 7 '15 at 13:46
1
\$\begingroup\$

If all the code is exactly the same you have a mistake here :

#define Crystal_Value       8          // MHz

you should replace this line by:

#define Crystal_Value       11          // MHz

at the condition 11MHz is really the value of your system oscillator and not the only the one of your crystal oscillator.

\$\endgroup\$
  • \$\begingroup\$ thanks for your response. I already did this. " #define Crystal_Value 11.0592 //MHz " \$\endgroup\$ – skg Oct 8 '15 at 4:22
  • \$\begingroup\$ Is 11MHz the frequency of your crystal or the frequency of your system? Some key word defines it \$\endgroup\$ – damien Oct 8 '15 at 8:38
  • \$\begingroup\$ Its Crystal Frequency \$\endgroup\$ – skg Oct 8 '15 at 13:10
1
\$\begingroup\$

Finally I caught my mistake.

Link provide just works fine. It was my mistake. While modifying the functions call, I deleted initI2C() function call. Which was causing the issue.

Also, Crystal value should be

#define Crystal_Value       12          // MHz

Thanks everyone for your valuable suggestions, that helped me improving my code.

\$\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.