I2C CONFUSION, Help needed please - Page 2


Closed Thread
Page 2 of 2 FirstFirst 12
Results 41 to 43 of 43
  1. #41
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Soooooo Close

    16F688 can go up to 8MHz on internal oscillator.

    I'd try that before changing PIC.

    Robert

  2. #42
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    I put a test circuit together on my LAB-X4 using the PIC16F688 to talk to a 128kB FRAM.
    I could feel your pain when trying to make your test program work so decided to start from almost scratch.
    The TRIS statements were missing some bit assignments which are not a good thing, from what I read somewhere here by Henrik Olssen, so I put them in.
    The order of CONFIG's and other setups were rearranged as well. Not really sure which fixed it but,

    The end results were that it works at 4MHz and here's the program to compare with.
    Code:
    '
    ' This setup uses a PIC16F688 and a FM24V01, 128kB Nonvolatile RAM to test
    ' the I2CREAD/WRITE functions at 4MHz.
    ' 
    ' First: The FRAM memory is loaded with values 1~5 starting from 
    ' location 0 using Word size address. The values written are sequentially
    ' loaded into the next memory location, so only the starting address is 
    ' needed for this test.
    ' Read address = $A0
    ' Write address = $A1
    '
    ' Second: The FRAM memory locations 0 thru 4 are READ in a loop then stops
    ' and waits the Test button on the LAB-4X to be pushed and repeats.
    '
    ' The data was monitored with the Saleae Logic scope.
    ' Max clock speed measured at 4Mhz was 29kHz
    '
    ' The DEBUG function was not used during this test
    '****************************************************************
    
    #CONFIG
    ifdef PM_USED
    device pic16F688, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
    else
    __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF
    endif
    #ENDCONFIG
    
    '-----------------------------------------------------
    PORTA=0
    PORTC=0
    TRISA = %00001000   ' All 8 bits assigned one way or the other
    TRISC = %00000000   ' All 8 bits assigned one way or the other
    CMCON0 = 7
    ANSEL = 0
    OPTION_REG = 128    ' PORTA pullups disabled
    INTCON=128
    OSCCON = %01100001  ' Oscillator set to 4MHz
    
    DEFINE DEBUG_REG PORTC
    DEFINE DEBUG_BIT 3
    DEFINE DEBUG_BAUD 2400
    DEFINE DEBUG_MODE 1
    DEFINE OSC 4
    Include "modedefs.bas"
     
    '-----------------------------------------------------------
    Value       VAR BYTE
    WR_Addr     VAR BYTE
    RD_Addr     VAR BYTE
    LOC         VAR WORD    ' FRAM address must be sent as Word size
    x           VAR BYTE
    '------------------------------------------------------------
    SCL     VAR PORTA.4     ' RA4, pin #3
    SDA     VAR PORTA.5     ' RA5, pin #2
    Change  VAR PORTA.3     ' Push button on LAB-X4
    LED     VAR PORTA.0     ' Test LED. LOW = ON
    '------------------------------------------------------------
    LOC = 0             ' Start at 0
    LED = 1             ' Turn LED OFF
    PAUSE 1000          ' Give me a chance to start the monitor
    
    GOSUB Load_Mem      ' Load FRAM memory locations 0~4 with values 1~5 
    
    Main:   
        FOR LOC = 0 TO 4
            LED = 0     ' Turn ON LED, scope monitored 
            I2CWRITE SDA,SCL,$A0,[LOC],Fail1
            PAUSEUS 25  ' Paused to see on display
            I2CREAD SDA,SCL,$A1,[VALUE],Fail2
            PAUSEUS 500 ' Paused to seperate packets, viewing purpose only
            LED =1      ' Turn OFF LED
        NEXT LOC
    
    WHILE CHange: WEND  ' Wait until button pushed
    PAUSE 500           ' Cheap debounce
    GOTO Main
    
    '----------------------- Fail routines -------------------------------
    
    Fail1:					' Try Write again
    	FOR x=0 to 50
    		LOW LED : PAUSE 50 : HIGH LED : PAUSE 50
    	Next x
    GOTO Main
    
    Fail2:					' Try read again
    	For x=0 to 5
    		LOW LED : PAUSE 250 : HIGH LED : PAUSE 250
    	Next x
    GOTO Main
    
    '---------------------- Load FRAM --------------------------------------
    
    Load_Mem:
        LED = 0     ' Turn ON LED, scope monitored 
        I2CWRITE SDA,SCL,$A0,[LOC,1,2,3,4,5],Fail1
        LED = 1     ' Turn OFF LED
    RETURN    
            
    END

    This first screenshot is from:
    Code:
    Load_Mem:
        LED = 0     ' Turn ON LED, scope monitored 
        I2CWRITE SDA,SCL,$A0,[LOC,1,2,3,4,5],Fail1
        LED = 1     ' Turn OFF LED
    RETURN
    The 2nd and 3rd from the first and last loop Reads showing the values 1 and 5 after the $A1 READ address.
    Attached Images Attached Images    
    Louie

  3. #43
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default ADDICTION, Help needed please

    Okay decided to try the Debug and got fancy while I was at it. This can be addicting!

    Here's the updated code...
    Code:
    '
    ' This setup uses a PIC16F688 and a FM24V01, 128kB Nonvolatile RAM to test
    ' the I2CREAD/WRITE functions at 4MHz.
    ' 
    ' First: The FRAM memory is loaded with values 1~5 starting from 
    ' location 0 using Word size address. The values written are sequentially
    ' loaded into the next memory location, so only the starting address is 
    ' needed for this test.
    ' Read address = $A0
    ' Write address = $A1
    '
    ' Second: The FRAM memory locations 0 thru 4 are READ in a loop then stops
    ' and waits the Test button on the LAB-4X to be pushed and repeats.
    '
    ' The data was monitored with the Saleae Logic scope.
    ' Max clock speed measured at 4Mhz was 29kHz
    '
    ' The DEBUG function was used this time.
    '****************************************************************
    
    #CONFIG
    ifdef PM_USED
    device pic16F688, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
    else
    __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF
    endif
    #ENDCONFIG
    
    '-----------------------------------------------------
    PORTA=0
    PORTC=0
    TRISA = %00001000   ' All 8 bits assigned one way or the other
    TRISC = %00000000   ' All 8 bits assigned one way or the other
    CMCON0 = 7
    ANSEL = 0
    OPTION_REG = 128    ' PORTA pullups disabled
    INTCON=128
    OSCCON = %01100001  ' Oscillator set to 4MHz
    
    DEFINE DEBUG_REG PORTC
    DEFINE DEBUG_BIT 3
    DEFINE DEBUG_BAUD 19200
    DEFINE DEBUG_MODE 1
    DEFINE OSC 4
    Include "modedefs.bas"
     
    '-----------------------------------------------------------
    Manf        VAR BYTE[3]
    Value       VAR BYTE
    LOC         VAR WORD    ' FRAM address must be sent as Word size
    x           VAR BYTE
    '------------------------------------------------------------
    SCL     VAR PORTA.4     ' RA4, pin #3
    SDA     VAR PORTA.5     ' RA5, pin #2
    Change  VAR PORTA.3     ' Push button on LAB-X4
    LED     VAR PORTA.0     ' Test LED. LOW = ON
    '------------------------------------------------------------
    LOC = 0             ' Start at 0
    LED = 1             ' Turn LED OFF
    PAUSE 1000          ' Give me a chance to start the monitor
    
    GOSUB Load_Mem      ' Load FRAM memory locations 0~4 with values 1~5 
    
    Main:   
        FOR LOC = 0 TO 4
            LED = 0     ' Turn ON LED, scope monitored 
            I2CWRITE SDA,SCL,$A0,[LOC],Fail1
            PAUSEUS 25  ' Paused to see on display
            I2CREAD SDA,SCL,$A1,[VALUE],Fail2
            DEBUG "LOC = ", DEC LOC,", ","Value = ", DEC Value,13,10
            LED =1      ' Turn OFF LED
        NEXT LOC
        
        DEBUG 13,10 ' Add a space between readings
        
    '   Send Reserved Slave ID $F8 and address
        I2CWRITE SDA,SCL,$F8,[$A1],Fail1
        PAUSEUS 25  ' Paused to see on display
    
    '   Send Reserved Slave ID $F9 and address then read in 3 bytes   
        I2CREAD SDA,SCL,$F9,$A1,[Manf[0], Manf[1], Manf[2]],Fail2
        
    '   Debug Manufacture and Product ID. This FRAM = 00x41x00
        DEBUG "Manf, & Product ID = ",HEX2 Manf[0],",",HEX2 Manf[1],",",_
        HEX2 Manf[2],13,10,13,10
        
    WHILE CHange: WEND  ' Wait until button pushed
    PAUSE 500           ' Cheap debounce
    GOTO Main
    
    '----------------------- Fail routines -------------------------------
    
    Fail1:					' Try Write again
    	FOR x=0 to 50
    		LOW LED : PAUSE 50 : HIGH LED : PAUSE 50
    	Next x
    GOTO Main
    
    Fail2:					' Try read again
    	For x=0 to 5
    		LOW LED : PAUSE 250 : HIGH LED : PAUSE 250
    	Next x
    GOTO Main
    
    '---------------------- Load FRAM --------------------------------------
    
    Load_Mem:
        LED = 0     ' Turn ON LED, scope monitored 
        I2CWRITE SDA,SCL,$A0,[LOC,1,2,3,4,5],Fail1
        LED = 1     ' Turn OFF LED
    RETURN    
            
    END
    Now the Debug at 19.2k..
    Name:  Debugged I2C.jpg
Views: 228
Size:  31.4 KB
    Louie

Similar Threads

  1. Sample code for I2C text LCD needed
    By Alexey in forum Code Examples
    Replies: 4
    Last Post: - 15th September 2011, 01:29
  2. TMR0 Confusion
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 19th August 2011, 11:55
  3. HPWM confusion
    By lerameur in forum General
    Replies: 12
    Last Post: - 5th November 2006, 10:09
  4. HPWM confusion
    By rossfree in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd November 2005, 16:50
  5. DIV32 confusion
    By dmairspotter in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th October 2005, 21:24

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