Protocol Analysis of STC12C Series

Publisher:WhisperingLightLatest update time:2015-07-15 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
This version of the protocol has undergone significant changes compared to the previous one, including the packet header, etc. However, STC has a thousand-year-old opening frame: 0x7F. The STC15 series MCU still uses this ISP opening frame. You all know the reason without me having to explain .

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 ta

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

Reference address:Protocol Analysis of STC12C Series

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

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号