Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 21:59 26 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 : I2C Address Problem with Micromite

     Page 2 of 2    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8579
Posted: 01:57pm 16 Jan 2022
Copy link to clipboard 
Print this post

Based on limited googling and the address list at i2cdevices.org there are no 10-bit devices hence no support on any of my ports
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 813
Posted: 09:55am 17 Jan 2022
Copy link to clipboard 
Print this post

I think I am too stupid for this project!  

I have tried the CFunction recommended by Geoff.
First of all:

If I use an array
Option EXPLICIT
Option default integer
Dim As Integer temp(4)
Dim r
Do
 r = I2CPort( 2, 18, 17, &H78, 4, temp() )
 If r=0 Then Error "Sensor not found!"
 Print temp(0),temp(1),temp(2),temp(3)
 Pause 1000
Loop

as in the example I get:
[6] r = I2CPort( 2, 18, 17, &H78, 4, temp() )
Error : Dimensions
???

Ok, then I'll just take individual variables:
Option EXPLICIT
Option default integer

Dim temA
Dim temB
Dim temC
Dim temD


Dim r

Do
 r = I2CPort( 2, 18, 17, &H78, 4, temA, temB, temC, temD )
 If r=0 Then Error "Sensor not found!"
 Print temA, temB, temC, temD
 Pause 1000
Loop

Then I get as error message:
[13] Print temA, temB, temC, temD
Error : TEMB is not declared
???

However, if I additionally declare a temE...
Option EXPLICIT
Option default integer

Dim temA
Dim temB
Dim temC
Dim temD
Dim temE

Dim r

Do
 r = I2CPort( 2, 18, 17, &H78, 4, temA, temC, temD, temE )
 If r=0 Then Error "Sensor not found!"
 Print temA, temC, temD, temE
 Pause 1000
Loop

I get data - at least one of the addresses can be read out - and the value changes when I change the air pressure...
12      0       0       0
12      0       0       0
12      0       0       0
13      0       0       0
12      0       0       0
12      0       0       0
28      0       0       0
56      0       0       0
90      0       0       0
86      0       0       0
86      0       0       0
86      0       0       0
86      0       0       0
85      0       0       0
85      0       0       0
12      0       0       0
12      0       0       0
12      0       0       0


WHAT AM I DOING WRONG??

(Oh yes, everywhere was of course the complete "CFunction I2CPort( INTEGER,INTEGER,INTEGER,INTEGER,INTEGER ) INTEGER" included!)

Frank
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 11:24am 17 Jan 2022
Copy link to clipboard 
Print this post

At a quick glance I can see one thing wrong.  In your sample code (at the top of your post) you have:
 Dim As Integer temp(4)
when it should be:
 Dim Integer temp(4)
(without the "As").

I'm not sure what MMBasic would do with this faulty syntax but it would at least get confused.

Geoff
Geoff Graham - http://geoffg.net
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 813
Posted: 12:29pm 17 Jan 2022
Copy link to clipboard 
Print this post

Hi Geoff,

thank you very much for your fast response!
You are right - the "As" is wrong! (but it is from the section "Example Application" from "I2CPort.pdf". (THANK YOU!!! I would not have found the error!!!)

But that was not the only error.
r = I2CPort( 2, 18, 17, &H78, 4, te() )

doesn't work, but
r = I2CPort( 2, 18, 17, &H78, 4, te())

do the job!!!

The problem was also the space before the last bracket! =>
[35] r = I2CPort( 2, 18, 17, &H78, 4, te() )
Error : Dimensions


Now I can finally read my 4 bytes correctly!!!

12      213     54      20
12      210     54      29
12      213     54      29
12      216     54      23
12      216     54      26
12      213     54      26
Now I only have to convert the values correctly...


THANK YOU VERY, VERY MUCH!!!

Frank
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 02:35pm 17 Jan 2022
Copy link to clipboard 
Print this post

Actually Dim As Integer temp(4) is not an error, it works fine.  I rechecked the source and even though the "As" is redundant it will still be accepted without error.  My mistake.

So, it seems that you found the problem all by yourself.  Congratulations.

Geoff
Geoff Graham - http://geoffg.net
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2287
Posted: 02:55pm 17 Jan 2022
Copy link to clipboard 
Print this post

hi Geoff,
   is the difference in how the interpreter handles:
r = I2CPort( 2, 18, 17, &H78, 4, te() )
(generating an error), and:
r = I2CPort( 2, 18, 17, &H78, 4, te())
(working), itself a bug in MMbasic?

i ask because i will often add in extra spaces, as formatting, around sets of brackets to help make an expression easier to understand. i'd expect one or more spaces to be ignored, unless placed within a function or variable name, or within a numeric.


cheers,
rob   :-)
Edited 2022-01-18 00:57 by robert.rozee
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3657
Posted: 05:31pm 17 Jan 2022
Copy link to clipboard 
Print this post

Sadly, yes, surely a bug.

John
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 840
Posted: 10:11pm 18 Jan 2022
Copy link to clipboard 
Print this post

Possibly a silly question but does the I2CPort CSub work on a Picomite? (I get a syntax error)

Andrew
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1781
Posted: 11:07pm 18 Jan 2022
Copy link to clipboard 
Print this post

I suspect the inner workings of the different ports of MMBasic (necessitated by the different processors) are sufficiently different to cause problems. Just to see what would happen I tried Peters new CSub LOG for the Pico on a MM2 and got a similar result.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 05:05am 19 Jan 2022
Copy link to clipboard 
Print this post

Andrew:  CSubs are compiled for the instruction set of a particular processor  (that is why they are so fast).  The Micromite and Picomite use completely different instruction sets so you need a CSub compiled for the Picomite.

Rob:  Good point, that is definitely a bug.  I will look into it for the next release.

Geoff
Geoff Graham - http://geoffg.net
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 840
Posted: 06:03am 19 Jan 2022
Copy link to clipboard 
Print this post

Phil and Geoff,
It stands to reason . . .
Many thanks,

Andrew
 
     Page 2 of 2    
Print this page


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

© JAQ Software 2024