HSerin- why won't it work?

rs2845

Senior Member
I seem to be having far too much difficulty with the use of Hserin on a 20X2. Firstly, I am unable to use the hserout as a normal i/o pin because my 6-8 month old picaxe can't handle it. That's fine, I can manage.

However, I am unable to receive any data through the Hserin pin (pin B.6). I can use this pin as a standard serial in pin, but not as a hardware serial in.

I have a feeling it is something to do with my Hsersetup command. Basically, I am using the 20X2 to 'wait' and respond to commands received via the serial in from another picaxe, sending data on N4800 baud.

Below is my code- it's a bit messy but it works if I convert the hserin commands to serin. I want the Hserin to work on N4800 baud and preferably. If I disable the Hserout pin, I get an error saying my chip doesn't support it, and even then the '%xyz' mode thing in the Hsersetup seems to be back to inverted! It's very annoying.

I have to use Hserin because the program freezes, and it needs to receive data into b0-b3 in the background

Code:
#picaxe 20x2
#com 3
hsersetup B2400_4,%00110


start0:


    hserin b0,b1
    debug


    IF b0 ="1" OR b1 ="1" THEN GOTO SoundAlarmsInitiated
    IF b0 ="2" OR b1 ="2" THEN GOTO SilenceInitiated
    IF b0 ="3" OR b1 ="3" THEN GOTO ResetInitiated
goto start0


start1:
SoundAlarmsInitiated:


    IF b0 = "2" THEN GOTO SilenceInitiated
    debug
pulsout C.1,100
goto SoundAlarmsInitiated


SilenceInitiated:
debug
    IF b0 = "3" THEN GOTO ResetInitiated
    high C.1
    IF b0 = "3" THEN GOTO ResetInitiated
    pause 100
    IF b0 = "3" THEN GOTO ResetInitiated
    low C.1
    IF b0 = "3" THEN GOTO ResetInitiated
    pause 100




goto SilenceInitiated


ResetInitiated:


low C.1


goto start0
 
Last edited:

nick12ab

Senior Member
You're not using the hserin command correctly.
For X2 parts

HSERIN spaddress, count {,(qualifier)} HSERIN [timeout, address], spaddress, count {,(qualifier)}

Qualifier - is an optional single variable/constant (0-255) which must bereceived before subsequent bytes can be received and stored in scratchpad

Spaddress - is the first scratchpad address where bytes are to be received

Count - is the number of bytes to receive

Timeout - is an optional variables/constants which sets the timeout period inmilliseconds

Address - is a label which specifies where to go if a timeout occurs.
What you you mean "preferably for no baud rate"?
 

rs2845

Senior Member
What you you mean "preferably for no baud rate"?
^^^ That sentence didnt make sense. Just meant that I want to use N4800 baud. Editing now.


Well, I adapted the example given on the Picaxe Commands page. So what am I doing wrong?

My £900 computer is failing me at the moment. I'll take a screenshot when it pulls its finger out.
 

rs2845

Senior Member
I've tried both, it just so happens that example 2 on the link was the other one I tried.

I've even checked the datasheet.

Again, what am I doing wrong?
 

rs2845

Senior Member
The hsersetup command. Only I changed the baud rate and the bit to not use scratchpad.

Any ideas? Something I can try?

All I want is background serial at N4800 baud rate and it to save into w1
 

rs2845

Senior Member
Well I tried without the brackets and the 0,4. Even then, if it was mandatory I would see values in the hserptr field of my debug window which I never did.


Going to try now. Hopefully it works!
 

hippy

Ex-Staff (retired)
I have to use Hserin because the program freezes, and it needs to receive data into b0-b3 in the background

hsersetup B2400_4,%00110

hserin b0,b1
The baud rate should be B4800_8 for a 20X2 though B2400_4 will effectively be the same.

For HSERIN you have the command wrong. The full format of that is -

HSERIN [timeout, address], spaddress, count {,(qualifier)}

To read four bytes that would be -

HSERIN 0, 4

And that puts the four bytes into scratchpad so you have to transfer those into variables using GET ...

HSERIN 0, 4
GET 0, b0
GET 1, b1
GET 2, b2
GET 3, b3

This form of background receive is not as flexible as full background receive; the HSERIN will wait until all four bytes have been received before the command continues.
 

rs2845

Senior Member
Basically, what I am trying to achieve is for my Picaxe 40X2 to send data to my 20X2 (this is working), but with the use of IF statements, the 20X2 should only respond to particular data from the 40x2.

I need this to happen very fast. @Hippy, like you say above is not as flexible- how could I achieve what I am wanting? The data may end up being 4 characters in length (its alphanumeric).

I had a go but for some reason there was a "1" in the hserptr debug field and the actual data being sent wasn't that in the scratchpad.

For this project, it's vital that the data doesn't get "missed".
 
Last edited:

hippy

Ex-Staff (retired)
You could use full background receive.

Code:
#Picaxe 20X2
HSerSetup B4800_8, %00111
Do
  Do : Loop Until ptr <> hSerPtr : b0 = @ptrInc
  Do : Loop Until ptr <> hSerPtr : b1 = @ptrInc
  Do : Loop Until ptr <> hSerPtr : b2 = @ptrInc
  Do : Loop Until ptr <> hSerPtr : b3 = @ptrInc
  SerTxd( "Got ", #b0, " ", #b1, " ", #b2, " ", #b3, CR, LF )
Loop
 
Top