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 I2C with 18F2685

    Hello,

    I am trying, unsuccessuly up to now, to make some I2C communications between a 18F2685, a DAC (MAX517) and two I/O expanders (23008), everybody is on the same I2C bus, the DAC receiving data from the PIC and the I/O expanders being read by the PIC.

    I would like to use the PBP commands I2CREAD and I2CWRITE but they look to be written for older PICS.

    Do they also work with 18F PICS ? If yes, do I need to make some kind of preliminary initialisation, for example set up the I2C pins via TRISC or configure the MSSP registers ? Do I need to setup the bus speed or anything else (address width for example ?)

    I have an other question about the addresses. They are supposed to be 7 bits width, but they look as being left justified. So, do they need to be passed to the PBP instructions as left justified or right justified variables. For example how should I pass the address $2c : $2c or $58 ?

    Any help greatly appreciated

    Best regards

    MikeBZH

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

    Default

    MikeBZH, Its in the manual.... And there is no difference whether its for an 16 series or 18 series..

    Dave Purola,
    N8NTA

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default

    I use both I2CRead and I2CWrite with pic18F4680 without any problem.

    In my code I use always the following two declarations:

    DEFINE I2C_SLOW 1
    DEFINE I2C_HOLD 1

    Al.
    All progress began with an idea

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

    Default

    Dave, Aratti

    So it is so simple ?
    I'll try this tomorrow.

    Many thanks for your help

    MikeBZH (also F8DFN, 73's Dave)

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

    Arrow

    Good evening !

    No way with this problem !
    I have spent the whole day on it with no result...

    The circuit is yet very simplified : only the 18F2685 + the MAX517 + 2 pull-up resistors. The PIC is running at 32 MHz.

    The program is also very simple and starts with :

    DEFINE I2C_SLOW 1
    DEFINE I2C_HOLD 1
    ....

    AppGain:

    Gain = $55
    RESET517 = $10
    CTRL517 = $00

    Re2 : I2CWRITE PORTC.4,PORTC.3,CTRL517,ADR517,[Gain],Re1
    PAUSE 10
    GOTO Re3

    Re1: ADR517 = ADR517 + 1
    if (ADR517 <> $FF) then
    goto Re2
    else
    endif

    Re3: RETURN

    All the variables are bytes.
    AppGain is called by a test section of my program.

    The hereabove version was adapted to scan the addresses in search of a response from the MAX517. According to the manual, the program jumps to Re1 if no ACK was received from the slave. And there is never any ACK received, the program always ends with $FF in ADR517. The slave address should be $2c but I got no answer from there.

    I have checked the SDA and SCL lines with my scope. The signals look fine but no ACK is visible. I have even changed the MAX517 for a new one : same behaviour.

    Any idea ?

    MikeBZH

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

    Default

    MikeBZH, What values are you using for the pullup reststors on the SDA/SCL lines... I have found in the past that 4.7 k resistors are too large and slow the current flow for passive pullup when I use more than 4 devices on a bus... I would use 2.2 k resistors and try that.. It should cleanup the data signal a bit.. I'm not sure if the statement DEFINE I2C_HOLD 1 is required or not.. I have never used it in the past and I have used 100 khz. parts and 400 khz. parts with no issues.. Just make sure you use the statement DEFINE I2C_SLOW 1 if the part is only good for 100 khz. and you are running the processor at more than 4 mhz..

    Dave Purola,
    N8NTA

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