Mcp 23017 and Pic 16f877


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Apr 2011
    Location
    BELGIQUE
    Posts
    12

    Default Mcp 23017 and Pic 16f877

    Hello everyone,
    I'm new to this forum and I would use a MCP23017 with a 16F877.
    Not knowing the MCP23017, I initially ordered the release of the MCP23017 in PBP.
    Could you please give me an example of code that could unlock and so I understand.

    In the wait for your answers, thank you in advance.

    Claudy

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


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    CLAUDY , Is the MCP23017 not some sort of I/O expander from MicroChip? You do not need PBP to use it. It is not a processor but an mearly a periferal to allow more I/O pins to be added to an exsisting processor. If the processor you are using is indeed from MicroChip then you can use some of the I2C or Shiftin/Shiftout commands to access it's registers provided if the PBP language.

    Dave Purola,
    N8NTA

  3. #3
    Join Date
    Apr 2011
    Location
    BELGIQUE
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Hello DAVE,
    Yes, I know that the MC23017 is not a processor but I forgot to say that I wish I could control the outputs from the 16F877 I2C. It would be very nice if I could have an example in PBR so I can start with that component which is new for me.

    A big thank you for your reply

    Claudy

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Here's an example from DaveC3.
    Just ignore the interrupt and USB portions.

    The constants and I2CREAD/I2CWRITE statements are what you need.

    http://www.picbasic.co.uk/forum/show...5720#post55720
    DT

  5. #5
    Join Date
    Apr 2011
    Location
    BELGIQUE
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Hi DT,

    Thank you for taking the time to answer me.
    I'll try this code as soon as Monday this weekend I'm in France.

    Again thank you and good weekend to all.

    Claudy

  6. #6
    Join Date
    Apr 2011
    Location
    BELGIQUE
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Hello,

    OK I managed to contact the MCP23017en I2C.
    For now, the test program the LED lights of the 2 ports following a counter made ​​by the software in the 16F877.
    I have a small question.
    When feeds it off, the LED of port B are all lit and the rest for + / - 30sec (while the PIC is running without problem) and then everything works normally.
    If I reflash the PIC everything is OK, the problem happens only when switched on.
    As if it would take some time for it to MCP23017 syncronise with I2C.

    Here is the code used

    adcon1=7 'pour que les entrées analogique du port A soient digitale

    trisa=0 'pour que RA3 soit une entrée et les autres des sorties
    trisb=0 'pour que tout le port B soit des entrées
    trisc=0 'pour que tout le port C soit des entrées

    'initialisation de LCD

    'debut code specifique 877


    DEFINE LCD_DREG PORTD 'LCD data port
    DEFINE LCD_DBIT 4 'LCD data starting bit 0 or 4
    DEFINE LCD_RSREG PORTD 'LCD register select port
    DEFINE LCD_RSBIT 0 'LCD register select bit
    DEFINE LCD_EREG PORTD 'LCD enable port
    DEFINE LCD_EBIT 1 'LCD enable bit
    DEFINE LCD_BITS 4 'LCD bus size 4 or 8
    DEFINE LCD_LINES 2 'Number lines on LCD '
    DEFINE LCD_COMMANDUS 2000 'Command delay time in us
    DEFINE LCD_DATAUS 50 'Data delay time in us




    '***definition des variable pour I2C***
    DEFINE I2C_HOLD 1
    DEFINE I2C_SCLOUT 1
    define I2C_SDA PORTa.0
    DEFINE I2C_SCL PORTa.1
    Define I2C_SLOW 1 'At this clock speed this needed to be added to make it work.


    sda var porta.0 'sda est sur le porta.0
    scl var porta.1 'scl est sur le porta.1


    Addr var byte
    j var byte
    i var byte

    '================================================= =====================================

    '************* DEFINITION DU PORT A ET DU PORT B ***************
    ' Port A Registers (8 Bit Mode)
    IODIRA con $00 ' Port A Direction Bit Control Reg (suivant datasheet)
    IOLATA con $0A ' Output Latch Reg (suivant datasheet)
    'Port B Registers (8 Bit Mode)
    IODIRB con $10 ' Port B Direction Bit Control AReg (suivant datasheet)
    IOLATB con $1A ' Output Latch Reg (suivant datasheet)
    debut:
    lcdout $FE,1, "TEST MCP23017 " ;affichage ecran acceuil
    lcdout $FE,$C0, "V 1.3" ;affichage ecran acceuil
    pause 1000 ;pause pour ecran acceuil

    i2cwrite sda,scl,$40,[IODIRA,0]


    i2cwrite sda,scl,$40,[IODIRb,0]
    pause 100
    'i2cwrite sda,scl,$40,[Ipola,255]
    lcdout $FE,1, "Debut"
    for i=1 to 255

    i2cwrite sda,scl,$40,[iolata,i]
    i2cwrite sda,scl,$40,[iolatb,i]
    lcdout $FE,$C0,"i=",#i
    pause 100
    next i
    lcdout $FE,1, "Fin"
    goto debut




    end


    Thank you for your help

    Claudy
    Last edited by CLAUDY; - 29th April 2011 at 18:58.

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Would a pull-down resistor at each LED solve the problem?
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  8. #8
    Join Date
    Apr 2011
    Location
    BELGIQUE
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    In fact the Pcb is done simply for the moment to get used to the MCP23017 that will serve me to something else after.

    The PCB is composed of 8 LED simply placed on Port A and 8 LED placed on port B. The communication with the Pic I2C is done.
    Pic also controls an LCD 2 * 16.

    The test program is to enable a counter from 1 to 255 that will be displayed on the LCD (i = 1 until i = 255) and the 2 * 8LED (port A and port B).

    At the first power, while port A is activated (LED lit) and port B is disabled (LED off). When the counter reaches + / - 130 (viewed from the LCD), Port A (which was fully activated) starts from the port B but it does not change state. And only when the counter recomm early as 2 port (A and B) fonctionnnent normally (they have at the same time as the LCD).
    And it works very well.
    The problem is powering up.

    The problem must come from the Start Bit of the I2C.
    I already tried some codes for the Start bit but I can not.

    Aurra you an idea?


    Again thank you for your reply

    Claudy

  9. #9
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Quote Originally Posted by CLAUDY
    In fact the Pcb is done simply for the moment to get used to the MCP23017 that will serve me to something else after.
    ...
    Are you saying the MCP23017 is NOT used at the moment? Why issue an I2C command to something inactive? Do you have LEDs connected on the MCP23017?


    Quote Originally Posted by CLAUDY
    The PCB is composed of 8 LED simply placed on Port A and 8 LED placed on port B.
    ...
    Code:
    sda var porta.0 'sda est sur le porta.0
    scl var porta.1 'scl est sur le porta.1
    So you have 16 LEDs on ports A and B, but you also use Port A for I2C communication?

    Why not use Port C.3 for SCL and Port C.4 for SDA (PIC 16F877 datasheet pinout p.3) to avoid interfering with your LEDs?

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Plus ça change, plus c'est pareil...

    KeyWord: Datasheet

    Not ALL PORTA pins are true output... and on PORTB there's this PGM pin who could do nasty thingy if your CONFIG FUSES aren't set properly...

    About them (Config fuses) Where are they?!?

    Are we talking about a 877 or 877A ?

    And finnally... you want to manually assign value to your PORT BEFORE doing anything else... say BEFORE the PAUSE 1000. Usually

    PORTA=0
    PORTB=0
    ...
    TRISA=0
    TRISB=0
    ....
    Variable and all other code here.

    Bonne chance
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Code:
    sda var porta.0 'sda est sur le porta.0
    scl var porta.1 'scl est sur le porta.1
    So you have 16 LEDs on ports A and B, but you also use Port A for I2C communication?

    Why not use Port C.3 for SCL and Port C.4 for SDA (PIC 16F877 datasheet pinout p.3) to avoid interfering with your LEDs?
    Actually If I understand properly, it is worst than this. If the LED are connected to Ground on the I2C line, they Screw-up the line as they have to be Pulled-high (hi-z) but the LED LOAD it to gnd.

    Get rid of the LED on those I/O or, like BobyBert said, move the I2C line elsewhere (it doesn<t need to be on a specific SCL, SDA PIC line as you're using I2CREAD/I2CWRITE who's not using the built in SSP module). You want the I2C line on their own I/O.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  12. #12
    Join Date
    Apr 2011
    Location
    BELGIQUE
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Hello,

    Thank you for your answers.

    When I speak of the port A and B have ports MCP23017 and not PIC.
    The PIC used is a 877A.
    The PIC controls only the LCD and I use the port A of the PIC to bond with the I2C MCP23017.

    A big thank you for your help.

    Soon

    Claudy

  13. #13
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Hi, Claudy

    Following your adventures on many forums for a moment ... I still miss a small thing : YOUR USED SCHEME ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  14. #14
    Join Date
    Apr 2011
    Location
    BELGIQUE
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Hello Alain,

    I still have not found the solution.

    Here's a quick diagram as requested.Printing TEST MCP23017-sch.pdf

    Thank you

    Claudy

  15. #15
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Looks there's also a missing register named IOCON in the settings.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  16. #16
    Join Date
    Apr 2011
    Location
    BELGIQUE
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Hello everyone,

    Ok it works!

    Bit 7 of Port A and B of the MCP23017 must be 1 before the startup of the program.

    And in this case each power program is operating normally the first

    Here is the code added.

    i2cwrite sda,scl,$40,[iolata,128] 'Output Latch Reg
    i2cwrite sda,scl,$40,[iolatb,128] 'Output Latch Reg


    If you have comments please.

    Thank you

    Claudy

  17. #17
    rauloj's Avatar
    rauloj Guest


    Did you find this post helpful? Yes | No

    Default Re: Mcp 23017 and Pic 16f877

    Quote Originally Posted by CLAUDY View Post
    Bit 7 of Port A and B of the MCP23017 must be 1 before the startup of the program.

    And in this case each power program is operating normally the first

    Here is the code added.

    i2cwrite sda,scl,$40,[iolata,128] 'Output Latch Reg
    i2cwrite sda,scl,$40,[iolatb,128] 'Output Latch Reg


    If you have comments please.

    Thank you

    Claudy
    Hi Claudy!

    It's not OLATA/OLATB you are setting 1, but IOCON.
    After power-on BANK bit = 0 and IOCON's adr = 0A/0B not OLATA/OLATB's.
    After setting IOCON bit 7 to 1 you can use address mapping as described in datasheet table 1-5.

    R

Members who have read this thread : 2

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