OWOUT and incramenting HEX addresses

drjeseuss

Member
Hello,
I am trying to write a bit of code that will send out via OWOUT a request for data, then grab the incoming data in 16 bytes, then incrament the address by 16 and repeat. The overall goal is to request data in blocks of 16 bytes from address 0x1000 to 0x2FFF

Here's a bit that will do this manually:

Code:
' *****  Data from 1000h
owout 3,%0001,($CC,$69,$00,$10,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF) ' Request Memory
owin 3,%0010,(b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15) ' Record result
sertxd ("Data 1000h:  ", 44)
sertxd (#b0," ",#b1," ",#b2," ",#b3," ",#b4," ",#b5," ",#b6," ",#b7," ",#b8," ",#b9," ",#b10," ",#b11," ",#b12," ",#b13," ",#b14," ",#b15, 10 , 13)
sertxd (10 , 13)
' *****  Data from 1010h
owout 3,%0001,($CC,$69,$10,$10,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF) ' Request Memory
owin 3,%0010,(b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15) ' Record result
sertxd ("Data 1010h:  ", 44)
sertxd (#b0," ",#b1," ",#b2," ",#b3," ",#b4," ",#b5," ",#b6," ",#b7," ",#b8," ",#b9," ",#b10," ",#b11," ",#b12," ",#b13," ",#b14," ",#b15, 10 , 13)
sertxd (10 , 13)
I know there are ways to clean things up with this. It's only a rough "working" copy. The sertxd line outputs as comma seperated value for viewing in Excel. My intent is to incrament the memory address by loop instead of doing each request manually.

For those not familiar with OWOUT or the DS1922 I'm connected to, I'll explain the request. $CC "talks" to any/all one-wire devices on he network (should only be one). $69 is the request to read memory. $00,$10 is the requested address 1000h. You will notice the values are swapped. As the values need to be sent as hex I'm hitting a brain fart with the counter. My idea was to take this in two pieces and incrament the last byte by 16 and the first byte by 1. I can use a variable in the OWOUT command, though it appears to send decimal, not hex, and changing b0 to $b0 is useless as expected.

Here's the code bit I wrote to loop this. It "appears" to work, but the address in the OWOUT is obviously wrong as the one-wire returns all 0's.

Code:
b26 = 10
for b25 = 0 to 240 step 16
  owout 3,%0001,($CC,$69,b25,b26,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF) ' Request Memory
  owin 3,%0010,(b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15) ' Record result
  sertxd ("Data : ",#b26,#b25,10,13)
  sertxd (#b0,44,#b1,10,13,#b2,44,#b3,10,13,#b4,44,#b5,10,13,#b6,44,#b7,10,13,#b8,44,#b9,10,13,#b10,44,#b11,10,13,#b12,44,#b13,10,13,#b14,44,#b15, 10 , 13)
sertxd (10 , 13)
  if b26 = 47 and b25 = 240 then
    Return
  elseif b25 = 240 then
    b26 = b26 + 1
  endif
next b25
As you can see in this example, I have replaced $00,$10 with b26,b25. As these output as DEC instead of HEX this part isn't working. I hope it's something simple I'm forgetting! Suggestions??
 
Last edited:

hippy

Ex-Staff (retired)
I cannot even get OWOUT to compile with #b25 in it.

I'm not familiar with the DS1922 but if those bytes are the address there should be no need to use anything other than the variable's name. The only significant thing is in using a 'word address'; when specified as two byte variables the order has to be correct. The data is transferred as 8-bit values, neither decimal nor hexadecimal; that's just an arbitrary convention for how they are considered to be in human readable representations.
 

drjeseuss

Member
I cannot even get OWOUT to compile with #b25 in it.
My mistake. OWOUT should have b26,b25 and not #b26,#b25.

I'm not familiar with the DS1922 but if those bytes are the address there should be no need to use anything other than the variable's name.
OK. So to break this into a simple example, I need a counter that runs from 0x1000 to 0x2FFF. Maybe I'm going about this part all wrong. My initial idea was to use (for example)

Code:
for w0 = 1000 to 12287 step 16
  owout 3,%0001,($CC,$69,b1,b0,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF)
next w0
If I understand you correctly, should this work then? If so, it should return values after each OWOUT from start addresses 0x1000, then 0x1010 and so on, correct?
 

drjeseuss

Member
To offer a bit of information about the DS1922 and therefore the goal, here are a few blurbs from the datasheet:

"After having sent the command code of the Read Memory with CRC command, the bus master sends a 2-byte address that indicates a starting byte location."

The master reads data from the DS1922E beginning from the starting address and continuing until the end of a 32-byte page is reached."

"The Read Memory with CRC command sequence can be ended at any point by issuing a reset pulse."

"The data-log logging memory starts at address 1000h (page 128) and extends over 256 pages (2FFFh)."

Based on these details gleaned, I know the device will send data starting at the requested address and continuing to the end of the page or until reset. I also know the address space starts at 1000h and continues until 2FFFh. So if I call for 1000h and grab 16 bytes, then reset, I should have the first 16 stored bytes. Then I will call the second half of the same page (1010h) and again grab 16 bytes. This gives me the second half of that page. This process can be repeated to obtain all data in the storage space.

I attempted to loop w13 (b26/b27) from 1000 to 12287 and appear to be getting invalid data back (as compared to manually requesting a specific address). I've also tried looping b26 (step 1) and b27 (step 16) and the results are different but no better.

Does anyone see a way of simplifying or looping these incraments to get the proper addresses requested?
 

papaof2

Senior Member
Hex 1000 is decimal 4096. Decimal 1000 is hex 3E8.
As shown, your loop starts at hex 3E8, not hex 1000.

Either start the loop counter at decimal 4096 or use the actual hex values in the loop counter.

John
 

hippy

Ex-Staff (retired)
It's probably best to use hexadecimal values when it makes sense to rather than mentally converting ...

for w0 = 0x1000 to 0x2FFF step 16
owout 3,%0001,($CC,$69,b1,b0,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF)
next w0

Hexadecimal numbers can be represented with a '0x' or '$' prefix, whichever is your preference.

'b0' is the LSB part of 'w0', 'b1' is the MSB part.
 

drjeseuss

Member
Hex 1000 is decimal 4096. Decimal 1000 is hex 3E8.
As shown, your loop starts at hex 3E8, not hex 1000.

That's the mistake for sure! And thanks to you and hippy to suggest using the hex values in the loop. Didn't think to do that. Spent too many brain cells trying to do conversions myself... and poorly at that. Of course 1000 <> 0x1000.

So, again, thanks to you both and here's a block of functional code. Beautiful. Now to trim the fat and get things rolling a bit faster. Cheers.

Code:
for w13 = 0x1000 to 0x2FFF step 16
  owout 3,%0001,($CC,$69,b26,b27,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF) ' Request Read Memory
  owin 3,%0010,(b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15) ' Accept Result
  sertxd ("Data ",#w13,"h:",10,13)
  sertxd (#b0,44,#b1,10,13,#b2,44,#b3,10,13,#b4,44,#b5,10,13,#b6,44,#b7,10,13,#b8,44,#b9,10,13,#b10,44,#b11,10,13,#b12,44,#b13,10,13,#b14,44,#b15, 10 , 13)
sertxd (10 , 13)
  if b0 = 255 and b1 = 255 and b2 = 255 and b3 = 255 then ' Detects iButton Removal
    goto main
  endif
next w13
 

Technical

Technical Support
Staff member
When you get to tidying up your sertxd ..... 10,13 is around the wrong way - return/linefeed is 13,10 and can actually be repalced by the symbols CR,LF
 

drjeseuss

Member
When you get to tidying up your sertxd ..... 10,13 is around the wrong way - return/linefeed is 13,10 and can actually be repalced by the symbols CR,LF

Amazing. I've always wondered why the editor terminal showed || instead of doing the CRLF properly. Oddly, most terminal apps didn't seem to care, though my data formatting always seemed off. Long ago I found a list of codes for CR, LF, Cls, comma, period, etc. It listed them as 10=CR and 13=LF. I've trusted that list ever since! No more of that. Thanks!


I am working to clean the code considerably. Currently, a device can be detected, then programmed and mission started from one sub. Another will detect then read memory to CSV format for Excel, StampPlot, etc. I'm working to modularize things a bit so it will be compatable across a range of iButton products. I'll post more when I get things a bit further. Thanks for all the help and inspiration!
 
Top