Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ATtiny104_Datasheet.pdf
Скачиваний:
0
Добавлен:
12.02.2026
Размер:
3.8 Mб
Скачать

20.4.5.Writing NVM Lock Bits

The algorithm for writing the Lock bits is as follows:

1.Write the WORD_WRITE command to the NVMCMD register.

2.Write the lock bits value to the Non-Volatile Memory Lock Byte location. This is the low byte of the NonVolatile Memory Lock Word.

3.Start the NVM Lock Bit write operation by writing a dummy byte to the high byte of the NVM Lock Word location.

4.Wait until the NVMBSY bit has been cleared.

20.5.Self programming

The Flash in Tiny104 does not support Read-While-Write, and cannot be read during an erase or write operation. Therefore, the CPU will halt execution.

The device provides a Self-Programming mechanism for downloading and uploading program code by the MCU itself. Only WORD_WRITE and PAGE_ERASE commands are supported in self-programming. The CPU can execute Page Erase and Word Write in the NVM code memory section to perform programming operations.

Note:  The user needs to add two NOP operations after the ST operation that triggers the selfprogramming to ensure correct CPU operation.

Table 20-9. Example code for self-programming:

Assembly Code Example

The sequence for entering self-programming mode is given below (r19 can be any register):

;set CCP

ldi

r19, 0xe7

out

CCP, r19

The software then has to perform the desired self-programming operation within 4 clock cycles. Example of the complete code to perform page erase:

;erase page

;set the page address pointer

ldi

ZL,

0xE1

ldi

ZH,

0x43

;set NVMCMD to page erase

ldi

temp,

0b011000

out

NVMCMD,

temp

;set CCP to enter program mode

ldi

r19, 0xe7

out

CCP, r19

; trigger the erase operation (within four clock cycles)

ldi

temp, 0x00

st

Z+, temp

; required for proper CPU halting nop

nop

20.6.External Programming

The method for programming the Non-Volatile Memories by means of an external programmer is referred to as external programming. External programming can be done both in-system or in mass production.

Atmel ATtiny102 / ATtiny104 [DATASHEET] 194

Atmel-42505D-ATtiny102-ATtiny104_Datasheet_Complete-10/2016