BeastFromTheEast
New Member
I am having problems with the latest addition to my PICAXE collection. It is a 20X2 which is slaved to a larger 40X2 as part of my milling machine project: it will be programmed to count incoming encoder pulses from 3 DC motors (which are bolted to my milling machine). The motors are controlled by the 40X2: I didn't think a single PICAXE could do everything without missing the odd incoming pulse and getting out of sync. To retrieve the positions the 40X2 will read the 20X2 like it is a 128 byte EEPROM.
At least that's the theory: practise is another matter entirely.
40X2 code. This is based on one of the examples and sends a byte to memory location 100 within the 20X2. It then pauses, reads it back again and places it in B2, before incrementing B1. The Debug window shows that this works as expected (i.e. the i2C interface / memory in the target 20X2 are both sound)
20X2 Code. Again this is based on one of the examples: whenever an incoming i2C transmission is detected, the code under main is fired to cycle through the 128 memory bytes and outputs the results to the serial terminal.
PICAXE manual 2 states (page 153) that locations 0-55 are the same as the variables b0 to b55, and I was expecting the incoming byte from the 40X2 to appear in memory location 100.
However all the memory locations in the 20X2 read zero. I was expecting to see some data, even if it was garbaged: but no, all I get is 128 consecutive zeroes.
I have been working on this most of today and am baffled: would appreciate any help.
Ian
At least that's the theory: practise is another matter entirely.
40X2 code. This is based on one of the examples and sends a byte to memory location 100 within the 20X2. It then pauses, reads it back again and places it in B2, before incrementing B1. The Debug window shows that this works as expected (i.e. the i2C interface / memory in the target 20X2 are both sound)
Code:
setfreq m16
i2cslave %10100000, i2cslow, i2cbyte
main: writei2c 100, (b0) ; Write data to eeprom
pause 50 ; Wait for write to complete
readi2c 100, (b1) ; Read data from eeprom
debug ; Show result
pause 100 ; Wait a short while
b0 = b0 + 1 ; Increment the data to write
goto main ; And repeat
Code:
setfreq m64
hi2csetup i2cslave, %10100000
b0=0
PAUSE 5000
main:
if hi2cflag = 0 then main ; poll flag, else loop
hi2cflag = 0 ; reset flag
peek b0,b2
sertxd (#b0," ",#b2,13,10) ; transmit to serial terminal
inc b0
if b0>126 then
b0=0
endif
goto main
However all the memory locations in the 20X2 read zero. I was expecting to see some data, even if it was garbaged: but no, all I get is 128 consecutive zeroes.
I have been working on this most of today and am baffled: would appreciate any help.
Ian