PIC16F73 with PCF8591


Closed Thread
Results 1 to 2 of 2
  1. #1
    Habasch's Avatar
    Habasch Guest

    Question PIC16F73 with PCF8591

    Hello all,
    a little newbe question:

    Does everybody have a code example how to read data from an PCF8591 A/D converter over the i2c bus.

    I have some problems with that. Always when I start reading with I2CREAD the Watchdog will reset the PIC.

    Here my code:

    ' Switch comperator mode on all ports off
    ADCON1 = %00000111


    ' LCD-Module settings
    DEFINE LCD_DREG PORTA
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTA
    DEFINE LCD-RSBIT 4
    DEFINE LCD_EREG PORTA
    DEFINE LCD_EBIT 5
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 4
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50

    DEFINE I2C_HOLD 0
    DEFINE I2C_SLOW 1

    SCL VAR PORTC.3 ' Clock pin
    SDA VAR PORTC.4 ' Data pin
    SAMPLE VAR BYTE ' Holds data from slave
    CONTROL VAR BYTE
    DEVICE1 VAR BYTE

    CONTROL = %00000000
    DEVICE1 = %10010100

    Pause 100 ' Wait for LCD to start up

    LCDOut $fe, 1, "I2C-TEST" ' Display
    Pause 1000


    loop:
    ' DEVICE 1
    LCDOut $fe, 1, "DEVICE1: "
    I2CRead SDA,SCL,CONTROL,DEVICE1,SAMPLE,timeout
    LCDOUT SAMPLE
    Pause 500

    GoTo loop


    timeout:
    LCDOut $fe, 1
    LCDOut $fe, $80, "timed out"
    Pause 1000

    GoTo loop


    Thanks, Habasch

  2. #2
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Question How do you know that it is a watchdog reset?

    Hi,

    I am curious to know what made you decide that it is a watchdog reset. Did you debug the POR registers.

    PBP drives the lines in an open collector fashion. That is it toggles between input and output. This facilitates the slave to pull down the line for acknowledge. So pull ups are absolutely necessary. Hope you have done it. A schematic post and complete code can be useful.
    Regards

    Sougata

Similar Threads

  1. Noise on PORTC.0 with PIC16F73
    By passion1 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th February 2009, 20:47
  2. ADCIN problems with PIC16F73
    By passion1 in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 26th July 2007, 11:38

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