I2C with 18F2685


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    May 2009
    Location
    Saint-Quentin-en-Yvelines, FRANCE
    Posts
    82

    Default

    Hi,

    I fixed it, but the result is very strange.
    Resistors values or Defines have no influence but it seems that there is bug in the PBP documentation (or in the compiler, as you prefer).

    I found that the instruction :
    I2CWRITE DataPin, ClockPin, Control, [Address,] ...

    should be written
    I2CWRITE DataPin, ClockPin, [Address,] Control...

    In other words everything works if one pass first the Address and then the Control instead of what is written in the documentation. This is very clear with a dual trace scope on SDA and SCL.

    My compiler version is 2.50L

    MikeBZH / F8DFN

  2. #2
    Join Date
    May 2009
    Location
    Saint-Quentin-en-Yvelines, FRANCE
    Posts
    82

    Default

    Moreover,

    The physical address has to be shifted left once (multiplied by 2) to cope with the I2C format. In my case the physical address is $2C : I have to pass $58 to I2CWRITE.

    MikeBZH / F8DFN

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358

    Default

    Strange... I use PBP v2.50 I2C to talk to EEPROM 24LC64, DS1307 and MCP23008 and other devices on the same board and it all behaves as expected per the Manual...

  4. #4
    Join Date
    May 2009
    Location
    Saint-Quentin-en-Yvelines, FRANCE
    Posts
    82

    Default

    Hi Melanie,

    Please note that I use PBPL. Maybe the behaviour of this version is different from the others. I have no more time to make some comparison tests but I will do them when I come back from vacation by the end of August.

    MikeBZH / F8DFN

  5. #5
    Join Date
    May 2009
    Location
    Saint-Quentin-en-Yvelines, FRANCE
    Posts
    82

    Talking Same bug with I2CREAD

    Hi,

    Coming back after some time spent with other business...
    I have no more MAX517 in my circuit but the MCP23008 are still there and I need to use I2CWRITE and I2CREAD with them.
    The issue is still there. I confirm that with my PBPL v2.50, I need to invert the address and the control fields and to multiply the address by 2 to make I2CWRITE work. And from the experiments done this morning I know that I need to do the same thing for I2CREAD !

    Best regards

    MikeBZH / F8DFN
    Last edited by MikeBZH; - 11th January 2010 at 12:46.

  6. #6
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default

    MikeBZH, I hope you had a nice vacation in August... I have been currently using a pair of 24LC1025's to log data from my Solar Tracker which uses an 18F2620 running @ 40 Mhz. I have had no problem with them even in the below zero temperatures we have up here in Michigan...
    I do not compile with PBPL as I have used the internal flash to about 3/4"s of its capacity. It's nice to see you back...

    Dave Purola
    N8NTA

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358

    Default

    I need to invert the address and the control fields and to multiply the address by 2
    Then you are doing something very strange in either your Hardware connections or in Software!

    If fact, I believe you've not realised how the chip is to be addressed (refer to Datasheet 1.4.1). If you have GROUNDED pins A0,A1 and A2, then you would address the chip as $40, but if for example A1 and A2 are GROUNDED and you tie A0 to VDD, then you would address the chip as $42. Note that Bit 0 must be left alone, because it determines if this is a READ or WRITE operation!!!! YOU don't touch BIT-0, it is set for you elsewhere by the I2C commands (which also determines that your ADDRESS must be a BYTE VARIABLE and NOT a Constant).

    I use MCP23008's in several designs with both 16F's and 18F's. PBP Ver 2.46 thru 2.50 has no problems and no issues and allows me to port software across several PIC families which may not have I2C hardware capability. I commonly mix MCP23008's with EEPROM's and RTC's all on the same bus, and up to five devices on the same bus pins are good with 4K7 Pull-Up's.

    I2CWrite SDA,SCL,I2CAddress,I2CRegister,[I2CData]

    Where I2CAddress, I2CRegister and I2CData are all BYTES and previously (for example)...

    I2CAddress=$42 ' Hardware Address of selected MCP23008 Device
    I2CRegister=9 ' Device Register Address being written to

    There is no Hardware initialisation required on the PIC side (other than defining your SCL and SDA pins), but yes, you DO have to initialise your MCP23008's before you use them!

    Here is a typical initialisation sequence at initial Power-On for TWO MCP's being configured for OUTPUT (with different inital ON states)...

    Code:
    	For CounterA=0 to 1
    		If CounterA=1 then 
    			I2CAddress=GPA
    			else
    			I2CAddress=GPB
    			endif
    		For I2CRegister=0 to 9
    			I2CData=0
    			If I2CRegister=9 then
    				If CounterA=0 then
    					I2CData=%11111111
    					else
    					I2CData=%00001100
    					endif
    				endif
    			I2CWrite SDA,SCL,I2CAddress,I2CRegister,[I2CData]
    			Next I2CRegister
    		Next CounterA
    Refer to the MCP's Datasheet for configuring for your own requirements.

Similar Threads

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

Members who have read this thread : 0

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