eeprom read working as it should
authorDarron Broad <darron@kewl.org>
Tue, 03 Feb 2015 17:43:01 +0000
changeset 12 58216cc75bdf
parent 11 313d83f016b8
child 13 27e8f05e8ffc
eeprom read working as it should

./i2c.esp
> > > > > > > >> >> >> >> >> >> >> >> >> >> >> > > > > 238

printf "%x\n" 238
ee

see: http://wiki.kewl.org/dokuwiki/projects:esp#lc512
i2c.esp
--- a/i2c.esp	Tue Feb 03 17:08:55 2015 +0000
+++ b/i2c.esp	Tue Feb 03 17:43:01 2015 +0000
@@ -1,7 +1,5 @@
 #!espy /dev/ttyUSB0
 
--- modified demo from https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en
-
 -- pin 3 = GPIO0
 sda=3
 
@@ -12,20 +10,22 @@
 i2c.setup(0,sda,scl,i2c.SLOW)
 
 -- read
-function read_reg(dev_addr, reg_addr)
+function read_eeprom(addrhigh,addrlow)
 	i2c.start(0)
-	i2c.address(0, dev_addr ,i2c.TRANSMITTER)
-	i2c.write(0,reg_addr)
+	i2c.address(0,0x50,i2c.TRANSMITTER)
+	i2c.write(0,addrhigh)
+	i2c.write(0,addrlow)
 	i2c.stop(0)
+
 	i2c.start(0)
-	i2c.address(0, dev_addr,i2c.RECEIVER)
+	i2c.address(0,0x50,i2c.RECEIVER)
 	c=i2c.read(0,1)
 	i2c.stop(0)
 	return c
 end
 
--- do something
-reg = read_reg(0x50, 0x01)
+-- read byte
+reg = read_eeprom(0x00,0x00)
 
--- output
+-- output byte
 print(string.byte(reg))