PDA

View Full Version : HSERIN and HSEROUT Pins



Dick Ivers
- 22nd February 2014, 00:39
I would like to use pins RB1 and RB5 in a multiplex fashion on a 16F1826. I have used hardware serial comms before sucessfully, but the layout of my board is now forcing a pin sharing situation.

The code set up is as follows:


'The following DEFINES are for EUSART at 16 mhz 2400 baud
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 130 ' 2400 Baud @ 16MHz, 0.0%
SPBRGH = 6
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

APFCON0.7 = 0 'rx on RB1 (16f1826)
APFCON1.0 = 1 'tx on pin RB5 (16f1826)

Serial communications are used early in my program. The TX and RX hardware pins are also connected to open switches. This should work OK, the switches are open. Later, I want to use the switches, and they will be closed some of the time, but there is no call for serial comms. at that point.

Do I have to disable the HSERIN and OUT hardware to use the switches? How to do this? Looking at the manual I see there is a Register RCSTA and it has a Serial Pin Enable function on pin 7. Will clearing this pin allow me to uses the switches?

Dick Ivers
- 2nd March 2014, 00:47
The following notes are to close out this thread. The findings here are available for future reference.

I tested the above question with actual hardware. The answer is yes, you can multiplex the hardware serial port pins. The pins can be enabled and disabled inline thus allow multiple usage.


'The following DEFINES are for EUSART at 16 mhz 2400 baud
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 130 ' 2400 Baud @ 16MHz, 0.0%
SPBRGH = 6
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

APFCON0.7 = 0 'rx on rb1 (16f1826)
APFCON1.0 = 1 'tx on pin rb5 (16f1826)

'use the hardware serial port in this space. The switches connected to rb1 and
'rb5 pins are open, so no effect on communications

RCSTA.7 = 0 'disable hardware serial port (SPEN = 0)
TRISB = %11100010 'refresh portb register

'no communications needed in this space. The switches are active open and close.

Andy Wood
- 2nd March 2014, 21:08
Hi Dick,

I have often wondered this myself but hadn't got around to any testing. Thanks for the information.

Andy