28X1: sertx question

Jeremy Leach

Senior Member
Hello all ...long time no post

Fiddling around with background receive on a 28X1. Leg17 (Input 6, also serTx) I was originally using as a switch input before trying background receive.

I then run the Hsersetup command in order to start background receive - and it all receives fine.

BUT ...I then realise that Leg17 is now set as an output. I'm assuming that by issuing the Hsersetup command that leg is automatically configured as the hardware serial output regardless of whether it's going to be used to transmit or not.

Is this correct? And is there any way of keeping it as a switch input while using background receive? I doubt it, but just asking.
 

hippy

Ex-Staff (retired)
Welcome back Jeremy !

The PICmicro datasheets might have to be checked for this. Sometimes the PICmicro will force the direction of a pin regardless of what anything else calls for, other times not, and sometimes the datasheet is not correct in what it says will happen or is a prerequisite for it working.

What it boils down to is whether enabling the AUSART overrides TRISx or TRISx overrides the AUSART.

That worked to my advantage when doing something on one PICAXE because setting a mode made what was a fixed input an output or vice-versa despite the datasheet saying not possible. On another PICmicro the same trick didn't work.

I'll have a read of the datasheet and see what I can find.
 

ylp88

Senior Member
With pretty much all PICmicros, enabling the serial port will override any TRIS, PORT or LAT settings.

16F887 Datasheet said:
When the SPEN bit is set the TX/CK I/O
pin is automatically configured as an
output, regardless of the state of the
corresponding TRIS bit and whether or not
the EUSART transmitter is enabled. The
PORT latch is disconnected from the
output driver so it is not possible to use the
TX/CK pin as a general purpose output.
ylp88
 

hippy

Ex-Staff (retired)
What ylp88 quotes looks to be the same in the 16F866 datasheet I have, although the diagrams for the Port pin don't reflect that override ( they do for other pins ) .

For the PICAXE-18 ( 16F627 ) the datasheet says; "Bit SPEN (RCSTA<7>), and bits TRISB<2:1>, have to be set in order to configure pins RB2/TX/CK and RB1/RX/DT as the Universal Synchronous Asynchronous Receiver Transmitter" - That's not true because output works with TRISB<2> clear, the AUSART overrides TRISB<2>, but there's no override for TRISB<1>.

I think you probably are stuck with TX becoming output once HSERIN is enabled but it's worthwhile poking TRISx and also clearing TXEN to see how it does behave. You may get lucky.
 

Jeremy Leach

Senior Member
Ok, thanks very much for taking the trouble. It looks like I'm going to have to shift my switch to another input - certainly sounds the safest thing to do.

I've had a narrow escape from frying the picaxe: The switch pulls a resistor low, leg17 has been made an output by Hsersetup and defaults to low output state, so I've been pressing the switch which has been connecting this output to ground - not good, but at least the output isn't high !

I think perhaps Technical could add a line in the manual just to clarify this behaviour, because to be honest I'd never thought about this happening, because I was only interested in receiving not transmitting.
 

ylp88

Senior Member
Actually, the PIC16F886 is the datasheet I was quoting from - my finger must have slipped...

ylp88
 

hippy

Ex-Staff (retired)
I've had a narrow escape from frying the picaxe: The switch pulls a resistor low, leg17 has been made an output by Hsersetup and defaults to low output state, so I've been pressing the switch which has been connecting this output to ground - not good, but at least the output isn't high !
High should be the idle state when HSERSETUP is enabled. Sounds like a lucky choice of mode in the HSERSETUP command. IF not there could be some more investigation needed.
 

Technical

Technical Support
Staff member
hsersetup does control and override both tx and rx at all times, they are always used together.
 
Top