| Posted: 12:57pm 21 Mar 2022 |
Copy link to clipboard |
 Print this post |
|
I have assembled a PicoMite with an SSD1963 screen and PS2 keyboard. All running well, operating with the SSD1963 in console mode and the touch interface and SD card interfaces are all fine. I have configured I2C on GP20 and GP21 and linked up to a Micromite 170 to add extra outputs. I pasted the following code into the slave Micromite, taken from Geoff's Micromite Getting Started book.
'I2C slave board program - outputs only
OPTION AUTORUN ON
SETPIN 2, DOUT 'Set up test pin and check it is working PIN(2)=0 PAUSE 500 PIN(2)=1 PAUSE 500 PIN(2)=0 DIM msg(2) ' array used to hold the message I2C SLAVE OPEN &H26, 0, 0, WriteD, ReadD ' slave's address is 26(hex)
DO ' the program loops forever WATCHDOG 1000 ' this will recover from errors LOOP
SUB ReadD ' received a message I2C SLAVE READ 3, msg(), recvd ' get the message into the array IF msg(0) = 1 THEN ' command = 1 SETPIN msg(1), msg(2) ' configure the I/O pin ELSEIF msg(0) = 2 THEN ' command = 2 PIN(msg(1)) = msg(2) ' set the I/O pin's output ELSE ' the command must be 3 s$ = STR$(PIN(msg(1))) + SPACE$(12) ' get the input on the I/O pin ENDIF END SUB ' return from the interrupt SUB WriteD ' request from the master I2C SLAVE WRITE 12, s$ ' send the last measurement END SUB ' return from the interrupt
I only want to be switch outputs on and off on the slave, therefore the code running in the PicoMite master;
' I2C Routines on Master to operate pins on a slave MicroMite ' Taken from "Getting Started" SetPin gp20, gp21, i2c I2C open 100,1000
Do SLAVEPIN 2, 1 Print "ON" Pause 2000 SLAVEPIN 2, 0 Print "OFF" Pause 2000 Loop
' set the output of an I/O pin on the slave Sub SLAVEPIN pinnbr, dat
I2C WRITE &H26, 0, 3, 2, pinnbr, dat If MM.I2C Then Error "Slave did not respond"
End Sub
When I run both codes, the master runs okay but the slave reports
[23] I2C SLAVE READ 3, msg(), recvd ' get the message into the array Error : Cannot find RECVD >
Watchdog timeout Processor restarted
What AM I doing wrong? I am sure there is a simple answer but I have been banging my head against this all weekend. |