28X2 'Disconnect' issues - digital I/O or not?

whiteoaks7

New Member
Okay, a lot of this has been gone through so forgive me but let me see if I've got this right. I want to use the Serial In pin (leg 6) on the 28X2 as a digital (binary) input. To do this I have to: (1) issue a 'disconnect' early in the program (2) ensure the pin is LOW before the disconnect is invoked. After this I can use the pin as a normal I/O it seems, however: (a) the simulator doesn't allow me to enter an input (the box displays a red RXD presumably to indicate the normal rxd is inhibited) (b) while part 1 of the manual tells me I can use the pin as digital I/O part 2 tells me I can only use it as a serial input (albeit serial under my control, not the processor's). Which is right? :confused:

Cheers
 

hippy

Ex-Staff (retired)
The download Serial In on the 28X2 does not have a port.pin designation so cannot be used as a digital input for measuring high, low, pulses etc. It can however be used to receive serial input using the SERRXD command ( a preceding DISCONNECT is optional for SERRXD as it performs a DISCONNECT itself ).

This program should work under Simulation, does for me when tested...

#Picaxe 28X2
Do
SerRxd w0
SerTxd( #w0 )
Loop
 

Wingrider

New Member
I know this is an old thread but here goes.

Hippy you state that a preceding DISCONNECT is optional for SERRXD as it performs a DISCONNECT itself.

This was using an 08m2 and a serrxd command.

Until I used the Disconnect command the program would reset under certain conditions when it shouldn't. So my question is is the
Disconnect command really optional.

The program just waits for a serial input before sending an enter command. If the serial command is absent for
a couple of seconds it will resend the Enter command. Under certain known conditions with out loss of signal the program
would reset and send the enter command until I added the Disconnect at the beginning of the program.


Code:
    Disconnect
    low Serial_line                      ' Close serial line relay
    low speed   
    let Looplimit = 250                  ' preload time out for Reverse loop
    setfreq M4   

    hsersetup 51,%0010
    Main:                 			  ' Run at startup
      No_Serial_Data: 
      serrxd [2000,No_Serial_Data],($10)	' wait for data if time out acknowledge Screen
      	  	  			      ' No serial data received
      pause 3000
      gosub Enter           			 ' Enter command routine
      low Serial_line                      ' Close serial line relay
      low speed      
      gosub Lockout_Override:
   end
    
    Lockout_Override:                              ' Main loop

       Do
         serrxd [1000,No_Serial_Data],($10)	   ' wait for hex 10 
         If Switch = 1 then                        ' button pressed
              LoopCount = 0                        ' reset time
         else   
            Count Speedsense_in,500, Speed         ' Read Speed_sence_in C.1
            If Speed > 5  then                     ' Moving
                gosub RVS_Override                 ' Override routine
            endif   
         endif
         low speed_sense_out                       ' Close Speedsense Relay    
       loop
     return                            		   ' End of main program
 

Technical

Technical Support
Staff member
Its optional until the very first time the RXD pin receives input data. By that time it needs to have had either a serrxd or a disconnect applied.

Also don't use an end, use stop instead. It might reset after the end (which is a permanent low power sleep).
 

Wingrider

New Member
Thank you for the reply but it doesn't receive input data until after the rxd command this was verified with a scope.
The resets wouldn't start until long after the chip had received the first $10 and sent the enter command. And it wasn't
the power supply it is as clean as you can get, no glitches and ripple under 10 mv.

Also I will change the end to stop but that line should never be reached under normal use.

Sorry but I fought this for three months and the only thing that fixed the problem was the disconnect.

Again thank you for your response.
 

Technical

Technical Support
Staff member
You probably have some gosub stack errors causing an eventual reset, as your program flow is wrong. Then, as the chip has reset, you end up back in the top code again which is why the disconnect makes a difference.

The error is this: you gosub into Lockout_override, but then on a serrxd timeout 'goto' back up out of the gosub before gosub'bing into it again.

Hence on every timeout you incorrectly loose a return, and after this happens 8 times your program will crash and reset. To fix this your serrxd timeout needs to point to a return command.
 

Wingrider

New Member
Technical

Thanks I knew that part of the Lockout_override was no good but had a hard time figuring out
how to fix it. I just fixed it by adding a loop.
 
Top