My first post searching help


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2016
    Posts
    60

    Default My first post searching help

    I having issues in connecting a small oled display purchesed from Adafruit. All the example they have are based on arduino library! The two example code I found in this forum do not work. It is a whole week I am trying to have this little thing to work without any luck. So I decided to check wich is the true address of the device I am wrking on (documentation I found says $3c; $3d ; $78 ; $7A and more) I did check all of them without any luck.
    The code below is supposed to be an I2C address scanner but I am lost on how to detect the ACKNOWLEDGMENT of the device any suggestion or advice?

    Code:
    
     ;----[16F88 Hardware Configuration]---------------------------------------------
    #IF __PROCESSOR__ = "16F88"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg1 = _INTRC_IO              ; INTRC oscillator; port I/O function on both RA6/OSC2/CLKO pin and RA7/OSC1/CLKI pin
    cfg1&= _WDT_OFF               ; WDT disabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLR_ON               ; RA5/MCLR/VPP pin function is MCLR
    cfg1&= _BODEN_OFF             ; BOR disabled
    cfg1&= _LVP_OFF               ; RB3 is digital I/O, HV on MCLR must be used for programming
    cfg1&= _CPD_OFF               ; Code protection off
    cfg1&= _WRT_PROTECT_OFF       ; Write protection off
    cfg1&= _DEBUG_OFF             ; In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
    cfg1&= _CCP1_RB0              ; CCP1 function on RB0
    cfg1&= _CP_OFF                ; Code protection off
      __CONFIG _CONFIG1, cfg1
    
    
    cfg2 = _FCMEN_ON              ; Fail-Safe Clock Monitor enabled
    cfg2&= _IESO_ON               ; Internal External Switchover mode enabled
      __CONFIG _CONFIG2, cfg2
    
    
    #ENDCONFIG
    
    
    #ENDIF
    
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    LED                 var PortB.3
    
    
    I2C_Dev             var byte
    SCL                 var PortA.3                     ' I2C Clock  PortA.3
    SDA                 var PortA.2                     ' I2C Data   PortA.2
    
    
    False               con 0
    True                con 1
    
    
    Flag_ack            var bit
    I                   VAR BYTE
    DC                  var byte
    say                 var byte                        
    
    
    DEFINE HSER_RCSTA 90h                               ' En. s.port & cont receive
    DEFINE HSER_TXSTA 20h                               ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 12                                ' 9600 Baud @ 32MHz, 0,16%
    DEFINE HSER_CLROERR 1                               ' Clear overflow automatically
    '==============================================================================
    
    
    Hserout  ["System ready"]
    
    
    For I = 1 to 10
    Led = !Led
    pause 100
    next I
    
    
    hserout ["Address scannining in progress..."]
    
    
    for I = $08 to $77 step 2
    I2CWrite SDA,SCL,I2C_Dev,[DC]  
    If Flag_Ack = true then say = I       
    pause 2000
    Led = !Led
    Next I
    
    
    hserout ["Address found = ",dec say]
    
    
    end
    Thank you for the attention

    Alberto

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: My first post searching help

    hserout ["Address scannining in progress..."]


    for I = $08 to $77 step 2
    I2CWrite SDA,SCL,I2C_Dev,[DC] ;Address scannining in progress.. yet you never change the address,, DC is used but never initialised
    If Flag_Ack = true then say = I ; how would Flag_Ack ever change
    pause 2000
    Led = !Led
    Next I


    hserout ["Address found = ",dec say]


    ps
    internal pbp regbit FLAGS.5 may act like you want Flag_Ack to , but its undocumented and may not be totally reliable





    try this


    Code:
    dc=0
    hserout ["Address scannining in progress..."]
    for I = $02 to $fe step 2
        I2CWrite SDA,I,[DC],nak  
        hserout ["Address found = ",hex2 I ,13,10]
        nak:
    Next I
    Last edited by richard; - 24th June 2016 at 12:47.
    Warning I'm not a teacher

  3. #3
    Join Date
    Jun 2016
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: My first post searching help

    Thank you Richard for the preciuos suggestions! the program now works, tested with a working device, while is giving "Address not found!" with the oled display. At least now I know that the display is faulty and I have to order a couple of new ones if I want to finish my project.

    I post the final working code for other that fighting with I2C divices could find it useful.

    Code:
     ;----[16F88 Hardware Configuration]---------------------------------------------
    #IF __PROCESSOR__ = "16F88"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg1 = _INTRC_IO              ; INTRC oscillator; port I/O function on both RA6/OSC2/CLKO pin and RA7/OSC1/CLKI pin
    cfg1&= _WDT_OFF               ; WDT disabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLR_ON               ; RA5/MCLR/VPP pin function is MCLR
    cfg1&= _BODEN_OFF             ; BOR disabled
    cfg1&= _LVP_OFF               ; RB3 is digital I/O, HV on MCLR must be used for programming
    cfg1&= _CPD_OFF               ; Code protection off
    cfg1&= _WRT_PROTECT_OFF       ; Write protection off
    cfg1&= _DEBUG_OFF             ; In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
    cfg1&= _CCP1_RB0              ; CCP1 function on RB0
    cfg1&= _CP_OFF                ; Code protection off
      __CONFIG _CONFIG1, cfg1
    
    cfg2 = _FCMEN_ON              ; Fail-Safe Clock Monitor enabled
    cfg2&= _IESO_ON               ; Internal External Switchover mode enabled
      __CONFIG _CONFIG2, cfg2
    
    #ENDCONFIG
    
    #ENDIF
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    
    DEFINE OSC 8                        ' define fosc
    define I2C_HOLD 1                   ' define I2C type 
    
        TrisB = %00000100               ' Set all port B pins as outputs
        TrisA = %00001100               ' Set portA.2 & portA.3 as inputs
        CMCON = 7                       ' Turn Off Comparators
        ADCON1 = 7                      ' Disable A/D converter    
        ANSEL = %00000000               ' set all analog pins to digital
        OSCCON = %01110000              ' Set PIC16F88 to 8 MHz = %01110000       
    
    LED                 var PortB.3
    
    I2C_Dev             var byte
    SCL                 var PortA.3                     ' I2C Clock  PortA.3
    SDA                 var PortA.2                     ' I2C Data   PortA.2
    
    False               con 0
    True                con 1
    
    Flag_ack            var bit
    I                   VAR BYTE
    DC                  var byte
    say                 var byte 
      
                 
    
    DEFINE HSER_RCSTA 90h                               ' En. s.port & cont receive
    DEFINE HSER_TXSTA 20h                               ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 12                                ' 9600 Baud @ 32MHz, 0,16%
    DEFINE HSER_CLROERR 1                               ' Clear overflow automatically
    '==============================================================================
    Pause 10
    Hserout  [13,10]
    pause 10
    Hserout  ["System ready",13,10]
    
    For I = 1 to 10
    Led = !Led
    pause 100
    next I
    
    DC = 0
    Flag_ack = false
    
    hserout ["Address scannining in progress...",13,10]
    
    for I = $08 to $77 step 2
    I2CWrite SDA,SCL,I,[DC],NAK  
    hserout ["Address found = ",hex2 I]
    Flag_Ack = true       
    NAK:
    pause 1000
    Led = !Led
    Next I
    
    If Flag_ack = false then hserout ["Address not found!",13,10]
    
    hserout ["Address scannining completed!",13,10]
    
    Led = False
    end
    Last edited by Alberto; - 24th June 2016 at 16:05.

  4. #4
    Join Date
    Jun 2016
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: My first post searching help

    I discover that $77 doesn't cover all devices addresses, since the scanning was unable to detect the address of a PCF8583, so exstending the scanning to $AA I got the address of this clock/calendar device.

    Code:
    for I = $08 to $AA step 2
    Alberto

Similar Threads

  1. Searching within array's
    By timmers in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th May 2012, 09:21
  2. Fix for preview post -> real post.
    By HenrikOlsson in forum Forum Requests
    Replies: 8
    Last Post: - 26th August 2011, 17:34
  3. Searching for a post
    By Nicmus in forum General
    Replies: 5
    Last Post: - 28th October 2008, 23:29
  4. searching for three letter words...
    By paxmowa in forum Forum Requests
    Replies: 4
    Last Post: - 12th September 2007, 17:06
  5. HSERIN command - Still searching for answers
    By electronicsuk in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 26th December 2003, 09:28

Members who have read this thread : 1

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