Shop OBEX P1 Docs P2 Docs Learn Events
Byte size problems — Parallax Forums

Byte size problems

jcfjrjcfjr Posts: 74
edited 2011-08-13 13:12 in Propeller 1
This is my first project using the Propeller,and usually with enough digging I have been able to understand how things work. But I have run into something I do not understand. I am using two Propeller chips in this project, and need to pass three numbers from the first Prop (U1) to the second Prop (U2). U2 is driving a 3.5 inch touchscreen and has no room for anything except driving the display, thus the need for the second Prop for my application. I am building a meter that measures two voltages, a forward and reflected voltage,and calculates some values (SWR and power), then passes these values to U2 for display, this part works. When there is no transmission to measure, I wanted to display the time on the meter. I am using the DS1302and it works fine. I want to pass the three values(integers) hour, minute, second to U2 for display. Graphics on U2 only uses strings to print, so I convert the hour, minute, second to strings before sending(no room on U2 to do this), and then print these as three separate strings on the display.

I use the following on U1 to send the values
repeat
 
    rtc.readTime( @hour, @minute, @second )     'read time from DS1302
            'send hour, minute, second to U2 as string
    Comm.str(CD.ToStr(hour,%000_000_000_0_0_000011_01010 ))
    Comm.Str(String(13))
    Comm.str(CD.ToStr(minute,%000_000_000_0_0_000011_01010 ))
    Comm.Str(String(13))
    Comm.str(CD.ToStr(second,%000_000_000_0_0_000011_01010 ))
    Comm.Str(String(13))
    waitcnt( 79_000_000 + cnt )

And the following to recieve on U2
Comm.Rxstr(@Rbuf)
    bytemove(@hour,@Rbuf,12)
'    minute := Comm.Rxstr(@Rbuf)
    Comm.Rxstr(@Rbuf)
    bytemove(@minute,@Rbuf,12)
'    second := Comm.Rxstr(@Rbuf)
    Comm.Rxstr(@Rbuf)
    bytemove(@second,@Rbuf,12)

Each string is 3 bytes according to strsize , so I set the following variable sizes in U2

byte Rbuf[3]
byte hour[3]
byte minute[3]
byte second[3]

and only moved 3 bytes with bytemove for each variable.

But the display would only show seconds on it. If I change all the above variable sizes of 3 to 8 bytes, then the minute and second will display, and only if I use a size of 12 bytes will it display all three values correctly.

I thought I was sending each value separately as three byte packets, copying it to its own location, then printing it on display as a string at a specified location. Why won't this work unless I use 12 byte lengths for the four variables, it seems to me 3 bytes should work since I am printing them as separate strings at separate locations, and not as one?? I have included complete code that shows the graphics portion.
Sign In or Register to comment.