pic basic i2c bus does not work


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2008
    Posts
    10

    Default pic basic i2c bus does not work

    Originally Posted by tamertokgoz
    'I try to use sda scl fmc24c512 and pcf8583 on the sda scl line
    'but could not read anythıng from eeprom when I push the
    'button also the second problem is the lcd shows abnormal
    'hour minute day v.s sometimes and shows what it has to
    'be sometimes could you help me
    'fm24c512 has a2 on chasis a1 and a0 on 5 volt connecttion with 4.7k thanks for help
    Code:
      
    DEFINE LCD_DREG PORTB 
    DEFINE LCD_DBIT 4 
    DEFINE LCD_RSREG PORTB 
    DEFINE LCD_RSBIT 2 
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 3 
    DEFINE ADC_BITS 100 
    DEFINE ADC_CLOCK 3 
    DEFINE ADC_SAMPLEUS 50 
    
    
    
    
    SDA var PORTC.4
    SCL var PORTC.3
    BTN1 VAR PORTD.0 ' BUTON 1 
    
    symbol So = PORTE.0 ' Serial output pin
    symbol capture = PIR1.2 ' CCP1 capture flag
    symbol overflow = PIR1.0 ' Timer1 overflow flag
    
    TRISA = %11111111 
    TRISB = %00000001 
    ADCON1 = %10000010 
    
    ADD VAR WORD
    ADDO VAR WORD
    FX VAR WORD
    
    f2 var word 
    VOLT VAR WORD 
    AMPER VAR WORD
    y var word
    F1 VAR WORD
    per var word
    
    fre var word
    MS VAR WORD
    period VAR WORD ' Word variable that stores the value
    
    sec var byte
    mnt var byte
    hour var byte
    day var byte
    month var byte
    year var byte
    
    CCP1CON = %00000100 ' Enable the CCP1 capture, falling edge
    T1CON = %00000001 ' TMR1 prescale=1, and turn it on (1uS per count)
    
    BOOT:
    LCDOut $fe, 1 
    
    LCDOut "  "
    
    LCDOut $fe,$c0," "
    pause 6
    ADD =10
    
    loop: 
    IF (capture = 0) Then loop ' Wait here until captured 
    
    period.lowbyte = CCPR1L ' Store the captured value in
    period.highbyte = CCPR1H ' period variable
    
    IF overflow = 0 Then ' Skip the output if the timer overflowed
    ' So=period
    goto adcloop
    EndIF
    
    capture = 0 ' Clear the capture flag
    reset:
    
    IF (capture = 0) Then reset ' Wait for beginning of next period
    
    TMR1L = 0 ' Clear Timer1 low register
    TMR1H = 0 ' Clear Timer1 high register
    capture = 0 ' Clear capture flag
    overflow = 0 ' Clear overflow flag
    
    
    
    goto loop
    
    
    
    ADCLOOP: 
    ADCIN 0, VOLT 
    PAUSE 40
    ADCIN 1, AMPER
    amper = (amper */ 15)>>2 
    
    
    
    i2cread SDA,scl,%10100000,2,[sec,mnt,hour,day,month]
    CKP =1
    year.3 = 1
    year.2 = 0
    year.1 = day.6
    year.0 = day.7
    
    month.5 =0
    month.6 =0
    month.7 =0
    'day.5 =0
    day.6 =0
    day.7 =0
    
    pause 25 
    f1 = period / 100
    f1 = 10000 / f1
    y = 10000/ f1
    y = y*100
    if y > period then 
    f2 =">"
    else
    f2 ="<"
    endif
    
    
    
    LCDOut $fe, 1 
    Lcdout hex2(hour),hex2(mnt),hex2(Sec), "-", hex2(day),".", hex2(month),"." , hex2(year)
    
    LCDOut $fe,$c0,"V="
    Lcdout dec VOLT
    
    lcdout " I=" 
    Lcdout dec AMPER
    LCDOut " F"
    Lcdout F2,"=",dec F1
    ADD = ADD +1 
    I2CWRITE SDA,SCL,$A6,ADD,[ADD],BOGUS
    PAUSE 50 
    IF BTN1 THEN OKU 
    GoTo loop ' Do it forever 
    OKU : 
    FOR ADDO =10 TO ADD
    I2CREAD SDA,SCL,$A7,ADDO,[FX],BOGUS
    PAUSE 25
    SEROUT2 So,84,[DEC ADDO ,"--", DEC(FX), 13,10]
    PAUSE 50
    
    NEXT
    GOTO LOOP
    bogus:
    LCDOut $fe,1, "timed out" ' I2C command timed out
    Pause 1000
    RETURN 
    
    
    End
    Last edited by tamertokgoz; - 11th June 2008 at 22:22. Reason: code tag used

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


    Did you find this post helpful? Yes | No

    Default

    This is absolutely imperative you told us which PIC you're using and at which frequency you run it.

    I don't see any Config fuses setting either.

    Schematic is more than welcome.
    Steve

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

  3. #3
    Join Date
    May 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default pic basic i2c bus does not work

    Quote Originally Posted by mister_e View Post
    This is absolutely imperative you told us which PIC you're using and at which frequency you run it.

    I don't see any Config fuses setting either.

    Schematic is more than welcome.
    pic 16f687
    Attached Images Attached Images  
    Last edited by tamertokgoz; - 11th June 2008 at 22:06.

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


    Did you find this post helpful? Yes | No

    Default

    Check your datasheet for ANSEL and ANSELH register settings.

    As you have it now, you have some digital vouched use... but... on analog configured pins.

    WOW ISIS...
    Last edited by mister_e; - 11th June 2008 at 22:13.
    Steve

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

  5. #5
    Join Date
    May 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default it also does not any help

    Quote Originally Posted by mister_e View Post
    Check your datasheet for ANSEL and ANSELH register settings.

    As you have it now, you have some digital vouched use... but... on analog configured pins.

    WOW ISIS...
    it also does not any help

Similar Threads

  1. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  2. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33
  3. I want to buy PIC BASIC PRO...
    By simransingh in forum General
    Replies: 2
    Last Post: - 30th October 2007, 17:13
  4. USB Pics, ICD2, pic basic pro
    By vacpress in forum USB
    Replies: 34
    Last Post: - 20th January 2007, 20:50
  5. How to use 93C46 Type EEPROM using PIC Basic PRo
    By in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st April 2003, 04:07

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