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




Bookmarks