Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 20:30 29 Nov 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 : Beta Testers Wanted

     Page 20 of 26    
Author Message
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 722
Posted: 12:25pm 01 Feb 2014
Copy link to clipboard 
Print this post

Didn't know that Register addresses depend on compiler's;-)
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9310
Posted: 12:50pm 01 Feb 2014
Copy link to clipboard 
Print this post

I have never needed to use peek and poke on modern microcontrollers, but I guess that is just me.

In the days of the Atari 8-bit, it's OS did have useful peek and poke registers for looking at things like timers etc. One useful command I remember was POKE 580,1(pretty sure I remember that correctly), which would cause the Atari to reboot when you pressed RESET rather then just stop the program and clear the screen.

There were other registers you could use to prevent the use of the BREAK key etc - all these tricks were used to prevent anyone from stopping and listing your program.
Smoke makes things work. When the smoke gets out, it stops!
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 02:31pm 01 Feb 2014
Copy link to clipboard 
Print this post

What is going on?

I2C open 100,100

lcd = &b0111000

n$="Hello World"

I2C write lcd,0,3,0,1,4:Pause 1
'I2C write lcd,0,3,0,44,2:Pause 1
'I2C write lcd,0,3,0,1,2:Pause 1

Print Len(n$)

End


If I comment out the I2C commands, (which all show MM.I2C = 0), the length of n$ prints out as 11 which is what I expect. But... if I un-comment any of the I2C commands, the length of n$ prints out 0.

If I replace the I2C commands with something like A = 1, then the length is 11 again.????
David M.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9310
Posted: 02:45pm 01 Feb 2014
Copy link to clipboard 
Print this post

Something to do with the I2C.

My test:

[code]
I2C open 100,100

lcd=&b0111000

n$="Hello World"
Print Len(n$)

I2C write lcd,0,3,0,1,4:Pause 1
'Hello. This is a comment.
'And another comment.n$="Hellor"


Print Len(n$)
[/code]

I get 11 as a result for this test code, but not sure what is going on in your case.
I also agree it should be 11.

I don't actually have any I2C to test with, but I wonder what would happen if I just run your code anyway....

EDIT: see my changed code above. The result I get is:

11
11


ANOTHER EDIT: I see I made a typo in the code above, but this would seem to be significant.

When I deleted the bit on the 2nd comment that read n$="Hellor", then saved and re-ran the code, the result was:


11
0


Very interesting....

ANOTHER EDIT: Yes, somehow, someway, n$ is being erased. If I add Print n$ at the bottom of the code, I get a blank line - definitely nothing in n$ anymore, so the len(n$) being equal to zero is, in fact, correct, but why should n$ be getting erased? Hmmmmmmmmmm.........

ANOTHER EDIT: Definetly something to do with the I2C handler. If I use this altered code to send stuff to the COM port rather then the I2C port:

[code]
Open "COM1:9600" As #1

lcd=&b0111000

n$="Hello World"
Print Len(n$)
Print #1,n$

'Hello. This is a comment.
'And another comment.


Print Len(n$)
Print n$
[/code]

....it returns with:


11
11
Hello World.

Edited by Grogster 2014-02-03
Smoke makes things work. When the smoke gets out, it stops!
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 02:55pm 01 Feb 2014
Copy link to clipboard 
Print this post

  Quote  
I don't actually have any I2C to test with, but I wonder what would happen if I just run your code anyway....


I tried that, but it doesn't work because I need the length of a string to output each character one at a time and if the length is 0, then it thinks there is nothing to display.

You can try it though. I'll have another go with a bad i2c address and see if it does the same after i2c time-out.

I have a feeling that the I2C function is somehow stuffing around with the variable tables??

I'll try a few different commands in between the n$ = "Hello world" and the print len(n$) to see if there is a conflict.

Does anybody else have an I2C module they can try?

===
I just tried it with a non valid i2c address and got mm.i2c=1 but len(n$) still 0...a bug???Edited by MOBI 2014-02-03
David M.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9310
Posted: 03:07pm 01 Feb 2014
Copy link to clipboard 
Print this post

Certainly sounds like one(a bug).

Please re-check my post at the end of page 32, as I have been adding to it....

EDIT: I have several I2C EEPROM chips I could play with, and also that ALFAT module, so I might dig one or both out, and try a version of your code, to see if I can send n$ to the EEPROM or the ALFAT module.

...but right now, I have to cut the grass. Edited by Grogster 2014-02-03
Smoke makes things work. When the smoke gets out, it stops!
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 03:43pm 01 Feb 2014
Copy link to clipboard 
Print this post

  grogster said  ...but right now, I have to cut the grass.



As long as it not your neighbours???

I tried a few more I2C modules and they all work but a "print len(n$) after the I2C command still says len(n$) is 0 despite it being set as "Hello world" before the I2C.

FIIK.

PS I had a look at the previous page.

PPS - a right scorcher today - like a furnace outside. 24C inside - no air con needed. There goes my vegie garden again. Ok if you like rhubarb as it is the only thing doing well.
David M.
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 04:03pm 01 Feb 2014
Copy link to clipboard 
Print this post

A trap for beginners?

Dim n$(20) first and every thing is hunky dory.


David M.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9310
Posted: 05:13pm 01 Feb 2014
Copy link to clipboard 
Print this post

Interesting.

Perhaps Geoff will chime in here with his thoughts.

In the MM and CMM, you don't have to DIM the strings, you just declare them as part of what you are doing. You only need to use DIM, if you are using any kind of array.

However, the MM chip is a cut-down version of MMBasic, so perhaps it has something to do with that?

I would expect that you only need to DIM n$(1) LENGTH 20 rather then 20....

EDIT: Yes, when I put in the DIM as above, it works fine for me too. Interesting though, cos you can define n$ without needing to DIM it before. Oh well....

Oh, and yes my grass - not keen enough to cut the neighbour's grass - we have enough of our own, as we own two properties next door to each other!

EDIT: Another interesting variation on this.....

At the command prompt, type:


> n$="Hello World."
> ? n$
Hello World.
> edit


Now, exit the editor, and type ? n$ again - it's gone.

Edited by Grogster 2014-02-03
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6103
Posted: 05:43pm 01 Feb 2014
Copy link to clipboard 
Print this post

It looks like the first string variable size is getting corrupted.
The actual string is still OK

This is an extract from some code with a few test strings added:
Function Calibrate()
' needs to be called once for each module.
' safest to do it on every program start.
Local n, calMEM
calMEM= BMP085calMEM
a$="hello world(A)"
b$="hello world(B)"
Print a$
Print b$
For n = 1 To 11
I2C write BMP085address, 0, 1, calMEM ' first calibration location
Pause 1
I2C read BMP085address, 0, 2, BMPData(0)
'print BMPData(1), BMPData(0)*256 + BMPData(1)
cal(n) = BMPData(0)*256 + BMPData(1)
If n < 4 Or n > 6 Then ' need to convert some to signed numbers
If cal(n) > 32767 Then
cal(n) = cal(n) - 65536
EndIf
EndIf
'print n,cal(n)
Pause 1
calMEM=calMEM+2 ' advance to the next calibration location
Next n
Print "A:"+a$
Print "B:"+b$
Print Len(a$)
Print Len(b$)
End Function


This is the output as HEX:
52 55 4E 20 0D 0A 68 65 6C 6C 6F 20 77 6F 72 6C RUN ..hello worl
64 28 41 29 0D 0A 68 65 6C 6C 6F 20 77 6F 72 6C d(A)..hello worl
64 28 42 29 0D 0A 41 3A 68 65 6C 6C 6F 20 77 6F d(B)..A:hello wo
72 6C 64 28 41 29 00 00 00 00 00 00 00 00 00 00 rld(A)..........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 0D 0A 42 3A 68 65 6C 6C 6F 20 ........B:hello
77 6F 72 6C 64 28 42 29 0D 0A 20 31 39 30 0D 0A world(B).. 190..
20 31 34 0D 0A 31 34 3A 32 37 3A 33 32 20 31 34 14..14:27:32 14
3A 32 37 3A 33 32 20 54 3A 32 34 2E 39 20 20 50 :27:32 T:24.9 P
3A 39 38 32 2E 38 20 20 50 28 73 6C 29 3A 31 30 :982.8 P(sl):10
31 31 2E 32 0D 0A

The first string size is 190 instead of the original 14 bytes.
All the extra bytes are output as asc(0) which really stuffed up MMedit2.
MMedit1 is more forgiving.

As a workaround, a sacrificial string could be used.
Start your program with:
Bugger$="Geoff said he wanted us to find some bugs"

It does explain a strange bug I was trying to find in MMedit2.

Jim
VK7JH
MMedit   MMBasic Help
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 05:52pm 01 Feb 2014
Copy link to clipboard 
Print this post

Indeed interesting.

If I declare a string variable: Dim n$(1) length(1), will it not only contain 1 character?

If so, why does it happily accept: n$ = "1.2345"

PS

Maybe "cut someone's grass" has a different meaning? Here, it means "while the cat's away......"
David M.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6103
Posted: 05:59pm 01 Feb 2014
Copy link to clipboard 
Print this post

  MOBI said   Indeed interesting.

If I declare a string variable: Dim n$(1) length(1), will it not only contain 1 character?

If so, why does it happily accept: n$ = "1.2345"

PS

Maybe "cut someone's grass" has a different meaning? Here, it means "while the cat's away......"


n$(1) is an string array while n$ is a string variable. Different things.
try n$(1)= "1.2345"

It is not a good idea to have similar names but it looks like it is allowed.

Jim
VK7JH
MMedit   MMBasic Help
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 06:17pm 01 Feb 2014
Copy link to clipboard 
Print this post

Hi Jim - thanks. The similarity of the n$ did put me off track. I usually try to avoid anonymity and ambiguity in variables - in this case I was just testing some I2C commands.

It still comes back to why I could give n$ a value before issuing I2C commands only to have it disappear after the I2C.

Still puzzled, any thoughts?
David M.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9310
Posted: 06:27pm 01 Feb 2014
Copy link to clipboard 
Print this post

  TassyJim said  As a workaround, a sacrificial string could be used.
Start your program with:
Bugger$="Geoff said he wanted us to find some bugs"

Jim


HAHAHAHA!
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9310
Posted: 06:30pm 01 Feb 2014
Copy link to clipboard 
Print this post

  MOBI said  PS

Maybe "cut someone's grass" has a different meaning? Here, it means "while the cat's away......"


Yes, it really was time to cut the grass.

Only problem is that now I want to trim the bush.

Oh stop it....

This forum is a bad influence on me.Edited by Grogster 2014-02-03
Smoke makes things work. When the smoke gets out, it stops!
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 722
Posted: 11:43pm 01 Feb 2014
Copy link to clipboard 
Print this post

Micromite DS1307

Hi,

does micromite support a directly connected DS 1307 with its time$ and date$ Funktions?
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9310
Posted: 11:50pm 01 Feb 2014
Copy link to clipboard 
Print this post

Yes and no.
YES in that you could connect it, and use I2C commands to access the 1307 in the normal way, along with the 1307's backup battery.

NO in that the MM chip will not remember any time or date once the power has been cycled, BUT, if you made the first bit of the code, to read the info from the 1307, and use that to alter the MM internal clock, then YES.

Hell - I'm on the beer tonight - yikes.
Smoke makes things work. When the smoke gets out, it stops!
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 11:54pm 01 Feb 2014
Copy link to clipboard 
Print this post

lcd = &b0111000
I2C open 100,100
I2C write lcd,0,3,0,1,4:Pause 100 'reset display
I2C write lcd,0,3,0,44,2:Pause 1 'set for 2 lines
I2C write lcd,0,3,0,1,2:Pause 1 'clear screen zero cursor pos 1
I2C write lcd,0,3,0,195,2:Pause 1 'set pointer 2nd line centre

Pause 1000

Dim lcd$(1)

volts = 1.2345 'test number

lcd$=Str$(volts) + " Volts"
Print lcd$
For char = 1 To Len(lcd$)
lcd_char = Asc(Mid$(lcd$,char,1)) 'convert string to ascii chars
I2C write lcd,0,3,0,lcd_char,1 'send char to LCD
Next char


My problem. If I insert the line Dim lcd$(1), everything works ok and the screen displays 1.2345 Volts

At Print lcd$, the result is 1.2345 Volts.

If I leave out the Dim lcd$(1), the lcd displays 1 then the rest garbage, but the Print lcd$ line still prints 1.2345 Volts.

What am I missing?

Can I not simply use lcd$ = text without a previous Dim?
David M.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9310
Posted: 12:10am 02 Feb 2014
Copy link to clipboard 
Print this post

I'll sleep on it......
Beer is good, but it does bugger one's ability to think logically.

Personally, I do think we have some kind of bug here.
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3198
Posted: 03:43am 02 Feb 2014
Copy link to clipboard 
Print this post

Hi All,

I does sound like another bug.

I have just got back from a couple of days away but I need to go to bed so I will tackle this tomorrow.

One thing that I have found is that beta one has a bug in the I2C slave routines.

Geoff
Geoff Graham - http://geoffg.net
 
     Page 20 of 26    
Print this page
© JAQ Software 2024