Pic18f25k20 + module i2c (pcf8574)


+ Reply to Thread
Results 1 to 9 of 9

Thread: Pic18f25k20 + module i2c (pcf8574)50 days old

  1. #1
    Inactive member Jenny96's Avatar
    Join Date
    Oct 2019
    Posts
    1
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    0

    0 Not allowed!

    Default Pic18f25k20 + module i2c (pcf8574)

    Hi everybody how are you?
    sorry, I have a problem with the I2C communication of pic18f25k20 to transmit data to the pcf8574 module.
    Actually I need to transmit data for an LCD, however not understanding the exact operation of the pcf8574 module, I am testing using a led sequence.
    According to the compilation manual for PROTON, I am using the busout commands and previously declared the pins: Declare SCL_Pin = PORTC.3
    Declare SDA_Pin = PORTC.4, now the operation of the pcf8574 module is identified by an address that is set with pins A0, A1, and A2, according to the data sheet, for the configuration A0 = low, A1 = low and A2 = low, the address corresponds 0x40 in hexadecimal, to identify it to that device, which after starting the I2C bus (BStart), I detail this address to identify the slave device ( BusOut 0x40), and then if I convey the desired address ( BusOut 0x0F ) in order to have 11110000 (0x0F) in binary and turn on LEDs, after a delay of 500ms again I transmit another address 00001111 (0xF0).

    the code does compile, and in the simulation it does not work! ... to which I thought the solution would be the configuration of 18f25k20 records detailed in the data sheet, and they are configured like this: SSPCON1 = 40, SSPCON2 = 37, SSPSTAT = 140, SSPADD = 40, SSPMSK = 255, and even then it does not work in the simulation (proteus 8.6)

    Code:
     ' Name: Jenny Rosales
     ' Date: ---------
     
     Device = 18F25K20
     Xtal = 16
     
     SSPCON1 = 40    'control register 1 in binary 00101000
     SSPCON2 = 37    'control register 2 in binary 00100101
     SSPSTAT = 140   'binary status register 10001100
     SSPADD  = 40    ' binary address register  00101000
     SSPMSK = 255    ' address mask register 
     
     Declare SCL_Pin = PORTC.1
     Declare SDA_Pin = PORTC.2
    
     main:
         BStart   'start I2C
         BusOut 0x40 'device address A0=L , A1=L, A2=L  
         BusOut 0x0F  ' bits to be transmitted to pcf8574 and get binary 11110000 and turn on the led
         DelayMS 500
         BusOut 0xF0   '  after the delay another address is sent 00001111 and turn on the led
         DelayMS 500
         BStop
         DelayMS 5
        
        GoTo main
        End
    It is not bad, if the code, or I must use another structure for the 18f25k20, since for the 16f877A if the code works in the compilation and simulation,
    Help me! .... I thank you for your attention and comments, regards


    I also attached an image of the simulation
    Attached Thumbnails Attached Thumbnails simulation.jpg‎  
    Last edited by Lester; 3rd October 2019 at 06:50. Reason: added BBCODE - Admin

Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,217
    Thumbs Up
    Received: 74
    Given: 180
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: Pic18f25k20 + module i2c (pcf8574)

    Sadly a simulation is only as good as the model. I find generally that stuff that works in sim tends to work in the real world, but if sim fails and I'm happy that the code is good, it's worth that small amount of time it takes to try it on real hardware.

    Although i2c is synchronous (and therefore not clock sensitive) are you sure the PIC device is running at the speed you think it is. Write a blinky to check clock speed.

    It might also be worth running an i2c scanner just to confirm addresses.

    I don't know the 18F25K20 but I do use 18F25K50. Don't know if this will help but heres config I use for the k50

    Xtal = 48
    Declare Hbus_Bitrate = 100
    Declare HSCL_Pin = PORTB.1
    Declare HSDA_Pin = PORTB.0

    Symbol PLLEN = OSCCON2.4 ' software PLL Enable Bit
    Symbol SPLLMULT = OSCTUNE.7 ' software PLL multiplier select bit
    Symbol PLLRDY = OSCCON2.7 ' PLL Run Status Bit

    PLLEN = 0 ' turn off PLL for safety while we setup clock
    SPLLMULT = 1 ' SPLLMULT 3xPLL
    OSCCON = 111000 ' Oscillator Control Register
    OSCCON2 = 010000 ' Oscillator Control Register 2
    ACTCON = 010000 ' Actice Clock Tuning Control Register
    While PLLRDY = 0
    DelayMS 1 ' wait a bit for the clock to stabilize
    Last edited by towlerg; 3rd October 2019 at 03:40.
    George.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,408
    Thumbs Up
    Received: 291
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: Pic18f25k20 + module i2c (pcf8574)

    One of our excellent code creators Alberto wrote a library for the PCF8574 on the Wiki a few years ago:

    Port expansion using the PCF8574A

    This should help.

    I also noticed you are setting up the MSSP peripheral, but the Busin and Busout commands use a software implementation of I2C so they are not needed, and can actually disturb a program if they are set, but not used.

    If you are using the new compiler vesion, the 18F25K20 device will default to its PLL set, because it is what the Amicus18 uses, and the device will run at Xtal x 4, unless fuses are placed in the code by the user. So change the Declare Xtal = 16 to Declare Xtal = 64.
    Last edited by top204; 3rd October 2019 at 10:02.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    505
    Thumbs Up
    Received: 30
    Given: 7
    Total Downloaded
    3.72 GB

    0 Not allowed!

    Default Re: Pic18f25k20 + module i2c (pcf8574)

    I see Les had already indicated that you do not need to set up the MSSP module. I am sure someone will correct me if I am wrong but for future reference my understanding is that...
    1) If you are using the MSSP module and commands rather than direct register reads/writes I believe you should be using the HBus commands (H for Hardware) in which case the with the exception of devices with PPS the Clock & Data pins are fixed when using the MSSP module.
    2) The SCL_Pin/SDA_Pin commands are generally only required when using a software implementation of the I2C bus such as the Bus and I2C command.

    Although I appreciate that with both hardware and software options available covered by three different sets of commands that it can be easy to accidentally mix and match.

    One thing I would have pointed out about your MSSP setup if you were using the MSSP was that Section 6.2 of the PCF8574 data sheet (Phillips) states that "Both data and clock lines remain HIGH when the bus is not busy." Thus the clock idle state is High and you had SSPCON1.4 set to 0 for a Low idle state. So it is worth double checking that is correct when using the MSSP.

    Make sure the 8574 device you are using is an 8574 and not an 8574A as they have different slave addresses.

    If you are having trouble with the bus commands try the I2Cin/I2Cout commands, this is an example of some code I wrote a few years ago for a I2C integrated D to A/A to D as an example of how to use them...
    Code:
    'Setup PCF8591P ADC/DAC Control codes
    Symbol Read_Control = $91   'PCF8591P Addressing & Read_Control value (1001, 000 (Address), 1 (Read))
    Symbol Write_Control = $90  'PCF8591P Addressing & Write_Control value(1001, 000 (Address), 0 (Write))
    Symbol Mode_Control = $40   'Enable PCF8591P Analogue output and set ADC channel to 0 [bits 1:0]
    
    '# Configure I2C Bus #
    I2C_Config:
    TRISC = $00                 'Set port to Output
    LATC = $00                  'Set inital status of all pins to 0
    'Alias Clock and Data
    Symbol SDA = PORTC.1        ' Alias the SDA (Data) line to PortC.1
    Symbol SCL = PORTC.0        ' Alias the SCL (Clock) line to PortC.0
    Return
    
    '# Initial data Write/Read #
    DAC_Data = 137                                                  'Send Inital data to DAC (Vout = 2.74V (137 x 20mV))
    I2COut SDA, SCL, Write_Control , Mode_Control ,  [ DAC_Data ]   'Send Initial data to the 8591 (output to Amplifer)
    DelayUS 20                                                      'Wait 2 clock cycles between Write & Read operations
    I2CIn SDA, SCL, Read_Control , [ ADC_Data]                      'Start a new ADC conversion and Read Junk ADC result
    DelayUS 20
    
    '~~~ Test LM741 ~~~
    LM741_Test:
    Pass_Count = 0  'Clear Pass Count
    'Generate Sawtooth wave value
    For DAC_Data = 138 To 188                                       '2.76V - 3.76V X 4 = 11.04 - 15.04V
                                                                    '138 - 162 = 2.76V - 3.24V X 4 = 11.04 - 12.96V
    'Send new data and get previous data
    I2COut SDA, SCL, Write_Control , Mode_Control , [ DAC_Data ]    'Send new data to the 8591 (output to Amplifer)
    DelayUS 20                                                      'Wait 2 clock cycles between Write & Read operations
    I2CIn SDA, SCL, Read_Control , [ ADC_Data ]                     'Start a new ADC conversion and Read previous ADC result
    ADC_Data = ADC_Data + 1                                         'Compensate for read being l count behind write
    
    'Compare ADC_Data to DAC_Data & display result 
    GoSub Increment_Pass_Count
    Next

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,287
    Thumbs Up
    Received: 17
    Given: 0
    Total Downloaded
    872.27 MB

    0 Not allowed!

    Default Re: Pic18f25k20 + module i2c (pcf8574)

    The LED bar graph in Proteus is not an 'animated' component so LED's will not work in the simulator, only the voltage indicators

    I see that your BUS declaration does not agree with the circuit diagram
    Last edited by See_Mos; 3rd October 2019 at 16:31.
    My RAM is failing

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,287
    Thumbs Up
    Received: 17
    Given: 0
    Total Downloaded
    872.27 MB

    0 Not allowed!

    Default Re: Pic18f25k20 + module i2c (pcf8574)

    Interesting, I dug out some old code for the PCF857x series.

    Busout and I2COut are not working but HBusOut is.
    My RAM is failing

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,287
    Thumbs Up
    Received: 17
    Given: 0
    Total Downloaded
    872.27 MB

    0 Not allowed!

    Default Re: Pic18f25k20 + module i2c (pcf8574)

    It's subtle, but all there in the manual. These work in Proteus using an 18F25K22 and I did not need to setup the MSSP though you might for real hardware.



    Code:
    ' ******************************************************************
    ' Software Bus
    ' ******************************************************************
        Declare SCL_Pin = PORTC.3
        Declare SDA_Pin = PORTC.4
        Declare Slow_Bus On            ' not used by Proteus ?
     
        While 1 = 1
            BStart   '
            BusOut $40,[$0F]       ' note square brackets after a command
            DelayMS 500
            BusOut $F0             ' Note, no command = no brackets
            DelayMS 500
            BStop
            DelayMS 5
        Wend
    Code:
    ' *********************************************************************
    ' I2C Bus
    ' *********************************************************************
        Symbol SCL = PORTC.3
        Symbol SDA = PORTC.4
        Declare I2C_Slow_Bus On
        
        While 1 = 1
            I2COut SDA,SCL, $40, [$0F]
            DelayMS 500
            I2COut SDA,SCL, $40, [$F0]
            DelayMS 500
        Wend
    Code:
    ' **********************************************************************
    ' Hardware Bus
    ' **********************************************************************
        Declare SDA_Pin PORTC.3
        Declare SCL_Pin PORTC.4
        Declare Hbus_Bitrate 100    '100, 400, 1000 (Not used by Proteus)    
    
        While 1 = 1
    '        HBStart
            A = $0F
            HBusOut $40, [A]          ' Square brackets after a command
            DelayMS 500
            HBusOut $40, [$F0]        ' as above
            DelayMS 500
            HBusOut $FF                     ' No command = no brackets
    '        HBStop
            DelayMS 500
        Wend
    My RAM is failing

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    129
    Thumbs Up
    Received: 8
    Given: 12
    Total Downloaded
    2.89 GB

    0 Not allowed!

    Default Re: Pic18f25k20 + module i2c (pcf8574)

    Hi,
    In my opinion hardware IIC is simpler to use than bitbanging. There is no setup apart from bitrate if you don't want the default and most of the time I get by with just Hbusin and Hbusout. The only downside is that on 18f25k20 you have fixed pins.
    Flosi Guğmundsson
    Reykjavík

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #9
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,779
    Thumbs Up
    Received: 83
    Given: 34
    Total Downloaded
    4.30 GB

    0 Not allowed!

    Default Re: Pic18f25k20 + module i2c (pcf8574)

    The other advantage of Hbusout/in is they have small hardware buffers and interrupts.
    I've used both the 8574 and the MCP23017 (16 ports ) with WIKI software for Lcd and for both inputs and outputs. They work well but I've only used 16f1827 and 18f2480 although I hope to be using your chip soon.
    John
    Last edited by John Drew; 4th October 2019 at 00:01. Reason: Messed up chip name

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. Replies: 4
      Last Post: 10th November 2019, 01:55
    2. I2C problem with PCF8574
      By gingpeakin in forum Master Synchronous Serial Port (MSSP) module / 3-wire SPI / I2C™ / Master and Slave modes
      Replies: 3
      Last Post: 18th April 2015, 00:32
    3. PCF8574 I2C port expander problem
      By Peter Truman in forum Proton Plus Compiler v3
      Replies: 12
      Last Post: 25th November 2012, 05:18
    4. [SOLVED !] I2c & Pcf8574 & Pic16f916?
      By IanHemmingsen in forum Proton Plus Compiler v3
      Replies: 5
      Last Post: 9th March 2012, 03:00
    5. [SOLVED !] PIC16F687 I2C problem reading PCF8574
      By Brent Warp in forum Proton Plus Compiler v3
      Replies: 1
      Last Post: 2nd August 2006, 08:38

    Posting Permissions

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