PIC 18F4550 and MCP23017


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Nov 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Ok I changed it to 4.7k R and correct the port direction.
    could you please tell me what im doing wrong for initializing the chip? I know the default mode chip's port are all input and all the register's bit are %000000000 according to table 1-6 page 11 pf MCP23017 data sheet it means there is no pull up, inverter. am i right?
    i just need to have access to those register address which they are all again at page 11 table 1-6.
    and the way to do that with I2CWRITE command is following the help page of PBP which it says: I2CWRITE DataPin,ClockPin,Control,{Address,}[Value{,Value...}]{,Label}
    indicate the data pin, indicate clock pin, address of specific register that i want to change (IODIRA &00) table 1-6, address of my chip, [ and value in the bracket ]
    is this the correct way?

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Table 1.6 pg 11 shows POR/RST value of IODIRA and IODIRB is %11111111. NOT %00000000. Setting the dir to 1 makes the pin an input.

    Maybe you were looking at the next 2 registers? IPOLA and IPOLB?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Mar 2008
    Location
    Gerogetown, Texas
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Take a look at your I2C data format

    The proper way to send data for this chip is

    i2cwrite I2C_SDA, I2C_CLK,control,[Value{..value}]

    In your case it should be:

    I2C_SDA is PORTC.4 or as you have defined DP
    I2C_CLK is PORTC.3 or as you have defined CP

    The control needs to be: (assuming you have the address lines connected to zero volts)
    %01000000 or $40 for write
    %01000001 or $41 for read

    {PicBasic actually changes the control bit.0 for you in the statement I2CWRITE and I2CREAD}

    So to set a register you need two values, the registers address and the value you want it to be.

    To set the IODIRA to be outputs you would send
    Value 1 control code for IODIRA is $00 see table 1-3 in the data sheet
    value 2 you want to make them outputs so would be $00 (just like setting TRIS in a PIC)

    I2CWRITE DP, CP, $40[$00, $00] 'IODIRA is set to output

    You also need to set the IOCON register
    I2CWRITE DP, CP, $40[$05, %10111000] "see data sheet register 1-6 for details


    So to initialize Porta as output you would program this.
    I2CWRITE DP, CP, $40[$05, %10111000] "Set configuration
    I2CWRITE DP, CP, $40[$00, $00] 'Make porta all outputs

    Then to write to the port you would use this:
    I2CWRITE DP, CP, $40[$09,$FF] '$09 is the address for GPIOA, $FF would make the porta pins high, to set them low, send values [$09, $00]

    You only need to set the weak pull-ups if you are making a port(pin) an input.

    Hope this helps
    Dave

  4. #4
    Join Date
    Nov 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Smile Thanks

    Thanks Dave,
    I really appreciate your time and patient. in I2c command where it asks about the address I thought it asks about chip's physical address, but now thank to you I can fully control this chip and use it. again thanks

    Artha

  5. #5
    Join Date
    Mar 2008
    Location
    Gerogetown, Texas
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    You are welcome, glad I could help.

    Take care

    Dave

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