Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I2C gives me headaches

Status
Not open for further replies.

Z80

Full Member level 1
Joined
Feb 20, 2004
Messages
96
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,257
i2c für z80 source

I am trying to use I2C with HI-TECH compiler v8.02 PL1
I have to connect a 24FC515 I2C EEPROM to a 16F876A. So, I am using master I2C communication.
The EEPROM is preprogrammed (it has a 8 bit PCM wave file stored in it). In my program I will only have to use sequential read, because I have to send that wave to the CCP port all at once. Anyway, since it's the first time I'm dealing practically with I2C, I guess I have a lot of learning to do. I'm familiar with I2C details but I haven't ever really used it.
I want to use 1MHz clock, and the datasheet says that the pullups have to be 2K.
I wrote my own I2C routines, using the 16F catalog, manual, and the app notes. Imagine my surprize when I found out that the PIC can't read a damn bit from the EEPROM.
So, after many hours spent banging my head against the keyboard, I thought that I might try to use the I2C examples that come with the PICC compiler. I made some manual test (read byte from that address, look on HEX file and see if its correct), and they seem to work. But, some guys on the HITECH forum say that those routines aren't working properly. How can that be? I guess that I'm doing something wrong when testing them. Well, considering that I'm very paranoid when it comes to freely available source code, I tend to believe those detractors.
Bottom line is: what I'm trying to do does not work, and since the CCP related code works fine (tested and retested it), I'm assuming that the problem comes from the I2C. And this confirmes my previous suspicion that I2C is a great source of frustration.
Now, being very low on time (it's a project that MUST be finalized in about three weeks, and the I2C part is only a minor section of it), I'm beginning to panic. The perspective of spending days trying to figure out what exacly that damn bit from register whatever does is frightening me.
I know of microchipc.com and piclist, but I really don't want to go through that the-guy-says-that-the-thing-is-tested-and-it-works-but-it-does-not experience. So if anyone can point me to something that is REALLY tested and proved to be working, you'd save extra hours of head aches.
Oh, I forgot to mention, I have to use the MSSP module, I'm not considering software I2C (yes, I know, those examples use software, but they were only for testing).
Any help would be much appreciated.
 

picc i2c example

I am working with I2C alot and there is no problem with it on the PIC.

Make sure that you are using pullups of max. 4K7 on SCA and SCL!

You can use the routines from here which are tested and working:
https://www.microchipc.com/sourcecode/PIC_Hi-Tech_C_I2C_for_EEPROM_24LC01B.zip

Another question: what update rate do you need for your data?

Note I2C is not the fastest bus, I have an application which uses voice playback to acknowledge commands from the user and I had to use an SPI dataflash to get the required data fast enough (I need 8Khz and the PIC is running with a 16MHz Xtal).

hope this helps and best regards

best regards
 

hitech c i2c rutins

Like I said, I use 2K pullups, as the datasheet says (standard value for 1MHz clock). Probably the problem is in software. Thank you for that link, I'll check it out today, and notify you tomorrow about the results.
24FC515 suports up to 1MHz clock rate, and I'm using too 8KHz sampling rate for PCM sound. BTW, my project is a phone alarm system that dials a specific number and sends a voice message through the phone line to the destinatary. I believe that 1MHz clock for I2C is more than enough for 8 KHz sampling frequency. Maybe I'm mistaking?
 

z80 i2c

C-Man said:
You can use the routines from here which are tested and working:
https://www.microchipc.com/sourcecode/PIC_Hi-Tech_C_I2C_for_EEPROM_24LC01B.zip

That code uses software I2C, I mentioned that I need HW. Besides that, it seems to need the I2C example that comes with the HI-TECH compiler. And, by the way, that example has an error that makes it unusable. Well, it can be easily corrected, but it doesn't work as it is.
I solved the problem yesterday using some code found on the internet, and the sound playback actually works (actually, someone listened yesterday the opening speech from Iron Maiden's "The Number of the Beast" on the phone, and that was played by my project, but I digress :D ).
Anyway, I still have many things left to clarify. After looking through a lot of I2C C code found on the net, I saw that nobody uses the same methods. For instance, for knowing when a START has ended, some poll SEN bit, others poll SSPIF. Another thing I don't understand is how should SSPIF be used? Some clear it before sending/receiving (writing/readint to/from SSPBUF), and poll it afterwards, others clear right after sending.
Other issues is RCEN. Does it automatically begin the reading of a byte, or the reading actually begins when SSPBUF is read?
And the MSSP section from the Midrange Manual for PICs is so HUGE! I think that a typical flowchart for reading/writing I2C should be provided, but it is not.
 

picc 1mhz i2c

Did someone use the master I2C mode in PICC compiler? Event-driven not software.
 

high tech c 1 mhz i2c

What do you mean event driven. Do you mean with internal hardware resources?

Regards!
 

how to check if i2c is working?

I think the best way you can do is to see the square wave yourself... try to use an oscilloscope and check if you are transmitting and recieving the correct data... you can also try to check if you have the same baudrate on both the master and slaves...

Added after 41 seconds:

I think the best way you can do is to see the square wave yourself... try to use an oscilloscope and check if you are transmitting and recieving the correct data... you can also try to check if you have the same baudrate on both the master and slaves...
 

hitech i2c sample

I agree with uper sugestion about use of osciloscope. I think that you can use 400kHz maximum CLK frequency on PIC.

I'm using I2C network. For master I'm using PIC18F8520 and for slaves PIC16F876 and for now that works quite OK. Now I have connected 4 slaves and my targert is 125.

If you still need help let me now.

Regards!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top