Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC18F24K22, Rx2/Tx2 and ICSP

Status
Not open for further replies.

For The Popcorn

Well-Known Member
Most Helpful Member
I want to use Rx2 and Tx2 on a PIC18F24K22 with a CH340 UART/USB chip. This UART uses RB6 and RB7, the same pins as ICSP. This is a problem because Tx holds the pin high (or is it low) at idle, so the CH340 is going to prevent ICSP working. Am I right in this thought?

I'm leaning towards a pair of jumpers to disconnect the CH340 during programming. I suppose I could add a couple logic gates so that using either/or interface would work, but that seems needlessly complex, at least after the code is developed.

Any suggestions?

Also, any suggestions for a PIC18F bootloader?
 
Solution
The 18F25K22 also has an internal programmable pull-up resistor (around 20k) that can be programmed with the WPUB register. Fortunately the programmable pull-ups are only on PORTB which encompass RB6(CLOCK) and RB7(DATA).
As I start searching boot loaders...do any of them work with UART2?
 
Well you could isolate the CH340 with a diode - one should be enough, on the RX side. Or, just use a better PIC, there are numerous slightly more modern 18F devices with better facilities, including PPS, which allows you to move peripherals to various different I/O pins. My personal favourite is the 18F27K42.

I don't use a bootloader, really there's little point - but I see no reason why one couldn't use UART2, just alter the source code for it - a bootloader is just a program that runs before the main program.
 
Ahhh. Great call on the diode! I've used that trick in the past. Thanks for the suggestion.

I have a bunch of 18F25k22s from a project that went nowhere. Most PICs are zero stock anywhere. Crazy times.
 
Well you could isolate the CH340 with a diode - one should be enough, on the RX side
I don't see that working. The TX output of a uart (ie CH340) idles high when not in use.
The ICSP interface has a 4.7K pulldown on the PGC/PGD pins, and must be able to drive these signals high and low.

In the idle state with the CH340 driving the line high, the ICSP PGD control line (RB7/RX2) would be trying to short the output.
 
I want to use Rx2 and Tx2 on a PIC18F24K22 with a CH340 UART/USB chip.
A high value series resistor in line with RXD data, eg. 100K ??

That should still work with the PIC pin in input mode, but hopefully not affect the ICSP connection.
TX should not matter, the serial port will just output garbage while programming or debugging.
 
I think this could work. An 18F with a 5v supply will interpret < 0.8 volts as a LOW. An ICSP programmer has a 4.7k pulldown resistor. As shown, a 24.9k pullup resistor will result in a low level of 0.8 volts.

When the ICSP is disconnected, the 24.9k resistor should pull high to make the UART work.

Oops. The diode is reversed.

icsp + ch340.jpg
 
The 18F25K22 also has an internal programmable pull-up resistor (around 20k) that can be programmed with the WPUB register. Fortunately the programmable pull-ups are only on PORTB which encompass RB6(CLOCK) and RB7(DATA).
 
Solution
I don't see that working. The TX output of a uart (ie CH340) idles high when not in use.
The ICSP interface has a 4.7K pulldown on the PGC/PGD pins, and must be able to drive these signals high and low.

In the idle state with the CH340 driving the line high, the ICSP PGD control line (RB7/RX2) would be trying to short the output.
That's why you put the diode the right way round :D
 
I think this could work. An 18F with a 5v supply will interpret < 0.8 volts as a LOW. An ICSP programmer has a 4.7k pulldown resistor. As shown, a 24.9k pullup resistor will result in a low level of 0.8 volts.

When the ICSP is disconnected, the 24.9k resistor should pull high to make the UART work.

Oops. The diode is reversed.

View attachment 138542
Looks like your diode is the wrong way round?.
 
Crazy resistor value? The 18F24k22 will interpret either 1.0 volts or 0.8 volts as LOW (depending on whether the pin is TTL or Schmidt trigger, when operating on 5 volts). When the ICSP programmer is idle, the 24.9k resistor to +5v and the programmer's 4.7k to ground form a voltage divider, with the resulting voltage being 0.8 volts, which will be read as LOW. When the programmer drives the line high, it just has to overcome its pull down resistor as usual.

The CH340 will only be active when the ICSP is not connected. The CH340 can only pull the pin low via the diode (which I noticed was backwards when I posted the schematic and did note) and otherwise the "crazy resistor" will pull the pin high.
 
24.9K ohms is a 'crazy' value, 47K, 100K - all perfectly good in this application, and 'sensible' values :D

Logic levels are ABOVE or BELOW specific values, not between two close values - aiming for 0.9V is really bad, as you're aiming for an extreme operating point of the device. You want it BELOW 0.8V, not anywhere near it.
 
I'm not aiming for between 0.8 and 1 volts. I don't know if the port pin is a TTL input or a Schmidt trigger input, so I'm aiming for the lowest possibility.
 
I'm not aiming for between 0.8 and 1 volts. I don't know if the port pin is a TTL input or a Schmidt trigger input, so I'm aiming for the lowest possibility.
The lowest possibility is zero volts, 0.8V is the highest possibility - it's just a pullup resistor, nothing critical at all, I'd have just stuck 100K in there. The internal pull-up would be OK (they aren't actually 'resistors') as they are usually suggested to have an equivalent of about 200K - however, I'm not sure the internal pull-up's apply to the port when it's set to RXIN.
 
I don't know if the port pin is a TTL input or a Schmidt trigger input, so I'm aiming for the lowest possibility.
According to the datasheet Table 1-2, the pin is a schmitt-trigger type (ST) when used as the uart input and TTL when it's "regular IO".

That's pretty typical of most PIC's that don't have an INLVL register to let you select the type... ST for peripherals, TTL for IO.

You can use the programmable pullup in either case
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top