WP is connected to ground. Same as all address pins of the eeprom.
WP is connected to ground. Same as all address pins of the eeprom.
Then I'd suggest backing up a bit...
Get uncomplicated...
Write some code to just write a few values to the eeprom and read them back to verify what was written...THEN write the code you actually want to use...'cause I see a few flaws in your logic in the code written a few posts back.
Thanks skimask,
Good idea. Will do that tonight and post the results
.
Just finished assembling a small code and still cannot work with the eeprom
this is the code i used :
The value returned for both addresses is 257Code:'**************************************************************** '**************************************************************** SSPCON.5 = 0 ; Disable SSP Module TXSTA.5 = 0 ; Disable AUSART Tx RCSTA.7 = 0 ; Disable Serial Port OSCCON = %01111110 'Internal RC w/ I/Os INTCON=0 PIE1 = 0 'PIE2 = 0 PIR1 = 0 'off CMCON= 7 'COMPARATOR OFF CVRCON= 0 'Vref Off CCP1CON= 0 T1CON= 0 'T2CON = %00000100 osctune=0 '***************************************************************************** 'DEFINEs '***************************************************************************** @ DEVICE INTRC_OSC @ DEVICE MCLR_OFF @ DEVICE PROTECT_OFF DEFINE osc 8 @ DEVICE CPD_OFF @ DEVICE LVP_OFF @ DEVICE BOD_OFF @ DEVICE PWRT_OFF @ DEVICE WDT_OFF '***************************************************************************** '***************************************************************************** 'ADC parameters ADCON1 =%10000000 'right justify ANSEL =%00000001 'PORTA.0 ANALOG ADCON0 =%11000001 '***************************************************************************** INCLUDE "modedefs.bas" 'settings for serial comm DEFINE debug_reg PORTB DEFINE debug_bit 7 DEFINE debug_baud 9600 DEFINE debug_mode 1 '***************************************************************************** 'I/O's PORTA=0 PORTB=0 TRISA=%00000001 'PORTA.0 AS INPUT TRISB=%00000111 'SDA,SCL AND BUT1 AS INPUTS '***************************************************************************** 'PINS A0 var PORTA.0 a1 var PORTA.1 A2 var PORTA.2 A3 var PORTA.3 A4 var PORTA.4 MCLR var PORTA.5 a6 var PORTA.6 a7 var PORTA.7 SDA var PORTB.0 'I2C DATA PIN SCL var PORTB.1 'I2C CLOCK PIN but1 var PORTB.2 'BUTTON FOR LOOP b3 var PORTB.3 B4 var PORTB.4 B5 var PORTB.5 B6 var PORTB.6 out var PORTB.7 '***************************************************************************** ' variables mem var byte ADDR var word m1 var word m2 var word CTW VAR WORD '***************************************************************************** CTW=$A0 m1=0 m2=0 '***************************************************************************** start: I2CREAD SDA,SCL,CTW,$1,[m1] pause 10 debug " value IN EEPROM address 1 = ",dec m1,13,10 I2CREAD SDA,SCL,CTW,$10,[m2] pause 10 debug " value IN EEPROM address 10 = ",dec m2,13,10 I2CWRITE SDA,SCL,CTW,$1,[5] PAUSE 10 debug " WROTE 5 at address 1 = ",13,10 I2CWRITE SDA,SCL,CTW,$10,[6] PAUSE 10 debug " WROTE 6 at address 10 = ",13,10 loop: if but1=1 then goto start else goto loop endif end
Just as a note, with the first code ( showned in post #4 ) the returned value was always 8 ( for any address ) and 0 when removing the pullups.
EDIT:
Changed the lines:
I2CWRITE SDA,SCL,CTW,$1,[5]
to
ADDR=$1
I2CWRITE SDA,SCL,CTW,ADDR,[5]
( as seen in Melanie's post about I2C )
http://www.picbasic.co.uk/forum/showthread.php?t=587
but the return value is the same![]()
Last edited by ruijc; - 20th February 2008 at 22:30.
OR un-COLONized...Code:DEFINE OSC 8 INCLUDE "modedefs.bas" @ DEVICE INTRC_OSC @ DEVICE MCLR_OFF @ DEVICE PROTECT_OFF @ DEVICE CPD_OFF @ DEVICE LVP_OFF @ DEVICE BOD_OFF @ DEVICE PWRT_OFF @ DEVICE WDT_OFF DEFINE DEBUG_REG PORTB DEFINE DEBUG_BIT 7 DEFINE DEBUG_BAUD 9600 DEFINE DEBUG_MODE 1 osccon=$7e:cmcon=7:adcon1=$80:ansel=1:adcon0=$c1:porta=0:portb=0:trisa=1 trisb=7:sda var portb.0:scl var portb.1:addr var word:dat var byte dat2 var byte:ctw con $a0 start: dat=dat+1:addr=addr+1 i2cwrite sda,scl,ctw,addr.highbyte,addr.lowbyte,[dat]:pause 10 debug "Wrote: ",dec addr," with ",dec dat,13,10 i2cread sda,scl,ctw,addr.highbyte,addr.lowbyte,[dat2] debug " Read: ",dec addr," val: ",dec dat2 , 13 , 10 if dat = dat2 then debug "Write/Read Successful at ",dec5 addr," with ",dec3 dat,13,10 else debug "Write/Read Error at ",dec5 addr,"-Wrote:",dec3 dat," - Read:",dec dat2,13,10 endif pause 500:goto start END
Code:DEFINE OSC 8 INCLUDE "modedefs.bas" @ DEVICE INTRC_OSC @ DEVICE MCLR_OFF @ DEVICE PROTECT_OFF @ DEVICE CPD_OFF @ DEVICE LVP_OFF @ DEVICE BOD_OFF @ DEVICE PWRT_OFF @ DEVICE WDT_OFF DEFINE DEBUG_REG PORTB DEFINE DEBUG_BIT 7 DEFINE DEBUG_BAUD 9600 DEFINE DEBUG_MODE 1 osccon = $7e cmcon = 7 adcon1 = $80 ansel = 1 adcon0 = $c1 porta = 0 portb = 0 trisa = 1 trisb = 7 sda var portb.0 scl var portb.1 addr var word dat var byte dat2 var byte ctw con $a0 start: dat = dat + 1 addr = addr + 1 i2cwrite sda , scl , ctw , addr.highbyte , addr.lowbyte , [ dat ] pause 10 debug "Wrote: " , dec5 addr , " with " , dec3 dat , 13 , 10 i2cread sda , scl , ctw , addr.highbyte , addr.lowbyte , [ dat2 ] debug " Read: " , dec5 addr , " val: " , dec3 dat2 , 13 , 10 if dat = dat2 then debug "Write/Read Successful at " , dec5 addr , " with " , dec3 dat , 13 , 10 else debug "Write/Read Error at " , dec5 addr , "-Wrote:" , dec3 dat , " - Read:" , dec dat2 , 13 , 10 endif pause 500 goto start END
Last edited by skimask; - 20th February 2008 at 23:42.
Hi skimask,
i'm pleased to say that your code worked. Thank you very much for your help
Will re-write my entire code from scratch.
I have some notes here and i will see what happens.
.
Bookmarks