Raspberry Pi And PICAXE using i2c

GreatWhiteNorth

New Member
I've also been trying to get a 20X2 to function as an i2c slave for the Raspberry Pi. I took Hippy's suggestion, and started with a 24LC16 EEPROM. With the 24LC16 set up at i2c address 0x50, the following Pi program correctly writes (and reads back) a series of values to and from EEPROM locations 0 through 4. (I'm using the pi smbus library, so my commands are slightly different from what Phil used.)

Code:
[FONT=Courier]from smbus import SMBus[/FONT]
[FONT=Courier]import time[/FONT]

[FONT=Courier]bus = SMBus(1)       #for pi rev 2[/FONT]
[FONT=Courier]adr = 0x50[/FONT]

[FONT=Courier]for loc in range 5:[/FONT]
[FONT=Courier]    data = loc + 65[/FONT]
[FONT=Courier]    bus.write_byte_data(adr,loc,data)[/FONT]
[FONT=Courier]    time.sleep(.01)[/FONT]
[FONT=Courier]    ch = bus.read_byte_data(adr,loc)[/FONT]
[FONT=Courier]    print ch[/FONT]
When I replace the EEPROM with a 20x2 (also set up at i2c address 0x50), the pi doesn't report any error, but the values are consistently read back as 0.

The 20X2 program just sets up the i2c slave, blinks an LED on pin C.0, and then sends the contents of scratchpad locs 0 through 4 to the terminal. To avoid the possibility that the 20X2 is executing the "get" command at the same time the pi is writing to or reading from the i2c bus, I run the pi program during the beginning of the 5 second delay in the 20X2 program.

The following 20X2 code confirms the pi output - the 5 scratchpad locations always contain 0, so the pi doesn't seem to be writing the i2c data at all.

Code:
[FONT=Courier]hi2csetup i2cslave, %10100000[/FONT]

[FONT=Courier]do[/FONT]
[FONT=Courier]  high C.0[/FONT]
[FONT=Courier]  pause 250[/FONT]
[FONT=Courier]  low C.0[/FONT]
[FONT=Courier]  wait 5 'pi writes data at this point[/FONT]
[FONT=Courier]  get 0,b0,b1,b2,b3,b4[/FONT]
[FONT=Courier]  sertxd (#b0,#b1,#b2,#b3,#b4,cr,lf)[/FONT]
[FONT=Courier]loop[/FONT]
If anyone can see where I'm going wrong, I would really appreciate the help!

Thanks… Ron
 
Top