How to Store Data in DWIN HMI NOR Flash Using UART Commands (DGUS Step-by-Step Guide)
You enter a server address, port and machine number on a DWIN touch display, power it off, and everything is gone. That happens because values typed on a DWIN HMI live in its VP (RAM) variables, which are cleared on every restart. This guide shows how to save those values permanently in the display's NOR Flash memory with a single UART command, and how to read them back after power-up. It covers the DGUS screen setup, the command frame byte by byte, and a real test with Docklight.
The example screen: Server address, Port no and Machine no, designed in DGUS.
What you need
- Display: DWIN DMG32240C035_03WTC (3.5", DGUS II). The same method works on other DGUS II displays.
- Software: DWIN DGUS tool, and Docklight (or any serial terminal) for testing.
- Hardware: USB-to-UART (TTL) converter, micro SD card and card reader.
- Serial settings used here: 115200 baud, 8 data bits, no parity, 1 stop bit (115200 8N1).
VP (RAM) vs NOR Flash: why data disappears
| Memory | What it is | After power off |
|---|---|---|
| VP variables (RAM) | Runtime memory that every DGUS widget reads and writes | Lost |
| NOR Flash database | Permanent storage inside the display (DWIN HMIs support NOR Flash, not NAND) | Kept |
The idea is simple: the user types values into VP variables, you copy that VP block into NOR Flash to save it, and at start-up you copy it back from NOR Flash into the same VP addresses.
Part 1: Design the screen in DGUS
1. Import the background and keyboard images
Open the DGUS tool, create a project and add the screen background and a full keyboard image (keep the keyboard on its own page).
2. Configure the keyboard keys
- On the keyboard page, go to Touch → Basic Touch, drag a box over the keyboard area.
- Enable Full QWERTY keyboard and click Set.
- Select each key and assign its key value. Repeat for every key.
Basic Touch over the keyboard image, with Full QWERTY keyboard enabled.
3. Text field: Server address (ASCII text)
- Text show → Text display: drag the area. Set VP = 0x3006, encoding as required, and the text length you need.
- Touch → ASCII input: drag the same area and use the same VP (0x3006) so the input and the display share one variable.
- Set Keyboard location = Other page, click Keyboard setting, choose the keyboard page, select the whole keyboard and click OK.
- Copy the keyboard area size into Show location, click Set, enable the option and select the text entry area.
Text display for the server address, VP 0x3006.
4. Number fields: Port no and Machine no
- Touch → Variable input: drag the area. Port no uses VP = 0x3004, variable type int (2 bytes), 4 integer digits. Set the keyboard as in step 3.
- Text show → Data variable display: drag the same area with the same VP, type and digits.
- Repeat for Machine no with VP = 0x3002.
Variable input for Port no: VP 0x3004, int, 4 digits.
Rules that save hours of debugging:
- Use even VP addresses.
- The input widget and its display widget must use the same VP, the same variable type and the same digits.
- Leave enough space between VPs. A text field uses several words, so its VP block must not overlap the next variable.
5. Save, generate and load to the display
- In DGUS, click File → Save and then Generate.
- Format the SD card, copy the project's DWIN_SET folder to the card and eject it.
- Power off the display, insert the SD card, power on and wait until the download finishes. Then remove the card and restart.
The SD card slot on the board, and the download screen shown while the display loads the project.
Part 2: The NOR Flash command (VP 0x0008)
DGUS II reserves a system variable at VP 0x0008 (NOR_FLASH_RW_CMD). Writing 4 words to it tells the display to copy data between its VP RAM and the NOR Flash database.
From the DWIN datasheet: 0x5A = read, 0xA5 = write; addresses and length must be even.
Write command, byte by byte
Save VP 0x3000 onwards (62 words) into NOR Flash address 0x000002:
5A A5 0B 82 00 08 A5 00 00 02 30 00 00 3E
| Bytes | Field | Meaning |
|---|---|---|
| 5A A5 | Header | Start of every DWIN frame |
| 0B | Length | 11 bytes follow this byte |
| 82 | Command | Write to VP (variable) memory |
| 00 08 | VP address | System variable NOR_FLASH_RW_CMD, so this is a flash operation, not a normal VP write |
| A5 | Mode | A5 = write to flash, 5A = read from flash |
| 00 00 02 | Flash address | NOR Flash start address (must be even) |
| 30 00 | VP address | First VP of your data block (must be even) |
| 00 3E | Data length | 0x3E = 62 words (124 bytes). The length is in words and must be even. |
62 words from 0x3000 covers 0x3000 to 0x303D, which includes Machine no (0x3002), Port no (0x3004) and the Server address text (0x3006 onwards).
Read command
Load the same 62 words from NOR Flash 0x000002 back into VP 0x3000. Only the mode byte changes:
5A A5 0B 82 00 08 5A 00 00 02 30 00 00 3E
The display's reply
5A A5 03 82 4F 4B
4F 4B is ASCII "OK": the display accepted the write to VP 0x0008.
Part 3: Test it with Docklight
- Connect the display's UART to your PC with a USB-to-UART converter.
- Open Docklight and set the COM port to 115200, None, 8, 1.
- Add two send sequences: the Write frame and the Read frame above.
Docklight COM port settings: 115200 baud, no parity, 8 data bits, 1 stop bit.
The real test
- Enter values on the display: Server add = acceedo, Port no = 2002, Machine no = 2003.
- Send the Write command. The display replies 5A A5 03 82 4F 4B (OK).
- Power the display off and on. The fields are now empty, because the VP RAM was cleared.
- Send the Read command. All three values come back from NOR Flash.
1. Values entered on the display.
2. Write command sent (TX) and the OK reply (RX).
3. After a restart: the fields are empty.
4. Read command sent: the values are back from NOR Flash.
Using it in your firmware
- On power-up: wait for the display to finish booting, then send the Read command so the screen shows the saved settings.
- On Save: when the user presses the Save button (read its key code or VP from the display), send the Write command.
- Wait between commands: the display clears byte D7 of VP 0x0008 when the flash operation finishes. Do not send another flash command until it is cleared, or add a short delay.
- Do not write continuously: flash memory has a limited number of erase/write cycles. Save only when values change or when the user presses Save, never in a fast loop.
- Plan your flash map: give each screen or settings group its own flash address range so blocks never overlap.
Troubleshooting
| Problem | Check |
|---|---|
| No reply from the display | Baud rate (115200 8N1), TX/RX crossed, common GND, correct COM port |
| Reply OK but data not restored | Flash address, VP and length are the same in the write and read frames; values were written before the restart |
| Only some fields restored | The length (in words) covers all your VPs; text fields need several words each |
| Strange characters or numbers | Odd VP or flash address; input and display widgets using different VP or variable type |
Frequently asked questions
Is the length in bytes or words?
Words. 0x003E means 62 words, which is 124 bytes. The DWIN datasheet example "store 2-word data" uses length 0x0002.
Does DWIN HMI support NAND flash?
No. The DGUS database used here is NOR Flash.
Which flash address should I use?
Any even address inside the NOR Flash range given in your display's datasheet. Keep a simple map, for example settings at 0x000002, so different data blocks never overlap.
What does 5A A5 03 82 4F 4B mean?
It is the display's acknowledgement of a 0x82 write: 4F 4B is ASCII "OK".
Need help with HMI or IoT products?
Acceedo designs HMI screens, PCBs, embedded firmware and IoT gateways in Coimbatore, and connects them to factory software for heat treatment, melting, warehouse and attendance systems.
- Website: acceedo.in
- Phone / WhatsApp: +91 99941 11214
- Email: dinesh@acceedo.in
Also read: RS485 and Modbus RTU Basics · Heat Treatment Furnace Monitoring with IoT
Related searches: DWIN HMI save data after power off, DWIN NOR flash read write, DGUS 0x0008 command, DWIN UART command 5A A5, DWIN VP address, DGUS ASCII input, DGUS variable input, DWIN display data storage, DMG32240C035, Docklight DWIN, DWIN HMI tutorial, DGUS II flash database.













Comments
Post a Comment