Then let's get to the topic: STC12 series download frame format:
Introduction to the protocol frame: The main components are as follows
Head |
Sign |
Reserved |
Length |
Frame |
Data |
Checksum |
Trail |
Detailed description of each filling area:
name |
length |
Function |
Head |
2-Byte |
Packet header (0×46, 0xB9) |
Sign |
1-Byte |
Identification (0x6A or 0x68) |
Reserved |
1-Byte |
Reserved area (filled with 0x00) |
Length |
1-Byte |
Total length of (Head + Length + Frame + Data |
Frame |
1-Byte |
To distinguish different frames |
Da |
0~0x8A Bytes |
data |
Checksum |
2 Byte |
Checksum |
Trail |
1 Byte |
Packet tail (0×16) |
As for Cmd's protocol response and the like:
Command Description MCU responds
7F Boot MCU into ISP and measure clock 50 MCU option information
50 Set MCU model, etc. 8F Response
8F New baud rate test 8F Test response
8E Formal baud rate change 84 Baud rate change response
84 File capacity, erase chip 00 Response
00 Download program 00/30 Response checksum, success or failure
30 Re-download program 00/30 Response checksum
69 Model, etc. 8D Response
8D Set Option 50 Answer Option
82 Exit Restart to enter user program
As for the interaction process, it is also very simple, it just depends on the reaction speed of your device. This is why some PL2303 line downloads often make mistakes , but at least it works well here.
PC -> 0x7f -> MCU
MCU -> Information -> PC
PC -> Verify? MCU model -> MCU
MCU -> Baud rate change request -> PC
PC -> Baud rate test -> MCU [At this time, calculate the reload value to switch the baud rate]
MCU -> Success/No response -> PC
PC -> Baud rate setting -> MCU [Switch to the lowest baud rate
MCU -> Success/No response -> PC [Switch to data baud rate
PC -> Erase chip -> MCU
MCU -> Success/No response -> PC
PC -> 0x80 bytes of data -> MCU
MCU -> Verification code -> PC
Loop until end of file
PC -> Settings? Model -> MCU
MCU -> Success/No response -> PC
PC -> Settings -> MCU
MCU -> Success/No response -> PC
PC -> Programming completed -> MCU
The checksum algorithm is to add up all the contents marked in the data area and take the lower sixteen bits. See the program:
01 | PUBLIC FUNCTION CheckSum(buff AS String, start AS Integer, endchr AS Integer) AS String 'Return two words |
02 | DIM i AS Integer |
03 | DIM chkSum AS Long |
04 | DIM lo AS Byte |
05 | DIM hi AS Byte |
06 | DIM tempStr AS String |
07 | chksum = 0 |
08 | FOR i = start TO endchr |
09 | chksum = chksum + Asc(Mid(buff, i, 1)) |
10 | NEXT |
11 | hi = Shr(chksum AND &HFF00, 8) |
12 | lo = chksum AND &H00FF |
13 | tempStr = Chr(hi) & Chr(lo) |
14 | RETURN tempStr |
15 | END |
Regarding the information frame of the STC12C5Ax series, here is a picture analyzed by others:
As for the firmware versions I tested here are:
1 | 6.6I : 66 49 |
2 | 6.2I : 62 49 |
About the calculation of crystal oscillator speed:
If it is a standard 12M clock and 1200Kps baud rate, the count value is 1/1200*7 = 5833uS, and the value is also 5833. The average of eight times (assuming 18 94=6292), then the MCU clock frequency = 6292*12M/5833 = 12.994MHz. [page]
I was wondering, is the C-level microcontroller xx 43?
The following data frames omit the frame header, frame tail, and frame length check code.
——————–Check MCU model frame————————-
Send data 50 07 00 36 01 MCU model
Receive data 8F
——————-Baud rate experiment frame——————————–
Send data 8F xx yy zz aa dd 83
xx=0xC0 (C0=1100 0000, which means T1x12, double the baud rate)
yy=timer reload value, calculated as double/1T.
zz=set checksum, calculated as ff=xx
aa=baud rate check value, calculated as aa=2 * (0×100 -yy)
dd=delay value, how much time is delayed before switching
83 is the ISP timing constant. This value is applicable to the 12M crystal oscillator. There is an unclear description in the STC manual:
1 | //#define ENABLE_IAP 0x80//if SYSCLK<30MHz |
2 | //#define ENABLE_IAP 0x81//if SYSCLK<24MHz |
3 | //#define ENABLE_IAP 0x82//if SYSCLK<20MHz |
4 | //#define ENABLE_IAP 0x83//if SYSCLK<12MHz |
5 | //#define ENABLE_IAP 0x84//if SYSCLK<6MHz |
6 | //#define ENABLE_IAP 0x85//if SYSCLK<3MHz |
7 | //#define ENABLE_IAP 0x86//if SYSCLK<2MHz |
8 | //#define ENABLE_IAP 0x87//if SYSCLK<1MHz |
But in actual testing, it seems that the value 83 has no problem at 40M.
Accept data:
8F xx yy zz aa dd 83
—————————–Baud rate confirmation frame
Send data 8E xx yy zz dd 83
Receive data as above
——————————Erase frame:
I have every reason to suspect that the old demon is sick. Even when it comes to downloading the program, it still uses such a weird erase command:
1 | 84 FF 00 F0 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 |
2 | 00 80 7F 7E 7D 7C 7B 7A 79 78 77 76 75 74 73 72 71 70 6F 6E 6D 6C 6B |
3 | 6A 69 68 67 66 65 64 63 62 61 60 5F 5E 5D 5C 5B 5A 59 58 57 56 55 54 |
4 | 53 52 51 50 4F 4E 4D 4C |
5 | 4B 4A 49 48 47 46 45 44 43 42 41 40 3F 3E 3D 3C 3B 3A 39 38 37 36 35 |
6 | 34 33 32 31 30 2F 2E 2D 2C 2B 2A 29 28 27 26 25 24 23 22 21 20 1F 1E |
7 | 1D 1C 1B 1A 19 18 17 16 15 14 13 12 11 10 0F 0E |
Response:
00 00
-------Data Frame
Send 00 00 00 ADDR 00 LEN EF 0×80 bytes data
ADDR = 2BYTE address, high byte first, low byte last
LEN seems to be the data length
If the data field is less than 80 bytes, fill it with ff
Response 07 ChkSum
The ChkSum algorithm is the same as described above, except that it only verifies the data part.
——————Set model frame:
69 07 00 36 01 MCU_MODEL
MCU_MODEL is the MCU model
The response is just one word 8D
——————-Set option frame
Send: 8D FF x1 x2 FF FF FF FF FF x3 FF FF FF FF FF FF 00 A9 0A A6
x1, x2, x3 see previous option information
Accept: 50 FF x1 x2 FF x3 03 FF Firmware version FF x1 x2 FF x3 FF 00 A9 00 03 00 9A 04 79 1A 00 AD FF 00 62
——————RESET frame
Send: 82 00 00
no respond.
For specific implementation, please refer to the implementation of kSTC12-ISP
Previous article:Modify the source code of EasyPro51 programmer on SDCC, compile and run successfully
Next article:A simple program to test the integer performance of the microcontroller
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Integer square root algorithm
- Combining the new 6-axis IMU with DSP to achieve high-performance motion tracking accuracy
- Six design issues for I2C isolators
- Common problems and solutions in CCS compilation
- Can TVS be used to extinguish arcs?
- #SpaceX sends 4 civilians into space#When can I travel in space too???
- Please tell me the circuit composed of TL431 directly and optocoupler inside the power supply
- The problem of via aperture and line width
- Use one data line to control full-color LED lights! Single bus LED usage guide
- 【Portable Programmable Meter】Sliding Rheostat Arrived