PDA

View Full Version : I2C command with 16F88



damiko
- 10th July 2005, 16:24
I have a PIC16F88 with port B pin1 as SDA and port B pin 4 as SCL. It runs on 20 Mhz crystal and has SDA only pulled to +5V via 10K resistor. I was using Pic Basic and successfully compiled and ran a program that accessed bytes from a 24LC256 EEprom.

Then I wanted to experience life after 2K, as they all say.. so I purchased and upgraded to Pic Basic PRO. I made changes throughout the program and got all working except for I2C commands. So here are the essential details of my attempt :

Line of code in question:
I2cread portb.1, portb.4, %11010000, EEP_Addr, [EEP_Data]

I have also tried using "DEFINE I2C SLOW 1", "DEFINE I2SCLOUT 1", adding a pullup resistor to SCL line and using 4Mhz crystal instead of 20Mhz..

It used to work!! so it must be possible, does anyone have any pointers for me here?

Thanks!

NavMicroSystems
- 10th July 2005, 17:15
...It used to work!!

I doubt it has ever worked with that line of code.

There are several things:

1.
The 24LC256's address (control-byte) (with A0, A1, and A2 tied to GND)
is: %10100000, NOT %11010000
(See DataSheet)

2.
your variable "EEP_Addr" must be declared as WORD
(See DataSheet)

3.
you should have 4k7 PullUps on both SDA, and SCL
(10k might be a bit to high)

damiko
- 10th July 2005, 18:14
Thanks Ralph,

I think you pretty much pin pointed the problem with my code. I've done as you suggested and now it works.. even with the 20 Mhz crystal and no need for any define commands at the beginning of the program.

cheers,

Damiko

NavMicroSystems
- 10th July 2005, 20:05
Damiko,

I'm glad to hear you have got it working now!