alistairsam
Senior Member
Hi,
looking through the I2C tutorial, its mentioned that "all data transfer from the mast to slave is a write, and from slave to the master is read".
but going by the manual, is the reverse possible? that is can the master read values from the slave?
if I'm using two 20X2 and no external EEPROM, can the bus speed be set to i2cfast (400KHz)
below will be the code for the slave chip which just counts and stores the position. the master chip will periodically read the position and calculate the offset and final position, then display, possibly just twice or thrice a second.
looking through the I2C tutorial, its mentioned that "all data transfer from the mast to slave is a write, and from slave to the master is read".
but going by the manual, is the reverse possible? that is can the master read values from the slave?
if I'm using two 20X2 and no external EEPROM, can the bus speed be set to i2cfast (400KHz)
below will be the code for the slave chip which just counts and stores the position. the master chip will periodically read the position and calculate the offset and final position, then display, possibly just twice or thrice a second.
Code:
'Slave Picaxe for counting pulses
setfreq m64
#picaxe 20X2
hi2csetup i2cslave, %10100000
Symbol enccount = w0
Symbol steps = w1
enccount = 16100 'enter max encoder pulses
HIntSetup %00100010
Gosub Interrupt_Enable
Do
Put 1, w0
Loop
incr:
hInt1Flag = 0
hInt2Flag = 0
SetIntFlags %00000010, %00000010
if steps = enccount then let steps = 0
endif
steps = steps + 1
goto interrupt_enable
decr:
hInt1Flag = 0
hInt2Flag = 0
SetIntFlags %00000010, %00000010
steps = steps - 1
if steps = 0 then let steps = enccount
endif
goto interrupt_enable
Interrupt_Enable:
SetIntFlags %00000010, %00000010
Return
Interrupt:
if pinB.1=1 then goto Incr
if pinB.1=0 then goto Decr