Hardware I2C


Closed Thread
Results 1 to 12 of 12

Thread: Hardware I2C

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Toley00,

    It may be worth your time to download the I2C Bus Specification manual from Phillips. There are 3 data modes for I2C, Standard Mode = upto 100kbits/sec, Fast Mode = upto 400kbits/sec, and High Speed Mode = 3.4Mbits/sec. I've only used I2C for RTC's using both software I2C and Hardware I2C. I didn't have to set anything up special on my PICs for speed. But you do have to put a 10ms pause after any write command to give it time to catch up or settle down. I have seen some posts on this forum where I2C worked better when it was slowed down.

    Don't know if this helps, but I think maybe their manual might give you a better insight into the whole process.

    BobK

  2. #2
    Join Date
    Jun 2005
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    Thank you BobK for your reply.
    I already know about I2C timing protocol, and I use it in many project already. I just need it to read an EEPROM faster than I2CREAD can do.
    Thanks for your help but a 10ms pause will not give me speed...

  3. #3
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    I don't know what PIC you are using, so I can't promise anything, but I've attached a file containing some portions of code I have used with the hardware I2C on a PIC 18F4620.

    The file is a compilation of cut and past from a few include files, and has only been minimally "cleaned up" for public viewing. It has 4 sections:
    1) Basic PIC and HSEROUT setup (mostly to reinforce what pic and how it's configured)
    2) The meat of the I2C commands
    3) Samples of Large Block Reading/Writing to an EEPROM
    4) Samples of Reading/Writing to an RTC

    Hopefully this will get you started.
    Best of luck,
    Steve B

    Disclaimer: Looking a little closer I recall this being one of my first PBP-ASM items I tackled. It worked, and with other things pressing, I haven't gone back and cleaned things up, like unused variables (DelayCtr1 and DelayCtr2) and rements of HSEROUT commands used to debug.
    Attached Files Attached Files
    Last edited by SteveB; - 20th January 2007 at 06:50. Reason: Added disclaime

  4. #4
    Join Date
    Jun 2005
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    Thank you SteveB, looks like what I need. I will take a closer look and adapt it to my needs. I'm using a PIC16F886, but I think all MSSP modules work the same way, and I only need to read from the EEPROM.

  5. #5
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Toley00 View Post
    Thank you SteveB, looks like what I need. I will take a closer look and adapt it to my needs. I'm using a PIC16F886, but I think all MSSP modules work the same way, and I only need to read from the EEPROM.
    A couple of things right off the top of my head. The buffer size will need to be reduced for a 16F. Also, the way I allocated variables to "BANKA" or "BANKX" in the declaration statements will also need changing. If I get a chance later I'll try to give it a look-over for anything else. As I recall, I think I got the basics of the ASM routines from a Microchip document/source, and adapted them for the 18F. So that might also be an avenue to persue.

    Steve B

  6. #6
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Thumbs up Thanks SteveB

    Hi,

    SteveB your routines are neat (at least than mine) and I learnt from it as well. Thanks to you and Toley for raising the topic.
    Regards

    Sougata

  7. #7
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    I made a quick run through the code (while my kids took a nap). Changed all the ASM to PBP. Also modified the buffer size, and some SFR lables to correspond the 16F. It compiles OK, but no 16F's to test it (nor anything to setup the circut without canibalizing something else). Keep in mind, on many of the 18Fs, you've got RAM to burn, so the buffers reflect that. On the 16Fs, you don't have that luxary.

    Hopefully, if you are working it on your end, you can compare/use what I've done to move further down the road.

    I did notice a number of areas where things could be improved or I would do thing differently. The error handling is especially weak. However, I never got any errors with the code and my setup, so never needed it to be very robust. So, I will put this on my *LONG* list of things to do when I get around to it.

    SteveB
    Attached Files Attached Files
    Last edited by SteveB; - 21st January 2007 at 05:58.

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 23:31
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 22:07
  3. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 20:33
  4. Hardware I2C
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 13th March 2008, 14:24
  5. Please help with i2cslave i2c slave
    By cycle_girl in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st December 2005, 14:55

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts