Memmory Adressing Problems

zufluchtzuflucht Posts: 2
edited 2020-05-20 - 13:48:21 in Propeller 1
Hi Folk,
I am new to µC- Programming and the Spin language.
I am trying to use Data over a set of subroutines / Cog's.

Main.Spin should create Some Data in an Array and send the Memory Adress to a second Cog where the address is read and stored in another Array. As seen in the Prop. Manual in Section Long (Syntax 3) p. 130

Here is My Code
OBJ
  'pst  : "Parallax Serial Terminal"
  dot : "PlayWithNumbers" 
 

CON
     _clkmode = xtal1 + pll16x                      ' System clock settings
     _xinfreq = 5_000_000
     CLS    = 16                                    ' Parallax Serial Terminal constants
     CR     = 13
VAR
     long Zahl[5]
     long ID
     long Index
     long read
     long write  
                       
PUB worker
'create some Numbers to play with
 Zahl[0] := 1234
 Zahl[1] := 5678
 Zahl[2] := 9999
 Zahl[3] := 9876
 Zahl[4] := 5432
 Zahl[5] := 1111
 
 dot.start(@Zahl[0])



 
 'pst.Start(115_200)
 'pst.Clear 

and the Code for the second cog in a new *.spin -sheet
Obj
  pst  : "Parallax Serial Terminal"

Con
  Konstante = 1337
  CLS = 16
  CR = 13

Var
  long Stack[30]
  long cog
  long read
  long write
[s][/s]
PUB start(Adr) : okay
  stop
    
  okay := cog := cognew(main(Adr), @Stack) +1
   
  waitcnt(200_000 + cnt)
  
  pst.Start(115_200)
  pst.Clear
   
PUB stop
'' Stoppt lesende Com-Routine - Setzt einen cog frei

  if cog
    cogstop(cog~ - 1)


PUB main(Adresse)
  
   read := 0
   read := long[@Adresse][0] 'does not Match With Zahl[0]

  repeat
   pst.Str(string("read: "))       
   pst.Dec(read)             
   pst.Str(string(CR))
   waitcnt (clkfreq + cnt)
  


Can anyone suggest where my Mistake is?

In a next Step the data will be modified, and read at the first Cog.

Thanks for Help

Many Greetings
zuflucht

Comments

  • Wuerfel_21Wuerfel_21 Posts: 672
    edited 2020-05-20 - 13:31:23
    First off, please use the proper source code tag (the "C" button above the text box)...

    Anyways,
    read := long[@Adresse][0] 'does not Match With Zahl[0]
    
    should be
    read := long[Adresse][0]
    

    @Adresse gives you the address of Adresse (which, being a method parameter, lies on the stack), i.e. a pointer to a pointer.
  • AribaAriba Posts: 2,315
    edited 2020-05-20 - 13:51:21
    Hello 'zuflucht', welcome to the parallax forums.

    Please use the code tags, when you post code (the big C in the edit menu), so the indentions will be visible.
    At a first look, I see two problems:
    The Zahl array is declared with 5 elements, but you use 6 (0..5). The 6th element just overwrites the following ID variable, which you not use yet, so no big problem.

    The bigger mistake:
    You pass the address of the array, and then you access the value with long[@Adresse][0]. That means you use the address of the address, and not the passed address itself.
    So try it with: long[Adresse][0].

    Andy

    Edit: Okay, Würfel_21 was a bit faster...
  • Also, you may run into trouble here at some pint:
    long Zahl[5]    <== do you mean 'Zahl[6]???
    long ID
    long Index
    long read
    long write
    
    PUB worker
    'create some Numbers to play with
    Zahl[0] := 1234
    Zahl[1] := 5678
    Zahl[2] := 9999
    Zahl[3] := 9876
    Zahl[4] := 5432
    Zahl[5] := 1111   <== there is no Zahl[5], only Zahl[0] thru Zahl[4]... '1111' is being written into ID, here!
    

    dgately
  • Many Thanks!
    I will test your sugestions this evening
Sign In or Register to comment.