News:

Let's find out together what makes a PIC Tick!

Main Menu

Using a Max232 to add an extra input?

Started by Peter Truman, Nov 30, 2023, 10:34 PM

Previous topic - Next topic

Peter Truman

Hi All - I find myself in a pickle with a project that will need an additional input over what I have already provided.

PIC 18F25K22

This project normally has 1 digital and 1 analogue input, because that is generally all it needs (PCB's already made). However, I have come across a situation where I need an additional input (from a panel switch). I don't want to hack the hardware too badly if I can avoid it, at the same time, the additional input needs to be quite robust and immune to glitches.

The PCB has a MAX232 with an external 3.5mm socket which is used at the commissioning stage just to set a few parameter - beyond that it is redundant.

Here's my thinking. Sticking with the current hardware, I could just look for a serial input for the first few seconds after power up (bit like a bootloader) - if I don't see any activity on the UART I can assume there is no configuration changes required. From then on I would like to use the RX2 pin as an input for the panel switch (on the RS232 side).

So I would just make up a cable with a 3.5mm plug on one end and a panel switch on the other end. The panel switch would be either floating (or pulled high) or grounded. So I would expect to see 5v on RX2 or 0v depending on the state of the panel switch.

I realise I probably need to do some experimenting here but, I thought I would check to see if this seems sensible or not.

The basic question is - once I setup the UART to receive data on RX2 can I subsequently abandon that (after the first few seconds from power up) and use that pin as a simple digital input?

If that seems possible - does anyone know what I should expect on ROUT1 with RIN1 disconnected? (I could just add a pullup/down but I prefer not to if I can avoid adding any parts on the board.

Any advice is appreciated.

tumbleweed

Something like that is workable... you can disable the UART (or just read the state of the input pin) when you want to use it that way.

The MAX232 has a 5K pulldown to GND on the RINx input (3K-7K ohms per the datasheet), so with the inversion that provides a logic high output on ROUTx pin with nothing connected to RINx. That's the idle state for a UART input/output. If you power up and enable the UART, if the PIC sees a low on the RX input pin that is the same as a serial BREAK condition.

Since the switch is on the RS232 side, you'll have to have it supply a high to tell the difference between open/closed.

If you leave the UART enabled the IO pin will be in Schmitt-trigger mode, so you'll need to supply > 0.8xVDD to be seen as a logic high, so you'll need a pretty stiff pullup, something < 750 ohms or so should do since the RIN pulldown could be as low as 3K.

I suppose you could just switch in 5V and skip the pullup, but I never like doing that.

Peter Truman

That is marvelous - easily achievable in this scenario.

Thanks very much for your help

tumbleweed

You can forget that part about the PIC IO pin voltage... don't know what I was thinking when I wrote that, but since you'll be going into the MAX232 RIN pin, it only needs >2.4V to be seen as a logic high.

Since the MAX232 RIN pulldown could be as low as 3K, that means that at 5V you could use anything less than about 3K for a pullup value (1K-2K would give you plenty of margin).