Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:37 25 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 : Problems with PEEK and POKE in MMBasic

Author Message
v.lenzer
Regular Member

Joined: 04/05/2024
Location: Germany
Posts: 49
Posted: 02:42pm 09 Jun 2024
Copy link to clipboard 
Print this post

I want to create a data logger with an RP2040-Zero. I'm working with MMBasic, V.5.08. I wanted to use POKE BYTE .. and PEEK ... for this. But I haven't had any success with that yet. POKE BYTE 1000,111 (write the value 111 to address 1000) seems to work. At least I don't get an error message with it. But with PEEK(BYTE 1000) I don't get the value 111 back. I've already searched the forum, but unfortunately I haven't found any entries. Does anyone have experience with PEEK and POKE in MMBasic? Can the RAM of the RP2040-Zero be used for this at all?
Best wishes! Joachim
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4036
Posted: 02:59pm 09 Jun 2024
Copy link to clipboard 
Print this post

Hi @v.lenzer,

Not immediately sure about why that doesn't work (Edit: perhaps address 1000 - which is very low - is acting as ROM but not reporting an error when you try to write to it ?), however ...

Are you POKEing and PEEKing into arbitrary addresses? ... I would recommend against that.

Allocate an INTEGER array, and use POKE VAR and PEEK(VAR ...) (or PEEK(VARADDR var) so you know that you own the memory in question and it isn't the address of a piece of supposedly opaque MMBasic internals.

Best wishes,

Tom
Edited 2024-06-10 01:12 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 03:23pm 09 Jun 2024
Copy link to clipboard 
Print this post

  Quote  2.6.1. ROM
A 16kB read-only memory (ROM) is at address 0x00000000. The ROM contents are fixed at the time the silicon is
manufactured. It contains:
• Initial startup routine
• Flash boot sequence
• Flash programming routines
• USB mass storage device with UF2 support
• Utility libraries such as fast floating point

As Tom says......
 
v.lenzer
Regular Member

Joined: 04/05/2024
Location: Germany
Posts: 49
Posted: 04:02pm 09 Jun 2024
Copy link to clipboard 
Print this post

thank you very much for your advices. I should have known that address 0 points to the ROM. I'm sorry. If I poke higher addresses than 16KB, the connection is broken. I'm probably poke to RAM locations that contain important values ​​or the program.
With DIM INTEGER adr(nbr) I can unfortunately only store a maximum of 256 bytes. That's why I came up with the idea of ​​writing to RAM. I wanted to write several thousand pulses (data logger).
I have to come up with a construct with variables. We'll see. In any case, I now know how to handle PEEK and POKE.
Edited 2024-06-10 02:07 by v.lenzer
Best wishes! Joachim
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6783
Posted: 04:02pm 09 Jun 2024
Copy link to clipboard 
Print this post

Don't POKE just anywhere. It either won't work (if you're lucky), introduce obscure and unpredictable errors (if you're unlucky) or just crash the lot.

There is no "safe" normal RAM area that can be used with POKE.

You can poke into the video display area or into the variables area (into known variables only). See VAR POKE. I often POKE into strings, it's a neat way to store individual bytes.

For a data logger you are probably better saving to a file using OPEN APPEND to tag the new stuff onto the end. The file can be on drive A (but space is limited) or on a SD card.
Mick

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

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4036
Posted: 04:11pm 09 Jun 2024
Copy link to clipboard 
Print this post

  v.lenzer said  With DIM AS INTEGER adr(nbr) I can unfortunately only store a maximum of 256 bytes.


Why do you conclude that ?

Untested but something along these lines definitely allows you to store/manipulate 16K:

Dim buf%(16 * 1024 / 8) ' 16K buffer
Dim offset%
For offset% = 0 To (16 * 1024) - 1
 Poke Var buf%, offset, &hAB ' Store 0xAB in each byte.
Next


Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
v.lenzer
Regular Member

Joined: 04/05/2024
Location: Germany
Posts: 49
Posted: 04:35pm 09 Jun 2024
Copy link to clipboard 
Print this post

Unfortunately, the short program didn't work. The error message appears: "[4] Poke Var buf%, offset%, &hAB ' Store 0xAB in each byte.
Error : Array dimensions"
Perhaps it's because I'm using an RP2040-Zero. I now have to study the OPEN APPEND command. Perhaps I can handle it.
At this point I have to apologize. I'm a newbie. I've already programmed many controllers in machine language, but I'm only just starting out with MMBasic. I'm trying to learn and practice through small projects in practice. That's why I often ask stupid questions.
Best wishes! Joachim
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4036
Posted: 04:40pm 09 Jun 2024
Copy link to clipboard 
Print this post

Replace buf% with buf%() in the offending line.

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 04:42pm 09 Jun 2024
Copy link to clipboard 
Print this post

Try this line. For me, it runs.

Poke Var buf%(), offset%, &hAB ' Store 0xAB in each byte.

(Note also "%" on offset.)

~
Edited 2024-06-10 02:43 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
v.lenzer
Regular Member

Joined: 04/05/2024
Location: Germany
Posts: 49
Posted: 04:54pm 09 Jun 2024
Copy link to clipboard 
Print this post

Hurray! It worked and I was able to read the values ​​again with PEEK (VAR ...)! Thank you very much!!!
Best wishes! Joachim
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1241
Posted: 05:23pm 09 Jun 2024
Copy link to clipboard 
Print this post

  v.lenzer said  ... That's why I came up with the idea of ​​writing to RAM. I wanted to write several thousand pulses (data logger).[...]

I don't know if it's a good idea to use Peek and Poke for this. I would consider whether a string array with one byte strings (length 1) might not be a cleaner solution.
Example for an array of 16kB:
DIM STRING myByte$(16*1024) LENGTH 1

Best regards
Michael

Edit: One disadvantage is that each usable byte costs you two bytes in memory.
Edited 2024-06-10 04:08 by twofingers
causality ≠ correlation ≠ coincidence
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1113
Posted: 06:38pm 09 Jun 2024
Copy link to clipboard 
Print this post

a more economical way for an array of 16kB:
DIM STRING myByte$(128) LENGTH 128

you only waste additional 128 bytes for 16k Memory
Edited 2024-06-10 04:39 by Martin H.
'no comment
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1241
Posted: 08:03am 10 Jun 2024
Copy link to clipboard 
Print this post

It might also be worth looking at the LONGSTRING command.
causality ≠ correlation ≠ coincidence
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1113
Posted: 12:38pm 10 Jun 2024
Copy link to clipboard 
Print this post

  twofingers said  It might also be worth looking at the LONGSTRING command.

possible.
As long as you do not use BASIC string functions on the array, you can even use the entire memory that has been reserved for this purpose.
'no comment
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1113
Posted: 01:38pm 10 Jun 2024
Copy link to clipboard 
Print this post

btw .. nice User Name @v.lenzer
a pun for slackers
'no comment
 
v.lenzer
Regular Member

Joined: 04/05/2024
Location: Germany
Posts: 49
Posted: 02:59pm 10 Jun 2024
Copy link to clipboard 
Print this post

Better than B.Trüger!
Best wishes! Joachim
 
Print this page


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

© JAQ Software 2024