Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 11:02 20 Apr 2024 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 : Attempt at E-100 with MX170 Slave

     Page 1 of 2    
Author Message
LouisG
Senior Member

Joined: 19/03/2016
Location: Australia
Posts: 121
Posted: 11:20am 07 May 2022
Copy link to clipboard 
Print this post

Hi Guys,

I am trying to duplicate the example of using a slave MX170 described on Page 72 of Getting Started with Micromite but have ground to a halt.

Am using an Explore 100 to control a small process pilot plant and have used up ALL the I/O points, believe it or not. Everything works! But now I need few additional points. I have never messed with serial communication so this is new for me.

I connected the two I2C lines of the E-100 (66, 67) to the MX170 (17, 18) respectively.(Actually it's an MX270, which is equal to the 170 but with two less I/O points). Both E-100 and the 170 are running MMBasic 5.05.05.

I copied and loaded the Slave program on Page 72 into the 170 and the three Master routines into the E-100. Using MMEdit Chat:

> ssetpin 4, 1
> print spin(4)
Error : Slave did not respond
>

I would have expected 0 (volts) for pin 4 of the MX170, which was set for analog input (with temporary 1k0 resistor to ground).

On looking closer, I also notice there is no subroutine for the E-100 called SPIN, only a function SPIN(), so how could the command example SPIN 15, 1 for switching on an output (Page 72 at bottom) work?

How could I troubleshoot this? Wondering if I am missing some information?

...  Louis
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 843
Posted: 12:10pm 07 May 2022
Copy link to clipboard 
Print this post

Looks like a typo. PIN can be both command and a function as normally used. So a neat way to have it for the slave would be using SPIN as both as well, but this would come undone when you try to create the SUB and FUNCTION with the same name.

Did the SUB SETPIN go into the Master, I thought it would complain about it being a reserved word.


PS. Looks like it wont complain about the SETPIN being used as a SUB (on an Armmite H7 anyway) but when you call it I think you will get the native SETPIN command which will act on the E100.
Edited 2022-05-07 22:25 by disco4now
Latest F4 Latest H7
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 01:12pm 07 May 2022
Copy link to clipboard 
Print this post

You didn't mention it, but have you got pull-ups on the I2C pins? I2C uses open collector signalling.

Watch the routine names. On the master they are
SSETPIN pin, cfg - configures a pin on the slave
SPIN pin, output - sets an output on the slave
nn = SPIN() - a function that returns a value from the slave

Don't confuse SETPIN and SSETPIN.

Page 73, 2nd routine should be SUB SPIN I think. Otherwise SPIN 1,2 will fail as there will be no routine for it.
Edited 2022-05-07 23:23 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
LouisG
Senior Member

Joined: 19/03/2016
Location: Australia
Posts: 121
Posted: 01:25pm 07 May 2022
Copy link to clipboard 
Print this post

Yes, and thanks disco4now. My thoughts exactly,

I think I will restart this experiment from scratch but am hoping first to hear from others who did try this.

-
 
LouisG
Senior Member

Joined: 19/03/2016
Location: Australia
Posts: 121
Posted: 01:33pm 07 May 2022
Copy link to clipboard 
Print this post

Thanks, too, Mick. You are on the right track but then there's the comment by Disco4now that you can't have a SUB and a FUNCTION with the same name.

Hmmm . . .

Yes, I do have the pullups installed.
Edited 2022-05-07 23:41 by LouisG
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 03:15pm 07 May 2022
Copy link to clipboard 
Print this post

I don't think it has the same name. There is no SUB SETPIN

Page 72 refers to the interface routines as being SSETPIN, SPIN and SPIN(). Page 73 gives examples as SSETPIN, SETPIN and SPIN() so I assume that SETPIN is a misprint for SPIN. It would tie in with how the routines work as well i.e. SPIN sets the output of an I/O pin on the slave. If I'm wrong then the system can never work as SPIN 15,1 and SPIN 15,0 on page 72 have nothing to call.

Function SPIN(pinnbr) isn't the same as the sub SPIN pin,output.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 10:20am 08 May 2022
Copy link to clipboard 
Print this post

  Mixtel90 said  Page 72 refers to the interface routines as being SSETPIN, SPIN and SPIN(). Page 73 gives examples as SSETPIN, SETPIN and SPIN() so I assume that SETPIN is a misprint for SPIN. It would tie in with how the routines work as well i.e. SPIN sets the output of an I/O pin on the slave. If I'm wrong then the system can never work as SPIN 15,1 and SPIN 15,0 on page 72 have nothing to call.

I have not been following this in detail so please forgive me if I have got the wrong end of the stick.  But, yes, there does appear to by a misprint in the following routine.  The sub SETPIN should in fact be SPIN as shown below.

' set the output of an I/O pin on the slave
SUB SPIN pinnbr, dat
 I2C OPEN 100, 1000
 I2C WRITE &H26, 0, 3, 2, pinnbr, dat
 IF MM.I2C THEN ERROR "Slave did not respond"
 I2C CLOSE
END SUB


Geoff
Geoff Graham - http://geoffg.net
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 03:18pm 08 May 2022
Copy link to clipboard 
Print this post

Cheers, Geoff. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
LouisG
Senior Member

Joined: 19/03/2016
Location: Australia
Posts: 121
Posted: 08:07pm 08 May 2022
Copy link to clipboard 
Print this post

Yes, and many thanks from me too.

Louis
 
LouisG
Senior Member

Joined: 19/03/2016
Location: Australia
Posts: 121
Posted: 03:52pm 10 May 2022
Copy link to clipboard 
Print this post

Guys,

I've implemented Geoff's correction but am still unable to get the demo example to work.
I'm testing the setup from the MMEdit chat window and sending to the E-100 master.

If, for example, I try to configure Pin 26 of the MX170 slave as an output (code 8) and type the SSetpin command as shown at the bottom of Page 72, I immediately get an error.


ssetpin 26, 8
[5] Sub SSETPIN pinnbr, cfg
Error : PINNBR already declared
>


Line [5] is the first line of the three subroutines for the master:

SUB SSETPIN pinnbr, cfg

What could be causing this error?

-  Louis
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 05:58pm 10 May 2022
Copy link to clipboard 
Print this post

Does it work if you put the

SSETPIN 26, 8

in the program rather than trying to run it from the command line?
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
LouisG
Senior Member

Joined: 19/03/2016
Location: Australia
Posts: 121
Posted: 06:44pm 10 May 2022
Copy link to clipboard 
Print this post

Hi Mick,

Excellent idea!
I put all 4 command lines for flashing a LED on pin 24

SSETPIN 24, 8
SPIN 24, 1
PAUSE 300
SPIN 24, 0

into the E-100 master. I got the following:

RUN
[18] Sub SPIN pinnbr, dat
Error : Duplicate Name
>

Could the problem be the sub and the function having the same name SPIN?

-

2nd Try.
I commented out the function FUNCTION SPIN(pinnbr) and repeated the above. Same error as earlier.

[18] Sub SPIN pinnbr, dat


-
Edited 2022-05-11 05:00 by LouisG
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 07:16pm 10 May 2022
Copy link to clipboard 
Print this post

The function SPIN() can have the same name as the sub SPIN because it's a different thing. MMBasic has different tables for them. Note that SPIN() returns a value, it doesn't take one. SUB SPIN takes a value but doesn't return one. :)

You could try using OPTION EXPLICIT and DIM your variables. That can sometimes show up odd things. You could also try changing the name of SUB SPIN to SUB SPOUT (both it's name and when you call it).
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 843
Posted: 12:32am 11 May 2022
Copy link to clipboard 
Print this post

  Mixtel90 said  The function SPIN() can have the same name as the sub SPIN because it's a different thing. MMBasic has different tables for them. Note that SPIN() returns a value, it doesn't take one. SUB SPIN takes a value but doesn't return one. :)

I think you will find SUB,FUNCTION,CSUB and CFUNCTION are all put in the same list when the program starts, and duplicates are not allowed. The built in commands and functions are separated, so PIN() the function and PIN the sub are allowed, but not for user defined stuff.

If you enter the SPIN() Function and SPIN Sub in the editor and save you can call them individually from the command line OK, but type the RUN command which preprocesses them during the startup of the program and the duplicate is detected.
Latest F4 Latest H7
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 06:25am 11 May 2022
Copy link to clipboard 
Print this post

It must work for Geoff. I don't think it would be in the manual otherwise. :)

Someone (Lizby?) has done a lot of work on this fairly recently and had it working. He changed it to use COM ports instead of I2C.
Try from here onward.
Edited 2022-05-11 16:38 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3010
Posted: 01:30pm 11 May 2022
Copy link to clipboard 
Print this post

More specifically, starting from here

I did not add the bells and whistles available with the implementation of the EXECUTE command, which adds a lot of functionality.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
LouisG
Senior Member

Joined: 19/03/2016
Location: Australia
Posts: 121
Posted: 02:05pm 11 May 2022
Copy link to clipboard 
Print this post

Thanks guys.

Looks interesting, Lizby. It's mainly discrete outputs that I'm short of.

-
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3010
Posted: 06:29pm 11 May 2022
Copy link to clipboard 
Print this post

  LouisG said  It's mainly discrete outputs that I'm short of.


Discrete outputs should be easy with either serial or I2C.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1773
Posted: 11:50pm 11 May 2022
Copy link to clipboard 
Print this post

If you only need outputs, (and if timing isn't critical) could a serial-to-parallel chip like 74HC595 do the job? They can be daisy-chained to get as may pins as you need. BITBANG BITSTREAM is an one way to feed them the bits.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3010
Posted: 10:52am 12 May 2022
Copy link to clipboard 
Print this post

  phil99 said  If you only need outputs, (and if timing isn't critical) could a serial-to-parallel chip like 74HC595 do the job?


Or, with I2C, an MCP23017 module (I just looked--that module is considerably more expensive than a pico, so serial or I2C to another picomite could well be the most cost-effective solution).
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
     Page 1 of 2    
Print this page
© JAQ Software 2024