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.

Low power bootloader circuit- is it possible?

Status
Not open for further replies.

Oznog

Active Member
I would like to build a bootloader for a PIC18F252. I am not aware of any electrical differences between that and a PIC16 bootloader though.

So I look into this and all the circuits I found use some version of the MAX232, which has an idle current of 10mA. This is too much of a load when the chip goes into sleep mode.

Now I saw other Maxim converters have a shutdown mode, but I'm not sure how to use it even if the chip is compatible. I.E. if it puts the 232 into shutdown when going to sleep, then it's obviously not going to be possible to program it at that time. I might be able to guarantee that we're going to wake it before trying to program, but with purely software control, don't we have the risk of a bad programming cycle leaving the system stuck with the 232 shutdown, thus unrepairable?

Plus, while loading, does a bootloader guarantee to tristate the pins? If so, I can put a pullup resistor to make sure shutdown isn't enabled while programming. If they're not specified then I'm probably screwed.

So:
1. Is there any way for the incoming RS232 signal to disable the shutdown through hardware components?
2. Does anyone have a bootloader schematic which has a low power RS232 converter?
3. Does bootloader execution guarantee pins will be tristated?
 
Oznog said:
1. Is there any way for the incoming RS232 signal to disable the shutdown through hardware components?

You could always feed the MAX232's power from the PIC, presuming it doesn't require more than 25mA - in which case you could use a PNP switching transistor. Also, there's no need to have the MAX232 as part of the target system - it could be part of the plugin bootloader lead - so only uses power when loading.

2. Does anyone have a bootloader schematic which has a low power RS232 converter?

If you do a websearch there are lots of bootloader designs, some use MAX232's and the internal USART, others use simpler interfaces and software UART's. But see the answer above, you don't really need a lower power one.

3. Does bootloader execution guarantee pins will be tristated?

A bootloader is simply a software program running on the PIC, you can make it do anything you want!.
 
The problem's not that the PIC can't supply the current! The current is going to drain the battery over time. But yes, switching off the supply is fine too if the PIC were to do it.

I'm familiar with the external bootloader dongels, but I'm trying to avoid making two pieces out of it. I probably should have mentioned that.

I've gone so far as to consider putting on a jumper or button to guarantee the MAX232 could be powered if the software wasn't cooperative.

So has anyone figured out if a single high on the serial data in could immediately disable the shutdown, while charging a cap to ensure that it will stay out of shutdown for a decent period of time to ensure it will be able to read in all the data before discharging and going back to sleep? That would be ideal.
 
Oznog said:
The problem's not that the PIC can't supply the current! The current is going to drain the battery over time. But yes, switching off the supply is fine too if the PIC were to do it.

If the MAX232 is powered from a PIC pin, or the power to it is switched with a transistor from a PIC pin, it won't drain the battery at all.

I'm familiar with the external bootloader dongels, but I'm trying to avoid making two pieces out of it. I probably should have mentioned that.

I can't say I understand the reasoning behind it - after all, you already have a seperate lead for bootloading - the MAX232 just becomes part of the lead. But that's your decision!.

So has anyone figured out if a single high on the serial data in could immediately disable the shutdown, while charging a cap to ensure that it will stay out of shutdown for a decent period of time to ensure it will be able to read in all the data before discharging and going back to sleep?

You seem to have totally the wrong idea about how a bootloader works, there's no requirement for anything like that to happen.

A bootloader usually works when the PIC first powers up, it jumps to the bootloader routine which waits for a specific byte from the serial port, if it doesn't receive this byte within a fairly short time the bootloader routine exits and runs the normal program at the bottom of memory. If it receives the specified byte from the serial port it sends an acknowledgement and the transfer takes place. Once the program has been transferred, the bootloader code executes the program - exactly the same as if it never found the initial serial byte.

So for your purposes, turning the MAX232 on and off from a PIC pin, you would simply need to make the first action of the bootloader code the turning on of the MAX232, and it's last action (before running the transferred program) turning it back off.

There are other ways of running a bootloader, where you have a button which you press to initiate a transfer, but this wastes an I/O pin - but in any case you could turn the MAX232 on or off in that code as well.
 
Dongle: I'd like to eventually sell this as a software-upgradeable product to end users who aren't going to build one themselves. It's a lot of extra cost relative to adding $2 of chips & caps on the board, and half the people are going to lose them. That's the problem.

Software control of MAX232 power: The problem is, if it's switched by the PIC, then a bad programming cycle (somebody trips over the cable, battery was low, etc) will leave the bootloader code intact, but the program code is screwed. So, you reset the system and it tries to execute the nonexistant program code, which doesn't know to enable the MAX232 anymore. The bootloader, which could have reenabled the MAX232, will not execute without the MCLR signal from the MAX232!

At that point, there's no valid program code, the MAX232 may be off, and the bootloader can't run so the part cannot be reprogrammed via bootloader to get valid code in there again. i.e. the box is toast until we pull the chip and put it in a PIC programmer.
 
MAX3232E should do it

Maxim's MAX3232E should do it. It's pin-compatible with the MAX232 but uses "AutoShutdown"

It doesn't use a shutdown pin, but rather automatically goes into shutdown whenever the cable is disconnected (Vin <3V && Vin>-3V), and the supply current drops to 1uA.

Recovery is automatic, and without glitches. It does consume power if the cable's left in with a device on the other side, but I don't think that's an issue in this case. There's an "AutoShutdown Plus" feature that Maxim has in other parts that also goes low power if there's no transitions for awhile, and recovers when they begin again, but it's still transparent from the TTL side.
 
Oznog said:
Software control of MAX232 power: The problem is, if it's switched by the PIC, then a bad programming cycle (somebody trips over the cable, battery was low, etc) will leave the bootloader code intact, but the program code is screwed. So, you reset the system and it tries to execute the nonexistant program code, which doesn't know to enable the MAX232 anymore. The bootloader, which could have reenabled the MAX232, will not execute without the MCLR signal from the MAX232!

A couple of points here, firstly the bootloader code always runs first, so even if the program code was corrupted the bootloader code would still run exactly as before. The MAX232 switching would be part of the bootloader code, so it wouldn't be a problem. If something trashes the bootloader code itself, you are stuffed in either case, and would need to reprogram the bootloader code in a PIC programmer.

Secondly, MCLR isn't used for bootloader programming - the PIC isn't set to programming mode at all, it's all done internally.

So having a permanently powered MAX232 has no advantages for bootloading at all!.
 
:idea:

Just thought I would add to a comment that Nigel made, my bootloader code (for the 18F452) looks for a 16 byte command string (to enable bootloader mode), just before the bootloader re-progs the first location on the pic it stores a value in the eeprom of the part.

When the pic first powers up, it check this location, if the value is set to "bootloader" mode, it just sits in the bootloader until power off.

This means that if the programming all go's "Iffy" then the PIC will still allow another re-program to take place.

btw, is this a "hobbyist" progject? If so, bin the max232 and use the 10k resistor "max232" that I keep ranting on about, you will have to code a s/w UART to use this, but I can post this if people are interested.

Hope this helps!
 
Matt(Pic progger) said:
btw, is this a "hobbyist" progject? If so, bin the max232 and use the 10k resistor "max232" that I keep ranting on about, you will have to code a s/w UART to use this, but I can post this if people are interested.

If the pic has a hardware usart, then why not use it? Like Nigel said, the pic can turn on/off the max232, so that isn't the problem. It seems to me that Oznog doesn't really understand how a bootloader works...

For the '10K MAX232' you talk about I regret to inform you that i have encountered several PC's where the setup failed to work, and not only older ones... So if one wants it to work on all Pc's (specially laptops) then the direct connection is out ...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top