📜 ⬆️ ⬇️

A simple in-circuit programmer LPC microcontroller. Features in-circuit programming. Part two

In my first article I described a simple programmer circuit , today I will tell you how to connect it to a programmable device.

Fig. 1. The appearance of the programmer.
In the good old times, when microcontrollers with flash memory of programs based on FLASH were just beginning to appear, they were programmed via a parallel interface. At the same time, more than 20 outputs could be used for programming and it was often necessary to use an increased voltage of 12 volts or more. Microcontrollers were then produced in pinouts DIP enclosures. They were programmed mainly by inserting them into high-quality programmer sockets, and only then they were soldered into the device. However, over time, the transition to programming via the serial channel began, with only 4-5 signal legs already being used for programming. In addition, the chips were made in a completely exotic buildings. Reliable panels for such cases sometimes could cost almost more than the programmer itself! Now it is possible and necessary to reprogram microcontrollers without soldering from the circuit - in-circuit programming. This is very convenient for debugging the program. In addition, it became possible to make the installation of the entire board, and programming should be carried out when setting up and releasing the device. This is especially convenient when working with contract manufacturers - there is a guarantee that no code leak will occur.
Today, most devices on microcontrollers use in-circuit programming. For illustration, consider the LPC2xxx microcontrollers.
These microcontrollers have a built-in bootloader that allows flash memory to be flashed by in-circuit programming. Serial port 0 is used for data transmission - RXD0 and TXD0 pins. The algorithm for entering the programming mode is very simple; for this, only two additional signal legs are used - P0.14 and Reset.
Port P0.14 is set to a low logic level, in other words, it closes to ground, while the Reset pin must have a high logic level. It is worth noting, however, that exceptions are possible if a user program was previously run, for example, in which the watchdog timer was activated. Therefore, the most reliable algorithm for entering the microcontroller into the programming mode is as follows.
Before turning on the power, close pins P0.14 and Reset to ground. Apply power, wait until it reaches the nominal value. Transfer Reset to a high logic level, wait at least a few milliseconds and submit a high level to P0.14.
To successfully use this feature, you need to follow a few uncomplicated rules that are easier to demonstrate with an example of a programmer connection circuit to a device based on a microcontroller from the LPC 214x series. For programming, we will use the programmer described in the last article.

Fig. 2. Wiring diagram of the programmer.
Let's begin the review of the scheme. P0.14 port is pulled to power with the help of resistor R4, so that when the device is turned on in normal mode, a high level appears on it and, accordingly, the user program is started. In the LPC_RESET circuit, there is a pull-down register for power and a capacitor to ground. For normal operation, their ratings must be selected depending on the power source used. The fact is that when the device is connected to power, the voltage on it reaches the nominal value not instantaneously, but gradually, as the filtering capacity is charged. For normal operation of the device, it is necessary that the microcontroller start up only when a certain power level is reached, special circuits are provided for this in modern microcontrollers, but rely on them and don’t make it - as practice shows, with a slow increase in the supply voltage, these schemes may not work correctly. At the moment when the supply voltage is applied, the capacitor C2 starts charging and the voltage on it is kept for a while at a low level. It is desirable to select the circuit ratings of R5, C2 in such a way that a high level at the RESET input does not appear before the power supply voltage of the microcontroller reaches a voltage of 2.6 volts.
The programming process takes place at a low level at the RESET input, with all the I / O ports of the microcontroller being converted to a high-resistance state. If the ports of your microcontroller are used to control any nodes, for example, power switches or controlled voltage regulators, they must be tightened to the required logic level during programming, otherwise big troubles can occur, even the board itself and the devices it controls fail.
In our example, the zero COM port is used not only for programming, but also for data exchange via the RS485 interface. For this is the node on the chip D2. Usually, the D2 chip is constantly switched to receive mode, while it generates a signal at the RXD input of the microcontroller. In programming mode, this signal will interfere with the programmer, so that this does not happen, the resistance R1 and R3 are provided in the circuit. R1 puts the D2 receiver in an inactive state — the R0 output goes into a high-resistance state and does not interfere with data transfer to the programmer, and R3 turns off the transmitter so that incorrect data is not received through the RS-485 driver of the interface.
If you intend to use sufficiently long wires for programming, or there is a possibility that the device may be reprogrammed by users who do not have sufficient qualifications, you should worry about protecting the programmable microcontroller from static and voltage surges. I, for example, had a case when the device had to replace the microcontroller 4 times due to Krivorukov “programmers”! The simplest protection can consist of diodes or zener diodes that limit the voltage and resistors connected in series with low resistance. For example, as shown in Figure 3.

Fig. 3. Connection diagram of the programmer with protective circuits.
It remains to add that for programming microcontrollers of the LPC2xxx family based on the ARM7TDMI core, pin 3 of the programmer is connected to port P0.14. To program the microcontrollers of the LPCxxx family based on the ARM7 Cortex core, pin 3 of the programmer is connected to port P2.10.
The topic of programming microcontrollers and other devices, despite the apparent simplicity, is very multifaceted and full of nuances. However, for our case
It remains to talk about the software and programming features of the LPC900 series.
PS This article is intended mainly for beginners, so I apologize for possibly explaining some obvious things to the pros in too much detail.

')

Source: https://habr.com/ru/post/164381/


All Articles