Serin receiving into scratchpad on 28X1

Simmicht

Senior Member
No Problem here but an example for others.

I have two serial devices attached to a 28Xx chip and I wanted
to have both data streams end up in the scratchpad.
With only one HSSERIN (pin 18) I tried the following with good results.;)

I am using the same pin 18 as the HSSERIN here for testing
but I can now use one of the other 0 to 6 (pins 11 to 17).
I tested up to 40 characters incoming at once.
The line should accept up to 80 which will suit the final NMEA string input.
The long SERIN command does play up with the code box...

Code:
#picaxe 28X1

#terminal 4800
#no_data
#no_table
setfreq m4

mainsl:

ptr=0
SERIN [1000,nodata],7 , T4800_4 ,("$"),@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc

nodata:
IF ptr=0 THEN nothing

sertxd(#ptr," ")
B1 = ptr - 1
ptr=0

SERTXD("$")
FOR B0 = 0 TO B1
  SERTXD(@ptrinc)
NEXT
    
GOTO mainsl
    
nothing:
sertxd (".")
GOTO mainsl
 

inglewoodpete

Senior Member
The X1 and X2 chips also give you the option of receiving the incoming serial in the background. This eliminates the chance of data arriving when your foreground code is doing something else (like processing a receive timeout!).
Code:
#PICAXE 28X1
'
        'Output pin is PortC 6 (Leg 17) (Fixed)
        'Input  pin is PortC 7 (Leg 18) (Fixed)
        '
Initialise: SetFreq m8                     '(Doesn't have to run at 8MHz)
            HSerSetup B9600_8, %01         '%ab where a=0 No invert;  a=1 Invert transmit;
            '                                     and b=0 Foreground; b=1 Background Receive
Main:       HSerOut SendNoBreak, ("Waiting...", CR, LF)
            HSerPtr = 0                    'Reset (background) write pointer
            HSerInFlag = 0                 'Reset reception indicator
            Ptr = 0                        'Reset read pointer
            @Ptr = 0                       'Clear the first scratchpad location
            '
            Do
                If HSerInFlag = 1 Then     'Only when there is an incoming character (or string)
                   'process the incoming serial data
                   Ptr = 0
                   b2 = @ptrinc            'Fetch a character
                   '
                   ~do what needs to be done with the incoming data
                   '
                   HSerPtr = 0                    'Reset (background) write pointer
                   HSerInFlag = 0                 'Reset reception indicator
                End
                ~do all the other things when no data is being received
            Loop
 
Top