Command not simulating

johnlong

Senior Member
Hi All
Using the following command in PE6 is not simulating
is there a setting other than the hsersetup needed for it to simulate
ie in the options for the simulator
Code:
#Picaxe 40x2
hi2csetup i2cmaster, %11010000, i2cslow_8, i2cbyte 
  	hi2csetup i2cslave, %11010000
	hsersetup   B9600_8, %001
	
	leave:
		if pointer="Z" and marker="X" then
			if theMode=1 then Run 1:endif
			if theMode=2 then Run 2:endif
                      endif
       hserin [1000,leave],0,2 'simulator just hangs on this line
have tried %00 and %0 for the hsersetup
just afrer it timing out not excicuting
regards
john
 
Last edited:

hippy

Technical Support
Staff member
It is not clear exactly which command is not simulating. How it's not simulating and what it is doing may help give an answer.
 

johnlong

Senior Member
It is not clear exactly which command is not simulating. How it's not simulating and what it is doing may help give an answer.
Sorry Hippy just noticed 2 points
point 1 I am an idiot the command not simulating is not there
point 2 the command
hserin [1000,leave],0,2
will edit above my apologies

john
 

hippy

Technical Support
Staff member
You cannot simulate a HSERIN while using backgroudn receive. This appears to simulate as expected...

Code:
hi2csetup i2cmaster, %11010000, i2cslow_8, i2cbyte 
hi2csetup i2cslave, %11010000
hsersetup   B9600_8, %000
hserin [1000,leave],0,2

sertxd("OK")
end

leave:
sertxd("Timeout")
end
 
Last edited by a moderator:

johnlong

Senior Member
Hi Hippy
Dropped your code in
doing just the same hits the command stops on it
make coffee go to toilet clean adhesive spreader
come back still sitting there
Do I needed to alter any settings in the simulators options
regards
j
 

hippy

Technical Support
Staff member
Have you got the latest PE6 installed ? Is the Terminal Window opened but not in the foreground ?
 

Goeytex

Senior Member
Possibly the terminal simulator is waiting for you to enter two bytes of data?

In the "transmit" pane, type two byte values separated by a comma, then click "send" The simulation then show "OK". To simulate the timeout, in the terminal click on "timeout" instead of entering the bytes.
 

johnlong

Senior Member
Looks like will have to revert back to point 1 (I'm an idiot)
There is a button on the terminal window
simulate timeout got a clock on so that you can not miss it (point 1 rules)
 

bobladell

New Member
hsersetup / hserptr query

I'm trying to understand the hsersetup command properly and in particular the use of hserptr vs ptr as they are both supposed to point to the scratchpad, unless I misunderstand the documentation ? I'm running on 40X h/w and hence simulating the same. It's the operation in the simulator - before trying on chip - that I'm querying.

Documentation 7.9.2 P97 says :-
When a byte is received it is saved to this scratchpad address, the hserptr variable is incremented and the hserinflag flag is set (must be cleared by user software). Therefore the value ‘hserptr -1’ indicates the last byte
written, and ‘hserinflag = 1’ indicates a byte has been received (see also the setintflags command).

hserptr equates to s_w5 according to P16.

So to test it I've used :-

s_w5 = 55 ; a good a number as any to test
hsersetup B9600_8, $00 ; 9600 baud, enable, True data TX/Rx in background mode

And "Watch" the variables ptr, s_w5, flags and bptr.

After simulated execution of hsersetup s_w5 remains = 55 when I'm expecting it to be set to zero.

What am I missing please ?

Thanks
 

Technical

Technical Support
Staff member
See post #4 above, background hserin can not be simulated. This is due to technical limitations of the simulator.
 

bobladell

New Member
Ah - assumed that meant background data couldn't be simulated, which makes sense, not the flags / pointer which should be OK to simulate.

Guess I'll have to sertxd (s_w5) on chip and see what it says

Thanks
 

bobladell

New Member
So is it s_w5 or ptr that should be zero after hsersetup - or are they just different names for the same pointer ?
 

hippy

Technical Support
Staff member
So is it s_w5 or ptr that should be zero after hsersetup - or are they just different names for the same pointer ?
The "s_w5" variable is also the "hserptr" variable on X2 PICAXE devices. The "ptr" variable is a separate variable in its own right.

"s_w5" / "hserptr" is reset to zero on execution of the HSERSETUP command. "ptr" will remain at whatever value it previously held.
 

bobladell

New Member
So if I put 4 characters into scratchpad 100 -104

hsersetup B9600_8, $00 ; 9600 baud, enable, True data TX/Rx in background mode

code to load 4 x characters into scratchpad 100 to 104 - simulates OK

endstring = ptr - 1 ; save pointer address in endstring - removing CR LF

ptr = 100 ; reset pointer to 0

for counter = 100 to endstring ; use endstring for variable length string transmission to device
char = @ptrinc ; get the next character
sertxd (char)
serout sero,T9600_8,(char) ; send to device on normal I/O port c.5 - alternative to hserout pin c.6
pause 200 ; pause 100mS between chars to let HC12 receive them
next counter

sertxd ("hserptr = ",hserptr,CR,LF) ; after rxing characters from sero into h/w buffer hserptr = 5 and ptr = 105 ?

hsersetup B9600_8, $00 ; execute hsersetup to reset hserptr = 0

sertxd ("hserptr = ",hserptr,CR,LF) ; show hserptr = 0 on Terminal

Correct so far ?
 

hippy

Technical Support
Staff member
Correct so far ?
It is not clear exactly what you are trying to do, whether simulating or running on a real chip. There seem to be some apparent bugs -

"hsersetup B9600_8, $00" - does not set background receive mode

"endstring = ptr - 1" - the 'ptr' will be 0 at this point so 'endstring' will be set to the last scratchpad location value.

"Pause 200" - Should this be for every character or outside the FOR-NEXT loop ?

"sertxd ("hserptr = ",hserptr,CR,LF) ; ... hserptr = 5" - No, nothing will have been received, 'hserptr' will not have value 5.
 

hippy

Technical Support
Staff member
There seems to be some confusion which we can hopefully clear up.

To have simulation put data from the Terminal automatically into Scratchpad; a HSERSETUP which enables background receive has to have been executed. That is, with bit0 set; "HSERSETUP <baud>,%xx1".

This functionality is already included in PE6 and is working as expected. A demonstration program for simulating background receive is included at the end.

The HSERIN command cannot be used once a HSERSETUP which enables background receive has been executed.

Likewise a SERIN command cannot be simulated once a HSERSETUP which enables background receive has been executed.

There is (was) a bug with HSERSETUP not zeroing 'hserptr' when simulating as it does on a physical PICAXE. This will not matter if 'hserptr' remains at its initialised to zero value from the program start, and can be worked around by explicitly specifying "hserptr=0" after the HSERSETUP command.

This bug has already been fixed and will be included in the next release of PE6.

Note that 'hserptr' is only cleared when background receive is enabled by HSERSETUP. 'hserptr' will not be reset to zero if background receive is not enabled by the HSERSETUP command.

Note that 'ptr' is not altered nor zeroed by HSERSETUP. While 'ptr' is used in conjunction with 'hserptr' and background recieve it is not a part of high-speed serial itself.

A demonstration program for simulating background receive is below. When the Terminal window appears enter "abc" (without the double-quotes) then press Send. The Terminal will show "<a><b><c>" echoed by the program.

Code:
#picaxe 28x2
#terminal 9600
hsersetup b9600_8, %001
do
  if ptr <> hserptr then
    b0 = @ptrinc
    sertxd( "<", b0, ">" )
  end if
loop
 

bobladell

New Member
Hi hippy - many thanks. Just got back to this. As usual, obvious when someone points it out ! I had been concentrating on the pointers and forgot about the "HSERSETUP <baud>,%xx1" - adding to the confusion.

So to try and summarise, I think the description is that both ptr and hserptr both point to the scratchpad (in X2's only M2's don't have one). ptr can be set to point to anywhere in the scratchpad as its starting point so could be used to setup a number of data buffers starting at addresses e.g. 0, 96, 520, 1000 (28 and 40X2 but only 128 bytes in 20X2) (needing coding to keep track of which pointer is being used for any given purpose).

hserptr only ever starts at 0 after a HSERSETUP command and hence ptr needs to be set to 0 to operate on the contents of the scratchpad.

What isn't clear is the width of hserptr - is it 8 bits (serial buffer of 256 bytes) or 10 bits (serial buffer of 1023 bytes) please ? And is it 7, 8 or 10 bits wide in a 20X2 ?

In M2's (and X2 operating in hserin mode) - the 2 byte buffer can be any one of the word variables w0 through wx which, with a stream of unprocessed inbound data, would continuously wrap between the lower and upper bytes as the circular 2 byte buffer - or does it just receive low byte, high byte and ignore anything following ?

Many thanks
 

hippy

Technical Support
Staff member
I think you've got it with respect to 'ptr' and 'hserptr'. Both initialised to zero, the 'hserptr' is the "put into buffer pointer" and 'ptr' is your "read from buffer pointer" which chases that. The number of bits in both depends on the size of scratchpad.

On the M2, the 2 byte serial buffer is entirely internal, part of the on-chip hardware. The variable used in a HSERIN command simply gets set to what's first in the buffer if there is anything in the buffer.
 

bobladell

New Member
Ah - M2 / hserin - so there is a separate 2 byte buffer hidden away in the H/W that auto transfers to the chosen variable

Thanks hippy - closes this one off
 
Top