Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:31 20 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Picomite I2C

Author Message
circuit
Senior Member

Joined: 10/01/2016
Location: United Kingdom
Posts: 292
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 2DOUT '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, 00, 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.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10620
Posted: 01:26pm 21 Mar 2022
Copy link to clipboard 
Print this post

  Quote  What AM I doing wrong?


You need to DIM (or LOCAL) the variable recvd before it is used (must be a float)
 
circuit
Senior Member

Joined: 10/01/2016
Location: United Kingdom
Posts: 292
Posted: 08:03pm 21 Mar 2022
Copy link to clipboard 
Print this post

  matherp said  
You need to DIM (or LOCAL) the variable recvd before it is used (must be a float)

Peter, thank you for you most speedy reply.  I copy/pasted the code directly from the manual - does this need correction?  This is the same code that appeared originally in v. 4.5 Micromite Manual and then was migrated over to the 'Getting Started with Micromite' manual - of which there have been several revisions.  Has no-one come across this issue before?
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4147
Posted: 08:19pm 21 Mar 2022
Copy link to clipboard 
Print this post

I suspect the default would have been a float back then.

Now it will depend what else you have in your program, I think.

John
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025