{"id":315165,"date":"2020-12-19T15:01:09","date_gmt":"2020-12-19T15:01:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=315165"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=315165","title":{"rendered":"24&#215;01 I2C \u043d\u0430 ATTINY13 \u0431\u0435\u0437 TWI"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u0447\u0442\u043e \u0442\u0443\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u043d\u0443 I2C \u043d\u0443 \u0431\u0435\u0437 TWI.<\/p>\n<p>\u041c\u043e\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u0431\u0441\u0442\u043e\u044f\u043b\u0430 \u0447\u0443\u0442\u044c \u0448\u0438\u0440\u0435, \u0432 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u043b\u0441\u044f \u0447\u0438\u043f \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 &#171;Reset&#187; \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, \u0434\u043b\u044f \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 \u043c\u0435\u0441\u0442\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0435, \u0437\u0430\u0434\u0430\u0447\u0430 \u044d\u0442\u043e\u0433\u043e \u0447\u0438\u043f\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043b\u0430 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u0438\u043c\u043f\u0443\u043b\u044c\u0441 \u043a\u0430\u043a \u0441\u0438\u0433\u043d\u0430\u043b \u043a \u043d\u0430\u0447\u0430\u043b\u0443 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 &#171;\u0434\u043b\u0438\u043d\u043d\u043e\u0433\u043e&#187; \u0441\u0431\u0440\u043e\u0441\u0430, \u0447\u0438\u043f \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u043b \u043e\u0434\u043d\u0443 \u0438\u0437 \u043b\u0438\u043d\u0438\u0439 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432 \u043d\u0438\u0437\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 (\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0438\u0437 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u043e\u0432 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430, \u043d\u043e \u043b\u0438\u043d\u0435\u0439\u043a\u0430 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u043e\u0432 \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0430 \u043f\u043e\u0447\u0442\u0438 80 \u044f\u0447\u0435\u0435\u043a \u0432 CPLD EPM240T100 \u0438 \u043c\u0435\u0441\u0442\u043e \u0442\u0430\u043c \u043e\u0439 \u043a\u0430\u043a \u043d\u0443\u0436\u043d\u043e) \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u044d\u0442\u043e\u0442 \u0447\u0438\u043f \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u043b \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e \u0448\u0438\u043d\u0435 I2C \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 1 (mode1).<\/p>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0440\u0438 \u0440\u0435\u0436\u0438\u043c\u0430 I2C, 2-\u043e\u0439 \u0438 3-\u0438\u0439 \u0440\u0435\u0436\u0438\u043c\u044b \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u044b \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u043d\u0430 \u0448\u0438\u043d\u0435 I2C \u0432\u0438\u0441\u0438\u0442 \u0433\u0438\u0440\u043b\u044f\u043d\u0434\u0430 \u0438\u0437 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c \u043d\u0430 \u0448\u0438\u043d\u0435 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 2 \u0438 3 \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e, \u0437\u0430\u0442\u0435\u043c \u0443\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u043d\u0435\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0438 \u0434\u0430\u043d\u043d\u044b\u0435. \u0420\u0435\u0436\u0438\u043c 1 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0440\u0435\u0436\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u044b I2C, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0440\u0430\u0437\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 \u0447\u0438\u043f \u0430\u0434\u0440\u0435\u0441 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u043b\u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u0412\u043e\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e \u0447\u0435\u043c \u044f \u0433\u043e\u0432\u043e\u0440\u044e (MODE1):<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c10\/ae8\/ff5\/c10ae8ff5a932d64f42ec70f2c28ecdb.png\" width=\"896\" height=\"197\"><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u044d\u0442\u043e MODE2:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1f7\/209\/859\/1f72098594facaccad0b08f8a1918791.png\" width=\"881\" height=\"190\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0442\u0443\u0442 \u0432\u0441\u0451 \u0438\u0442\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043d\u043e! \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u0437\u0430\u0434\u0430\u0447\u0438:<\/p>\n<ol>\n<li>\n<p>\u0412 ATTINY13 \u043d\u0435\u0442 \u0430\u043f\u043f\u0430\u0440\u0430\u0442\u043d\u043e\u0433\u043e I2C.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0438\u043f \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0435\u0449\u0451 \u0438 \u0441\u0431\u0440\u043e\u0441 (\u0445\u043e\u0442\u044f \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u044d\u0442\u043e \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u0432\u0430\u0436\u043d\u043e).<\/p>\n<\/li>\n<li>\n<p>\u0418 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 24&#215;01 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043c EEP 128 \u0431\u0430\u0439\u0442, \u0430 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0447\u0438\u043f\u0435 EEPROM \u043e\u0431\u044a\u0435\u043c\u043e\u043c \u0442\u043e\u043b\u044c\u043a\u043e 64 \u0431\u0430\u0439\u0442\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u0442\u0430\u0432\u0438\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0430 \u0448\u0438\u043d\u0435, \u043a\u043e\u0434\u043e\u043c, &#8212; \u0442\u0443\u0442 \u0434\u043b\u044f \u043d\u0430\u0441 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440, \u0432\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u044d\u0442\u043e \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0441\u0431\u0440\u043e\u0441\u0430, \u0430 \u0432\u043e\u0442 \u0442\u0440\u0435\u0442\u044c\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u0422\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438 FLASH \u043d\u0435 \u0437\u0430\u043d\u044f\u0442\u043e\u0439 \u043d\u0430\u0448\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u043d\u043e EEPROM \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0431\u0430\u0439\u0442\u043d\u043e, \u0430 FLASH \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u043c\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u043e FLASH \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u044f \u043e\u0431\u044f\u0437\u0430\u043d \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432 \u0432\u0441\u0435\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, &#171;\u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c&#187; \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430, \u0441\u0442\u0435\u0440\u0435\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0441\u043e\u0441\u0442\u0430\u0432 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043f\u0430\u0441\u0442\u044c\u0441\u044f \u0432 \u0441\u043c\u0435\u0436\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430 \u0441\u0442\u044b\u043a\u0430\u0445. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u044f \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0434\u0432\u0430 \u044d\u0442\u0430\u043f\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/828\/093\/aad\/828093aad54b3d5ad02a2c503f03939a.png\" width=\"880\" height=\"300\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u044f \u0442\u0430\u043a \u043f\u043e\u043d\u0438\u043c\u0430\u044e \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043b\u0438\u0440\u0438\u043a\u0430 \u043c\u0430\u043b\u043e \u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442, \u0442\u0443\u0442 CTRC+C \u0438 CTRL+V \u0447\u0430\u0449\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u0443\u0436\u0435 \u043a\u043e\u0434.<\/p>\n<p>\u0422\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u0435\u0440\u0432\u0430 \u041a\u043e\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438:<\/p>\n<ol>\n<li>\n<p>CHIP_PINOUTS &#8212; \u041a\u0430\u043a \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434\u044b \u043d\u0430 \u0447\u0438\u043f\u0435 (FT24Cxx &#8212; \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u043a\u0430 \u0447\u0438\u043f\u0430 I2C, InDRIVE_v4 &#8212; \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u043a\u0430 \u043f\u043e\u0434 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c \u0441\u0431\u0440\u043e\u0441\u0430).<\/p>\n<\/li>\n<li>\n<p>I2C_MODE &#8212; \u0420\u0435\u0436\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u044b I2C (MODE_1 \u0438 MODE_2).<\/p>\n<\/li>\n<li>\n<p>I2C<em>PAGE<\/em>SIZE &#8212; \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b I2C \u043f\u0440\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<\/li>\n<li>\n<p>I2C<em>EEP<\/em>SIZE &#8212; \u043e\u0431\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0438\u043f\u0430 (\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u043a\u043e\u0434\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 64 \u0431\u0430\u0439\u0442\u0430 EEPROM, \u0437\u0430\u0442\u0435\u043c \u0440\u0430\u0441\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442 &#171;\u043e\u0441\u0442\u0430\u0442\u043a\u0438&#187; \u0432\u043e FLASH).<\/p>\n<\/li>\n<li>\n<p>RESET_CNT &#8212; \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0441\u0431\u0440\u043e\u0441\u0430 (ON &#8212; \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, OFF &#8212; \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442).<\/p>\n<\/li>\n<\/ol>\n<h2>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435, \u0434\u043e\u0441\u0442\u0430\u0435\u043c TLL866<\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f54\/4a8\/89b\/f544a889b18ec0985ae89974688fbfd7.jpg\" width=\"596\" height=\"640\"><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043e\u0442\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 (AVR Studio v4), \u044f \u043f\u0440\u043e\u043b\u0438\u0441\u0442\u0430\u043b \u0432 \u043a\u043e\u043d\u0435\u0446 \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432 &#171;\u043f\u0441\u0435\u0432\u0434\u043e EEP&#187;:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5a0\/1dd\/266\/5a01dd2664f2f6e461795866220cb751.png\" width=\"803\" height=\"599\"><figcaption><\/figcaption><\/figure>\n<p> \u0421\u0442\u0430\u0432\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0431\u0438\u0442\u044b \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043c\u0438\u043a\u0440\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 \u043d\u0430\u0448\u0443 ATTINY13:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aef\/50b\/d93\/aef50bd934cbfc3a9e635c45c9d120bf.png\" width=\"795\" height=\"599\"><figcaption><\/figcaption><\/figure>\n<p>\u0410\u0433\u0430, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044f \u0447\u0438\u043f \u043f\u0438\u0448\u0435\u043c \u0435\u0433\u043e \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 I2C EEPROM Mode1 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ff5\/d0f\/1e9\/ff5d0f1e9058d401fa38c76725a7fe1f.png\" width=\"813\" height=\"709\"><figcaption><\/figcaption><\/figure>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0427\u0442\u043e \u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 I2C EEP \u0434\u043b\u044f ATTINY13<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">\/* \tInDRIVE v4 Application (chip like: FT24C01, Selfprg Must Be Enabled!!! )  \tFuse BYTES \tLow(0x7A) : \t\tHigh(0xEE) : \tSPIEN = 1\t\tSELFPRGEN = 1 \tEESAVE = 0\t\tDWEN = 0 \tWDTON = 0\t\tBODLEVEL1 = 0 \tCKDIV8 = 0\t\tBODLEVEL0 = 0 \tSUT1 = 0\t\tRSTDISBL = 1 \tSUT0 = 1 \tCKSEL1 = 0 \tCKSEL0 = 1  *\/  .include \"tn13def.inc\"  \/* On\/Off Defines *\/ .equ\tOFF\t\t\t=0 .equ\tON\t\t\t=1 \/* Chip Pinouts *\/ .equ\tFT24Cxx\t\t=0 .equ\tInDRIVE_v4\t=1  \/* Reset Controller Enable\/Disable *\/ .equ\tRESET_CNT\t=OFF \/* Chip Pinouts Define: InDrivev4\/Regular I2C Chip *\/ .equ\tCHIP_PINOUTS\t=FT24Cxx  .equ\tDEBUG\t\t=OFF \/* I2C Mode Define MODE 1\/MODE 2 *\/ .equ\tMODE_1\t\t=1 .equ\tMODE_2\t\t=2 .EQU\tI2C_MODE\t=MODE_1  \/* Define I2C Parameters *\/ \/* Page Size for Write in BYTES 4\/8\/16 *\/ \/* 128\/256 Size in MODE 1 Protocol can't receive more than 128 Bytes *\/ .IF I2C_MODE == MODE_2 \t.MESSAGE \"Compile for I2C Mode 2\" .equ\tI2C_PAGE_SIZE\t=8 .equ\tI2C_EEP_SIZE\t=256 .ELSE \t.MESSAGE \"Compile for I2C Mode 1\" .equ\tI2C_PAGE_SIZE\t=4 .equ\tI2C_EEP_SIZE\t=128 .ENDIF  \/*  Modes Define  \tA - Address \tiD - Data From Master \toD - Data To Master  \tMODE 1 \t\tWrite - [START][AAAAAAA0][iD + 0]...[iD + I2C_PAGE_SIZE - 1][STOP] \t\tRead -  [START][AAAAAAA1][oD + 0]...[oD + I2C_EEP_SIZE - 1][STOP] \tMODE 2  \t\tWrite - [START][10100000][AAAAAAAA][iD + 0]...[iD + I2C_PAGE_SIZE - 1][STOP] \t\tRead -  [START][10100001][oD + 0]...[oD + I2C_EEP_SIZE - 1][STOP] *\/  \/* \tI2C slave, fSCL = 400kHz \tFULLY Implemented I2C Protocol for 24xx01\/24xx02 \tAnd RESET Controller FOR InDRIVE(v4)  **************************************************************    \tATTINY13A I2C Configuration **************************************************************       \tpin configuration InDRIVE v4:                         ,---_---.     (RESET\/PB5)     nc |1     8| VCC           (PB3)  inRST |2     7| SCL  \t(PB2)           (PB4) outRST |3     6| EMU24X (PB1) SDA pin from CORE                    GND |4     5| nc \t(PB0) unused SDA pin                        `-------'     \tpin configuration FT24C01:                         ,---_---.     (RESET\/PB5)     nc |1     8| VCC         \t  (PB3)  \tnc |2     7| nc  \t(PB2)       \t    (PB4) \tnc |3     6| SCL \t(PB1) SCL pin I2C                    GND |4     5| SDA \t(PB0) SDA pin I2C                        `-------'     \tpin configuration FT24C02:                         ,---_---.     (RESET\/PB5)     A0 |1     8| VCC        \t   (PB3)  \tA1 |2     7| nc  \t(PB2)       \t    (PB4) \tA2 |3     6| SCL \t(PB1) SCL pin I2C                    GND |4     5| SDA \t(PB0) SDA pin I2C                        `-------'  *\/ \/* Pins Define *\/ .IF CHIP_PINOUTS == InDRIVE_v4 \t.MESSAGE \"Chip Pinouts: InDRIVE v4\" .equ\tEMU24X\t= 1 .equ \tSCL \t= 2 .ELSE .equ\tEMU24X\t= 0 .equ \tSCL \t= 1 \t.MESSAGE \"Chip Pinouts: Regular 24Cxx\" .ENDIF .equ \tSDA \t= EMU24X .equ \tACK \t= SDA .equ\tinRST\t= 3 .equ\toutRST\t= 4   .def\tTMPnoINT\t\t=R19 .def\tCounter\t\t\t=R3 .def\tCounterInWrite\t=R4 .def\tSREGST\t\t\t=R5  \/* Real ATTINY13A FLASH Page SIZE In Bytes *\/ .equ\tPAGESIZEB\t\t=(PAGESIZE*2)  \/* SRAM Mapping *\/ .DSEG .IF I2C_MODE == MODE_2 \t_I2c_device_inaddr:  .BYTE 1\t\/* MODE 2 Region *\/ \t_I2c_device_myaddr:  .BYTE 1 .ENDIF \t_valSPMCSR: .BYTE 1 \t_I2c_data_buffer:\t.BYTE I2C_PAGE_SIZE \t_I2c_FLASH_buffer:\t.BYTE PAGESIZEB .cseg  \/* Read\/Write Pointers *\/ .def\tI2c_start_addr\t=R16 .def\tI2c_wr_counter\t=R17 .def\tI2c_wr_pointer\t=R18 .def\tI2c_rd_pointer\t=R21  .def\t_PINB\t\t\t=R20  .IF I2C_MODE != MODE_2 \t.IF I2C_MODE != MODE_1 \t\t.error \"Invalid mode for I2C Selected, please correct I2C_MODE define\" \t.ENDIF .ENDIF  .cseg  .org 0\/\/Reset .IF RESET_CNT == ON \t\trjmp\tWaitinRSTHI\t\t;RESET \t\treti\t\t\t\t\t;INT0addr\t= 0x0001\t; External Interrupt 0 \t\trjmp\tResetInProcess\t;PCI0addr\t= 0x0002\t; External Interrupt Request 0 .ELSE \t\trjmp\tmain\t\t\t;RESET \t\treti\t\t\t\t\t;INT0addr\t= 0x0001\t; External Interrupt 0 \t\treti\t\t\t\t\t;PCI0addr\t= 0x0002\t; External Interrupt Request 0 .ENDIF \t\treti\t\t\t\t\t;OVF0addr\t= 0x0003\t; Timer\/Counter0 Overflow \t\treti\t\t\t\t\t;ERDYaddr\t= 0x0004\t; EEPROM Ready \t\treti\t\t\t\t\t;ACIaddr\t= 0x0005\t; Analog Comparator \t\treti\t\t\t\t\t;OC0Aaddr\t= 0x0006\t; Timer\/Counter Compare Match A \t\treti\t\t\t\t\t;OC0Baddr\t= 0x0007\t; Timer\/Counter Compare Match B \t\treti\t\t\t\t\t;WDTaddr\t= 0x0008\t; Watchdog Time-out \t\treti\t\t\t\t\t;ADCCaddr\t= 0x0009\t; ADC Conversion Complete  \/\/ ******************************************************************************************* \/\/ **   Reset Processor                                                       \t\t\t\t** \/\/ ******************************************************************************************* .IF RESET_CNT == ON \t.MESSAGE \"Reset Controller Function is: ON\" ResetInProcess:\t;Proccess reset \t\tsbic\tpinb,inRST\t;Process reset on falling edge \t\treti  WaitinRSTHI: \t\tcli  \t\t;Wait ~80 mS 0x04E360 on 9.6MHz \t\tldi\t\tR16,0x10 \t\tldi\t\tR17,0xE3 \t\tldi\t\tR18,0x60 \t\t;Set RESET Enable \t\tcbi\t\tPORTB,outRST  _CntLO: \t\tdec\t\tR18 \t\tBRNE\t_CntLO _CntME: \t\tdec\t\tR17 \t\tBRNE\t_CntLO _CntHI: \t\tdec\t\tR16 \t\tBRNE\t_CntLO  \t\t; And Clear Iterrupt flag for normal exit \t\tldi\t\tR16,(1 &lt;&lt; PCIF) \t\tout\t\tGIFR,R16 .ELSE \t.MESSAGE \"Reset Controller Function is: OFF\" .ENDIF\t\/\/ RESET_CNT == ON \t\t \/\/ ******************************************************************************************************* \/\/ **   Main Programm                                                         \t\t\t\t** \/\/ ******************************************************************************************************* main: \t\t;init STACK \t\tldi\t\tTMPnoINT,low(RAMEND) \t\tout\t\tSPL,TMPnoINT  \t\t;init IO \t\tldi\t\tTMPnoINT,0x00 \t\tout\t\tMCUCR,TMPnoINT \t\t;Outputs to HI (Pull UP) \t\tldi\t\tTMPnoINT,0xFF \t\tout\t\tPORTB,TMPnoINT .IF RESET_CNT == ON \t\t;Output enable for outRST, all other for input \t\tsbi\t\tPORTB, outRST \t\tsbi\t\tPINB, inRST \t\tsbi\t\tDDRB,outRST\t; Output Enable \t\t;Init Interrupt\t\t     \tldi \tTMPnoINT, (1 &lt;&lt; inRST)\t; set pin change interrupt for inRST     \tout \tPCMSK, TMPnoINT\t\t \t\tldi\t\tTMPnoINT, (1&lt;&lt;PCIE)\t\t; unmask interrupt PCIE \t\tout\t\tGIMSK,TMPnoINT \t\tSEI\t\t\t\t\t;Enable PCIE Int Processing .ELSE \t\tCLI\t\t; Disable Reset Controller .ENDIF  .IF I2C_MODE == MODE_2 \t\t\/* Set I2C Device Address *\/ \t\tldi\t\tTMPnoINT, 0xA0 \t\tsts\t\t_I2c_device_myaddr,TMPnoINT .ENDIF  \t\t\/* Clear Buffer Pointers *\/ \t\tclr\t\tI2c_wr_counter \t\tclr\t\tI2c_wr_pointer \t\tclr\t\tI2c_start_addr \t\tclr\t\tI2c_rd_pointer   main_loop:  lI2c_get: \tsbi portb,ack \tsbis pinb,scl                                            ;wait for SCL&amp;SDA=1 \trjmp lI2c_get \tsbis pinb,sda \trjmp lI2c_get lI2c_wait_for_start: \tsbis pinb,scl                                            ;wait for SCL=1,SDA=0 (START) \trjmp lI2c_get \tsbic pinb,sda \trjmp lI2c_wait_for_start lI2c_get_0:                                                  ;clear receive area .IF I2C_MODE == MODE_2 \tclr r22 \tsts _I2c_device_inaddr,r22 .ENDIF lI2c_get_1:                                                  ;get 1st byte \tsbi portb,ack lI2c_10:                                                     ;wait for SCL=0 \tsbic pinb,scl \trjmp lI2c_10 \tldi r22,8                                                ;bits to receive=8 .IF I2C_MODE == MODE_2 \tlds r23,_I2c_device_myaddr                               ;I2C address-&gt;R23 .ENDIF lI2c_11: \tin\t_PINB, pinb \tsbrs _PINB,scl                                            ;wait for SCL=1 \trjmp lI2c_11 \tsbrc _PINB,sda \trjmp lI2c_13 lI2c_12:                                                     ;if SDA=0 \tsbic pinb,sda \trjmp lI2c_wait_for_start                                  ;  SDA 0-&gt;1? I2CSTOP! (unexpected: wait for next start) \tsbic pinb,scl \trjmp lI2c_12                                              ;  loop while SCL=1 \tclc                                                      ;  SDA=0-&gt;C \trjmp lI2c_15 lI2c_13:                                                     ;if SDA=1 \tsbis pinb,sda \trjmp lI2c_get_1                                           ;  SDA 1-&gt;0? I2CSTART! (repeated start) \tsbic pinb,scl \trjmp lI2c_13                                              ;  loop while SCL=1 \tsec                                                      ;  SDA=1-&gt;C lI2c_15: \trol r24 \tdec r22 \tbrne lI2c_11                                              ;loop to next bit  .IF I2C_MODE == MODE_2 \tsts _I2c_device_inaddr,r24 \tSUB r24,r23                                              ;my address? \tcpi r24,2 \tbrlo lI2c_ack_1 \trjmp lI2c_exit                                            ;  no: exit and wait for next start .ENDIF  lI2c_ack_1:                                                  ;  yes: generate ack  \tclr\t\tI2c_wr_counter\t\t\t\t\t\t\t\t; Clear Write Buffer Pointers \tclr\t\tI2c_wr_pointer \tclr\t\tI2c_start_addr \tcbi portb,ack \tsbi ddrb,ack                                             ;pinb.ack = output (ACK) lI2c_ack_10: \tsbis pinb,scl                                            ;wait for SCL=1 \trjmp lI2c_ack_10 lI2c_ack_11: \tsbic pinb,scl                                            ;wait for SCL=0 \trjmp lI2c_ack_11 \/************************************************************************* *\t\tSelect Read\/Write **************************************************************************\/ .IF I2C_MODE == MODE_2 \tcpi r24,0 \tbreq lI2c_get_2 .ELSE \tmov\tI2c_start_addr,r24\t\t\t\t; Extract Received Address \tlsr I2c_start_addr\t\t\t\t\t; And Read\/Write BIT \tmov I2c_rd_pointer,I2c_start_addr\t; Upadate Read Address \tbrcs lI2c_send_new_byte  \trjmp\tlI2c_ack_25 .ENDIF \/************************************************************************* *\t\tSending Data to Master **************************************************************************\/ lI2c_send_new_byte:                                             ;read address received \tsbi ddrb,sda                                             ;pinb.sda = output (will send data) \/* Read From Flash *\/ \tandi I2c_rd_pointer, (I2C_EEP_SIZE - 1) \tLDI\tZH,high(MemoryBlockFLASH&lt;&lt;1) \tLDI\tZL,low(MemoryBlockFLASH&lt;&lt;1) \tadd ZL,I2c_rd_pointer \tinc I2c_rd_pointer \tlpm\tR24, Z \tldi r22,8  .IF DEBUG == 1 \trjmp lI2c_s1\t \/* Read From SRAM *\/ ReadFromSram: \tandi I2c_rd_pointer, (I2C_EEP_SIZE - 1) \tLDI\tZH,high(_I2c_device_inaddr) \tLDI\tZL,low(_I2c_device_inaddr) \tadd ZL,I2c_rd_pointer \tinc I2c_rd_pointer \tld\tR24, Z \tldi r22,8 .ENDIF  lI2c_s1: \tcbi portb,sda \tsbrc r24,7 \tsbi portb,sda lI2c_s2: \tsbis pinb,scl                                            ;wait for SCL=1 \trjmp lI2c_s2 \tlsl r24 lI2c_s3: \tsbic pinb,scl                                            ;wait for SCL=0 \trjmp lI2c_s3 \tdec r22 \tbrne lI2c_s1 \tsbi portb,sda                                            ;pinb.sda = 0 (will generate ACK) \tcbi ddrb,sda                                             ;pinb.sda = input (will receive data)  lI2c_s4:                                            \t\t\t;wait acknowloge receive \tsbis pinb,scl                                            ;wait for SCL=1 \trjmp lI2c_s4 lI2c_s5: \tsbic pinb,scl                                            ;wait for SCL=0 \trjmp lI2c_s5 \t \tsbis pinb,sda\t\t\t\t\t\t\t\t\t\t\t;if answer received, - continue \trjmp\tlI2c_send_new_byte  \trjmp lI2c_wait_for_start_stop                             ;wait for next start\/stop  \/************************************************************************* *\t\tReceiving Data from Master **************************************************************************\/ .IF I2C_MODE == MODE_2 lI2c_get_2:                                                  ;write address received: get 2nd byte \tcbi ddrb,ack                                             ;pinb.ack = output (ACK) lI2c_20:                                                     ;wait for SCL=0 \tsbic pinb,scl \trjmp lI2c_20 \tldi r22,8                                                ;bits to receive=8 lI2c_21: \tsbis pinb,scl                                            ;wait for SCL=1 \trjmp lI2c_21 \tsbic pinb,sda \trjmp lI2c_23 lI2c_22:                                                     ;if SDA=0 \tsbic pinb,sda \trjmp lI2c_stop                                            ;  SDA 0-&gt;1? I2CSTOP! (finish this sequence) \tsbic pinb,scl \trjmp lI2c_22                                              ;  loop while SCL=1 \tclc                                                      ;  SDA=0-&gt;C \trjmp lI2c_25 lI2c_23:                                                     ;if SDA=1 \tsbis pinb,sda \trjmp lI2c_get_1                                           ;  SDA 1-&gt;0? I2CSTART! (repeated start) \tsbic pinb,scl \trjmp lI2c_23                                              ;  loop while SCL=1 \tsec                                                      ;  SDA=1-&gt;C lI2c_25: \trol r24 \tdec r22 \tbrne lI2c_21                                              ;loop to next bit \tmov I2c_start_addr,r24                                         ;store received I2C address \tmov I2c_rd_pointer,I2c_start_addr\t\t\t\t\t\t; Upadate Read Address .ENDIF  ReceiveAcknowloge: \tcbi\tportb,sda \tsbi\tddrb,sda lI2c_ack_21: \tsbis pinb,scl                                            ;wait for SCL=1 \trjmp lI2c_ack_21 \tsbic pinb,sda \trjmp lI2c_ack_23 lI2c_ack_22:                                                     ;if SDA=0 \tsbic pinb,sda \trjmp lI2c_stop                                            ;  SDA 0-&gt;1? I2CSTOP! (finish this sequence) \tsbic pinb,scl \trjmp lI2c_ack_22                                              ;  loop while SCL=1 \trjmp lI2c_ack_25 lI2c_ack_23:                                                     ;if SDA=1 \tsbis pinb,sda \trjmp lI2c_get_1                                           ;  SDA 1-&gt;0? I2CSTART! (repeated start) \tsbic pinb,scl \trjmp lI2c_ack_23                                              ;  loop while SCL=1 lI2c_ack_25:  \tcbi ddrb,ack                                             ;pinb.ack = input \tLDI\tZH,high(_I2c_data_buffer) \tLDI\tZL,low(_I2c_data_buffer) lI2c_get_3:                                                  ;get 3rd byte lI2c_30:                                                     ;wait for SCL=0 \tsbic pinb,scl \trjmp lI2c_30 \tldi r22,8                                                ;bits to receive=8 \tmov\tTMPnoINT, I2c_wr_pointer \tandi TMPnoINT, (I2C_PAGE_SIZE - 1) \tadd ZL,TMPnoINT lI2c_31: \tsbis pinb,scl                                            ;wait for SCL=1 \trjmp lI2c_31 \tsbic pinb,sda \trjmp lI2c_33_ lI2c_32:                                                     ;if SDA=0 \tsbic pinb,sda \trjmp lI2c_stop_                                            ;  SDA 0-&gt;1? I2CSTOP! (finish this sequence) \tsbic pinb,scl \trjmp lI2c_32                                              ;  loop while SCL=1 \tclc                                                      ;  SDA=0-&gt;C \trjmp lI2c_35 lI2c_33_: lI2c_33:                                                     ;if SDA=1 \tsbis pinb,sda \trjmp lI2c_start_                                           ;  SDA 1-&gt;0? I2CSTART! (repeated start) \tsbic pinb,scl \trjmp lI2c_33                                              ;  loop while SCL=1 \tsec                                                      ;  SDA=1-&gt;C lI2c_35: \trol r24 \tdec r22 \tbrne lI2c_31                                              ;loop to next bit  \tinc I2c_wr_counter \tinc I2c_wr_pointer \tinc I2c_rd_pointer \tst\tZ,R24  \trjmp ReceiveAcknowloge  lI2c_wait_for_start_stop:                                    ;wait for start\/stop lI2c_ss_1: \tsbis pinb,scl                                            ;wait for SCL=1 \trjmp lI2c_ss_1 \tsbic pinb,sda \trjmp lI2c_ss_3 lI2c_ss_2:                                                   ;if SDA=0 \tsbic pinb,sda \trjmp lI2c_stop                                            ;  SDA 0-&gt;1? I2CSTOP! (finish this sequence) \tsbic pinb,scl \trjmp lI2c_ss_2                                            ;  loop while SCL=1 \trjmp lI2c_ss_1 lI2c_ss_3:                                                   ;if SDA=1 \tsbis pinb,sda \trjmp lI2c_get_1                                           ;  SDA 1-&gt;0? I2CSTART! (repeated start) \tsbic pinb,scl \trjmp lI2c_ss_3                                            ;  loop while SCL=1 \trjmp lI2c_ss_1                                            ;  SDA=1-&gt;C  lI2c_stop_: lI2c_stop:                                                   ;if stop, \tcbi\tddrb, sda \tcpi\tI2c_wr_counter,0x00 \tbrne WriteFlashRom lI2c_exit: \trjmp lI2c_get  lI2c_start_: \trjmp lI2c_get_1  WriteFlashRom: \tcli\t\t\t\t\t\t\t; Disable INTERRUPTS \trcall WriteReceivedData \tclr\t\tI2c_wr_counter\t\t\t\t\t\t\t\t; Clear Write Buffer Pointers \tclr\t\tI2c_wr_pointer \tsei\t\t\t\t\t\t\t; Enable INTERRUPTS \trjmp lI2c_get \/*********************************************************** * \t\t\tWrite internal FLASH by page ************************************************************\/ \/\/--------- Erase\/Program Page FROM FLASH to SRAM BackupFlashPage: \tldi\t\tYH,high(_I2c_FLASH_buffer) ; Load SRAM Buffer  \tldi\t\tYL,low(_I2c_FLASH_buffer)  \tmov\t\tTMPnoINT, I2c_start_addr \tandi\tTMPnoINT, ((I2C_EEP_SIZE - 1) &amp; ~(PAGESIZEB - 1))  \tldi\t\tZH,high(MemoryBlockFLASH &lt;&lt; 1) \tldi\t\tZL,low(MemoryBlockFLASH &lt;&lt; 1)  \tadc\t\tZL,TMPnoINT \tbrcc\tNoIncBackupPage \tinc\t\tZH NoIncBackupPage:  \tldi\t\tR22, PAGESIZEB BackupPageLoop: \tlpm\t\tTMPnoINT,Z+ \tst\t\tY+,TMPnoINT \tdec\t\tR22 \tbrne\tBackupPageLoop \tret \/\/--------- Add received data to SRAM Page WriteReceivedData: \t\/* Have Data For Write ? *\/ \tcpi\t\tI2c_wr_counter,0x00 \tbrne\tDataForWritePresent \tret DataForWritePresent:  \trcall BackupFlashPage  \tldi\t\tYH,high(_I2c_FLASH_buffer) ; Load SRAM Backup Buffer Address \tldi\t\tYL,low(_I2c_FLASH_buffer)  \tldi\t\tXH,high(_I2c_data_buffer) ; Load SRAM Receive Buffer Address \tldi\t\tXL,low(_I2c_data_buffer)  \tmov\t\tTMPnoINT, I2c_start_addr \tandi\tTMPnoINT, (PAGESIZEB - 1)  \tadc\t\tYL,TMPnoINT \tbrcc\tNoIncPreparePage \tinc\t\tYH NoIncPreparePage:  \tmov\t\tCounterInWrite,TMPnoINT \t\/* Make PAGE SIZE Window *\/ \tcpi\t\tI2c_wr_counter, I2C_PAGE_SIZE \tbrlo\tPreparePageLoop \tldi\t\tI2c_wr_counter, I2C_PAGE_SIZE PreparePageLoop: \tld\t\tR22,X+ \tst\t\tY+,R22  \tdec\t\tI2c_wr_counter \tbreq\tNormalPageWrite  \tmov\t\tTMPnoINT,CounterInWrite \tcpi\t\tTMPnoINT, (PAGESIZEB - 1) \tbrne\tNoWritePageSizeExceeded  \trcall\tErase_page_by_SPM \trcall\tWrite_Current_Page  \tinc\t\tCounterInWrite \tinc\t\tI2c_start_addr \tdec\t\tI2c_wr_pointer  \trjmp\tWriteReceivedData  NoWritePageSizeExceeded:  \tinc\t\tCounterInWrite \tinc\t\tI2c_start_addr \tdec\t\tI2c_wr_pointer  \trjmp\tPreparePageLoop  NormalPageWrite: \trcall\tErase_page_by_SPM \trcall\tWrite_Current_Page  \tinc\t\tI2c_start_addr \tdec\t\tI2c_wr_pointer \tret \/\/--------- Erase page Erase_page_by_SPM: \tldi\t\tZH,high(MemoryBlockFLASH &lt;&lt; 1) \tldi\t\tZL,low(MemoryBlockFLASH &lt;&lt; 1)  \tmov\t\tTMPnoINT,I2c_start_addr \tandi \tTMPnoINT, ((I2C_EEP_SIZE - 1) &amp; ~(PAGESIZEB - 1)) \/* Mask Maximum Data Size and Mask Out Real Flash Page Size *\/ \tadc\t\tZL,TMPnoINT \tbrcc\tNoIncErasePage \tinc\t\tZH NoIncErasePage: \t\/* Load Erase Instruction *\/ \tldi\t\tTMPnoINT, (1&lt;&lt;PGERS) | (1&lt;&lt;SPMEN) \tsts\t\t_valSPMCSR, TMPnoINT \trcall\tWait_spm\t;CPU Halted while erase \tret  \/\/Wite page Write_Current_Page: \tldi\t\tXH,high(_I2c_FLASH_buffer) ; Load SRAM Backup Buffer Address \tldi\t\tXL,low(_I2c_FLASH_buffer)  \tldi\t\tZH,high(MemoryBlockFLASH &lt;&lt; 1) \tldi\t\tZL,low(MemoryBlockFLASH &lt;&lt; 1)  \tmov\t\tTMPnoINT,I2c_start_addr \tandi \tTMPnoINT, ((I2C_EEP_SIZE - 1) &amp; ~(PAGESIZEB - 1)) \/* Mask Maximum Data Size and Mask Out Real Flash Page Size *\/ \tadc\t\tZL,TMPnoINT \tbrcc\tNoIncWritePage \tinc\t\tZH NoIncWritePage:  \tldi\t\tTMPnoINT, (PAGESIZE) \tmov\t\tCounter, TMPnoINT  \tmovw\tY,Z\t\t\t; Store Z in Y reg \tclr\t\tZL\t\t\t;Clear Z \tclr\t\tZH Fill_Page_Buffer_loop: \tld\t\tR0, X+ \tld\t\tR1, X+  \tldi\t\tTMPnoINT, (1&lt;&lt;SPMEN)\t;Write word into page buffer \tsts\t\t_valSPMCSR, TMPnoINT \trcall\tWait_spm\t;CPU Halted while erase  \tadiw\tZ, 2 \tdec\t\tCounter \tbrne\tFill_Page_Buffer_loop\t  \tmovw\tZ,Y\t\t\t; Restore Z from Y reg  \tldi \tTMPnoINT, (1&lt;&lt;PGWRT) | (1&lt;&lt;SPMEN) \tsts\t\t_valSPMCSR, TMPnoINT \trcall\tWait_spm\t;CPU Halted while erase \tret  Do_spm: ; check for previous SPM complete Wait_spm: \tin\tTMPnoINT, SPMCSR \tsbrc TMPnoINT, SPMEN \trjmp Wait_spm Wait_ee: \tsbic EECR, EEWE \trjmp Wait_ee ; SPM timed sequence \tlds\tTMPnoINT, _valSPMCSR \tout SPMCSR, TMPnoINT \tspm \tret  .cseg .org\t(0x200 - (I2C_EEP_SIZE\/2)) MemoryBlockFLASH:          ; Bytes in Flash    .DB 0x55, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F    .DB 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F    .DB 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F    .DB 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F    .DB 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F    .DB 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F    .DB 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F    .DB 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D    ; Mark End of EEP DATA .org\t(0x1FF) \t.db 0x7E,0x7F  .MESSAGE \"I2C For Read\/Write Processing SELFPRGEN FUSE Must Be Enabled!!!\"  .eseg MemoryBlockEEP:          ; Bytes in EEP    .DB 0x55, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F    .DB 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F    .DB 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F    .DB 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412\u0441\u0435\u043c \u0434\u043e\u0431\u0440\u0430 \u0438 \u0443\u0441\u043f\u0435\u0445\u043e\u0432!!!<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<\/p>\n<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/533922\/\"> https:\/\/habr.com\/ru\/post\/533922\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u0447\u0442\u043e \u0442\u0443\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u043d\u0443 I2C \u043d\u0443 \u0431\u0435\u0437 TWI.<\/p>\n<p>\u041c\u043e\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u0431\u0441\u0442\u043e\u044f\u043b\u0430 \u0447\u0443\u0442\u044c \u0448\u0438\u0440\u0435, \u0432 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u043b\u0441\u044f \u0447\u0438\u043f \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 &#171;Reset&#187; \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, \u0434\u043b\u044f \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 \u043c\u0435\u0441\u0442\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0435, \u0437\u0430\u0434\u0430\u0447\u0430 \u044d\u0442\u043e\u0433\u043e \u0447\u0438\u043f\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043b\u0430 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u0438\u043c\u043f\u0443\u043b\u044c\u0441 \u043a\u0430\u043a \u0441\u0438\u0433\u043d\u0430\u043b \u043a \u043d\u0430\u0447\u0430\u043b\u0443 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 &#171;\u0434\u043b\u0438\u043d\u043d\u043e\u0433\u043e&#187; \u0441\u0431\u0440\u043e\u0441\u0430, \u0447\u0438\u043f \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u043b \u043e\u0434\u043d\u0443 \u0438\u0437 \u043b\u0438\u043d\u0438\u0439 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432 \u043d\u0438\u0437\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 (\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0438\u0437 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u043e\u0432 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430, \u043d\u043e \u043b\u0438\u043d\u0435\u0439\u043a\u0430 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u043e\u0432 \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0430 \u043f\u043e\u0447\u0442\u0438 80 \u044f\u0447\u0435\u0435\u043a \u0432 CPLD EPM240T100 \u0438 \u043c\u0435\u0441\u0442\u043e \u0442\u0430\u043c \u043e\u0439 \u043a\u0430\u043a \u043d\u0443\u0436\u043d\u043e) \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u044d\u0442\u043e\u0442 \u0447\u0438\u043f \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u043b \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e \u0448\u0438\u043d\u0435 I2C \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 1 (mode1).<\/p>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0440\u0438 \u0440\u0435\u0436\u0438\u043c\u0430 I2C, 2-\u043e\u0439 \u0438 3-\u0438\u0439 \u0440\u0435\u0436\u0438\u043c\u044b \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u044b \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u043d\u0430 \u0448\u0438\u043d\u0435 I2C \u0432\u0438\u0441\u0438\u0442 \u0433\u0438\u0440\u043b\u044f\u043d\u0434\u0430 \u0438\u0437 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c \u043d\u0430 \u0448\u0438\u043d\u0435 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 2 \u0438 3 \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e, \u0437\u0430\u0442\u0435\u043c \u0443\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u043d\u0435\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0438 \u0434\u0430\u043d\u043d\u044b\u0435. \u0420\u0435\u0436\u0438\u043c 1 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0440\u0435\u0436\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u044b I2C, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0440\u0430\u0437\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 \u0447\u0438\u043f \u0430\u0434\u0440\u0435\u0441 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u043b\u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u0412\u043e\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e \u0447\u0435\u043c \u044f \u0433\u043e\u0432\u043e\u0440\u044e (MODE1):<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u044d\u0442\u043e MODE2:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0442\u0443\u0442 \u0432\u0441\u0451 \u0438\u0442\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043d\u043e! \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u0437\u0430\u0434\u0430\u0447\u0438:<\/p>\n<ol>\n<li>\n<p>\u0412 ATTINY13 \u043d\u0435\u0442 \u0430\u043f\u043f\u0430\u0440\u0430\u0442\u043d\u043e\u0433\u043e I2C.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0438\u043f \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0435\u0449\u0451 \u0438 \u0441\u0431\u0440\u043e\u0441 (\u0445\u043e\u0442\u044f \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u044d\u0442\u043e \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u0432\u0430\u0436\u043d\u043e).<\/p>\n<\/li>\n<li>\n<p>\u0418 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 24&#215;01 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043c EEP 128 \u0431\u0430\u0439\u0442, \u0430 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0447\u0438\u043f\u0435 EEPROM \u043e\u0431\u044a\u0435\u043c\u043e\u043c \u0442\u043e\u043b\u044c\u043a\u043e 64 \u0431\u0430\u0439\u0442\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u0442\u0430\u0432\u0438\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0430 \u0448\u0438\u043d\u0435, \u043a\u043e\u0434\u043e\u043c, &#8212; \u0442\u0443\u0442 \u0434\u043b\u044f \u043d\u0430\u0441 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440, \u0432\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u044d\u0442\u043e \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0441\u0431\u0440\u043e\u0441\u0430, \u0430 \u0432\u043e\u0442 \u0442\u0440\u0435\u0442\u044c\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u0422\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438 FLASH \u043d\u0435 \u0437\u0430\u043d\u044f\u0442\u043e\u0439 \u043d\u0430\u0448\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u043d\u043e EEPROM \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0431\u0430\u0439\u0442\u043d\u043e, \u0430 FLASH \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u043c\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u043e FLASH \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u044f \u043e\u0431\u044f\u0437\u0430\u043d \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432 \u0432\u0441\u0435\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, &#171;\u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c&#187; \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430, \u0441\u0442\u0435\u0440\u0435\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0441\u043e\u0441\u0442\u0430\u0432 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043f\u0430\u0441\u0442\u044c\u0441\u044f \u0432 \u0441\u043c\u0435\u0436\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430 \u0441\u0442\u044b\u043a\u0430\u0445. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u044f \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0434\u0432\u0430 \u044d\u0442\u0430\u043f\u0430:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u044f \u0442\u0430\u043a \u043f\u043e\u043d\u0438\u043c\u0430\u044e \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043b\u0438\u0440\u0438\u043a\u0430 \u043c\u0430\u043b\u043e \u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442, \u0442\u0443\u0442 CTRC+C \u0438 CTRL+V \u0447\u0430\u0449\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u0443\u0436\u0435 \u043a\u043e\u0434.<\/p>\n<p>\u0422\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u0435\u0440\u0432\u0430 \u041a\u043e\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438:<\/p>\n<ol>\n<li>\n<p>CHIP_PINOUTS &#8212; \u041a\u0430\u043a \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434\u044b \u043d\u0430 \u0447\u0438\u043f\u0435 (FT24Cxx &#8212; \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u043a\u0430 \u0447\u0438\u043f\u0430 I2C, InDRIVE_v4 &#8212; \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u043a\u0430 \u043f\u043e\u0434 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c \u0441\u0431\u0440\u043e\u0441\u0430).<\/p>\n<\/li>\n<li>\n<p>I2C_MODE &#8212; \u0420\u0435\u0436\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u044b I2C (MODE_1 \u0438 MODE_2).<\/p>\n<\/li>\n<li>\n<p>I2C<em>PAGE<\/em>SIZE &#8212; \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b I2C \u043f\u0440\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<\/li>\n<li>\n<p>I2C<em>EEP<\/em>SIZE &#8212; \u043e\u0431\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0438\u043f\u0430 (\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u043a\u043e\u0434\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 64 \u0431\u0430\u0439\u0442\u0430 EEPROM, \u0437\u0430\u0442\u0435\u043c \u0440\u0430\u0441\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442 &#171;\u043e\u0441\u0442\u0430\u0442\u043a\u0438&#187; \u0432\u043e FLASH).<\/p>\n<\/li>\n<li>\n<p>RESET_CNT &#8212; \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0441\u0431\u0440\u043e\u0441\u0430 (ON &#8212; \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, OFF &#8212; \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442).<\/p>\n<\/li>\n<\/ol>\n<h2>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435, \u0434\u043e\u0441\u0442\u0430\u0435\u043c TLL866<\/h2>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043e\u0442\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 (AVR Studio v4), \u044f \u043f\u0440\u043e\u043b\u0438\u0441\u0442\u0430\u043b \u0432 \u043a\u043e\u043d\u0435\u0446 \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432 &#171;\u043f\u0441\u0435\u0432\u0434\u043e EEP&#187;:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p> \u0421\u0442\u0430\u0432\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0431\u0438\u0442\u044b \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043c\u0438\u043a\u0440\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 \u043d\u0430\u0448\u0443 ATTINY13:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0410\u0433\u0430, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044f \u0447\u0438\u043f \u043f\u0438\u0448\u0435\u043c \u0435\u0433\u043e \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 I2C EEPROM Mode1 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0427\u0442\u043e \u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 I2C EEP \u0434\u043b\u044f ATTINY13<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">\/* \tInDRIVE v4 Application (chip like: FT24C01, Selfprg Must Be Enabled!!! )  \tFuse BYTES \tLow(0x7A) : \t\tHigh(0xEE) : \tSPIEN = 1\t\tSELFPRGEN = 1 \tEESAVE = 0\t\tDWEN = 0 \tWDTON = 0\t\tBODLEVEL1 = 0 \tCKDIV8 = 0\t\tBODLEVEL0 = 0 \tSUT1 = 0\t\tRSTDISBL = 1 \tSUT0 = 1 \tCKSEL1 = 0 \tCKSEL0 = 1  *\/  .include \"tn13def.inc\"  \/* On\/Off Defines *\/ .equ\tOFF\t\t\t=0 .equ\tON\t\t\t=1 \/* Chip Pinouts *\/ .equ\tFT24Cxx\t\t=0 .equ\tInDRIVE_v4\t=1  \/* Reset Controller Enable\/Disable *\/ .equ\tRESET_CNT\t=OFF \/* Chip Pinouts Define: InDrivev4\/Regular I2C Chip *\/ .equ\tCHIP_PINOUTS\t=FT24Cxx  .equ\tDEBUG\t\t=OFF \/* I2C Mode Define MODE 1\/MODE 2 *\/ .equ\tMODE_1\t\t=1 .equ\tMODE_2\t\t=2 .EQU\tI2C_MODE\t=MODE_1  \/* Define I2C Parameters *\/ \/* Page Size for Write in BYTES 4\/8\/16 *\/ \/* 128\/256 Size in MODE 1 Protocol can't receive more than 128 Bytes *\/ .IF I2C_MODE == MODE_2 \t.MESSAGE \"Compile for I2C Mode 2\" .equ\tI2C_PAGE_SIZE\t=8 .equ\tI2C_EEP_SIZE\t=256 .ELSE \t.MESSAGE \"Compile for I2C Mode 1\" .equ\tI2C_PAGE_SIZE\t=4 .equ\tI2C_EEP_SIZE\t=128 .ENDIF  \/*  Modes Define  \tA - Address \tiD - Data From Master \toD - Data To Master  \tMODE 1 \t\tWrite - [START][AAAAAAA0][iD + 0]...[iD + I2C_PAGE_SIZE - 1][STOP] \t\tRead -  [START][AAAAAAA1][oD + 0]...[oD + I2C_EEP_SIZE - 1][STOP] \tMODE 2  \t\tWrite - [START][10100000][AAAAAAAA][iD + 0]...[iD + I2C_PAGE_SIZE - 1][STOP] \t\tRead -  [START][10100001][oD + 0]...[oD + I2C_EEP_SIZE - 1][STOP] *\/  \/* \tI2C slave, fSCL = 400kHz \tFULLY Implemented I2C Protocol for 24xx01\/24xx02 \tAnd RESET Controller FOR InDRIVE(v4)  **************************************************************    \tATTINY13A I2C Configuration **************************************************************       \tpin configuration InDRIVE v4:                         ,---_---.     (RESET\/PB5)     nc |1     8| VCC           (PB3)  inRST |2     7| SCL  \t(PB2)           (PB4) outRST |3     6| EMU24X (PB1) SDA pin from CORE                    GND |4     5| nc \t(PB0) unused SDA pin                        `-------'     \tpin configuration FT24C01:                         ,---_---.     (RESET\/PB5)     nc |1     8| VCC         \t  (PB3)  \tnc |2     7| nc  \t(PB2)       \t    (PB4) \tnc |3     6| SCL \t(PB1) SCL pin I2C                    GND |4     5| SDA \t(PB0) SDA pin I2C                        `-------'     \tpin configuration FT24C02:                         ,---_---.     (RESET\/PB5)     A0 |1     8| VCC        \t   (PB3)  \tA1 |2     7| nc  \t(PB2)       \t    (PB4) \tA2 |3     6| SCL \t(PB1) SCL pin I2C                    GND |4     5| SDA \t(PB0) SDA pin I2C                        `-------'  *\/ \/* Pins Define *\/ .IF CHIP_PINOUTS == InDRIVE_v4 \t.MESSAGE \"Chip Pinouts: InDRIVE v4\" .equ\tEMU24X\t= 1 .equ \tSCL \t= 2 .ELSE .equ\tEMU24X\t= 0 .equ \tSCL \t= 1 \t.MESSAGE \"Chip Pinouts: Regular 24Cxx\" .ENDIF .equ \tSDA \t= EMU24X .equ \tACK \t= SDA .equ\tinRST\t= 3 .equ\toutRST\t= 4   .def\tTMPnoINT\t\t=R19 .def\tCounter\t\t\t=R3 .def\tCounterInWrite\t=R4 .def\tSREGST\t\t\t=R5  \/* Real ATTINY13A FLASH Page SIZE In Bytes *\/ .equ\tPAGESIZEB\t\t=(PAGESIZE*2)  \/* SRAM Mapping *\/ .DSEG .IF I2C_MODE == MODE_2 \t_I2c_device_inaddr:  .BYTE 1\t\/* MODE 2 Region *\/ \t_I2c_device_myaddr:  .BYTE 1 .ENDIF \t_valSPMCSR: .BYTE 1 \t_I2c_data_buffer:\t.BYTE I2C_PAGE_SIZE \t_I2c_FLASH_buffer:\t.BYTE PAGESIZEB .cseg  \/* Read\/Write Pointers *\/ .def\tI2c_start_addr\t=R16 .def\tI2c_wr_counter\t=R17 .def\tI2c_wr_pointer\t=R18 .def\tI2c_rd_pointer\t=R21  .def\t_PINB\t\t\t=R20  .IF I2C_MODE != MODE_2 \t.IF I2C_MODE != MODE_1 \t\t.error \"Invalid mode for I2C Selected, please correct I2C_MODE define\" \t.ENDIF .ENDIF  .cseg  .org 0\/\/Reset .IF RESET_CNT == ON \t\trjmp\tWaitinRSTHI\t\t;RESET \t\treti\t\t\t\t\t;INT0addr\t= 0x0001\t; External Interrupt 0 \t\trjmp\tResetInProcess\t;PCI0addr\t= 0x0002\t; External Interrupt Request 0 .ELSE \t\trjmp\tmain\t\t\t;RESET \t\treti\t\t\t\t\t;INT0addr\t= 0x0001\t; External Interrupt 0 \t\treti\t\t\t\t\t;PCI0addr\t= 0x0002\t; External Interrupt Request 0 .ENDIF \t\treti\t\t\t\t\t;OVF0addr\t= 0x0003\t; Timer\/Counter0 Overflow \t\treti\t\t\t\t\t;ERDYaddr\t= 0x0004\t; EEPROM Ready \t\treti\t\t\t\t\t;ACIaddr\t= 0x0005\t; Analog Comparator \t\treti\t\t\t\t\t;OC0Aaddr\t= 0x0006\t; Timer\/Counter Compare Match A \t\treti\t\t\t\t\t;OC0Baddr\t= 0x0007\t; Timer\/Counter Compare Match B \t\treti\t\t\t\t\t;WDTaddr\t= 0x0008\t; Watchdog Time-out \t\treti\t\t\t\t\t;ADCCaddr\t= 0x0009\t; ADC Conversion Complete  \/\/ ******************************************************************************************* \/\/ **   Reset Processor                                                       \t\t\t\t** \/\/ ******************************************************************************************* .IF RESET_CNT == ON \t.MESSAGE \"Reset Controller Function is: ON\" ResetInProcess:\t;Proccess reset \t\tsbic\tpinb,inRST\t;Process reset on falling edge \t\treti  WaitinRSTHI: \t\tcli  \t\t;Wait ~80 mS 0x04E360 on 9.6MHz \t\tldi\t\tR16,0x10 \t\tldi\t\tR17,0xE3 \t\tldi\t\tR18,0x60 \t\t;Set RESET Enable \t\tcbi\t\tPORTB,outRST  _CntLO: \t\tdec\t\tR18 \t\tBRNE\t_CntLO _CntME: \t\tdec\t\tR17 \t\tBRNE\t_CntLO _CntHI: \t\tdec\t\tR16 \t\tBRNE\t_CntLO  \t\t; And Clear Iterrupt flag for normal exit \t\tldi\t\tR16,(1 &lt;&lt; PCIF) \t\tout\t\tGIFR,R16 .ELSE \t.MESSAGE \"Reset Controller Function is: OFF\" .ENDIF\t\/\/ RESET_CNT == ON \t\t \/\/ ******************************************************************************************************* \/\/ **   Main Programm                                                         \t\t\t\t** \/\/ ******************************************************************************************************* main: \t\t;init STACK \t\tldi\t\tTMPnoINT,low(RAMEND) \t\tout\t\tSPL,TMPnoINT  \t\t;init IO \t\tldi\t\tTMPnoINT,0x00 \t\tout\t\tMCUCR,TMPnoINT \t\t;Outputs to HI (Pull UP) \t\tldi\t\tTMPnoINT,0xFF \t\tout\t\tPORTB,TMPnoINT .IF RESET_CNT == ON \t\t;Output enable for outRST, all other for input \t\tsbi\t\tPORTB, outRST \t\tsbi\t\tPINB, inRST \t\tsbi\t\tDDRB,outRST\t; Output Enable \t\t;Init Interrupt\t\t     \tldi \tTMPnoINT, (1 &lt;&lt; inRST)\t; set pin change interrupt for inRST     \tout \tPCMSK, TMPnoINT\t\t \t\tldi\t\tTMPnoINT, (1&lt;&lt;PCIE)\t\t; unmask interrupt PCIE \t\tout\t\tGIMSK,TMPnoINT \t\tSEI\t\t\t\t\t;Enable PCIE Int Processing .ELSE \t\tCLI\t\t; Disable Reset Controller .ENDIF  .IF I2C_MODE == MODE_2 \t\t\/* Set I2C Device Address *\/ \t\tldi\t\tTMPnoINT, 0xA0 \t\tsts\t\t_I2c_device_myaddr,TMPnoINT .ENDIF  \t\t\/* Clear Buffer Pointers *\/ \t\tclr\t\tI2c_wr_counter \t\tclr\t\tI2c_wr_pointer \t\tclr\t\tI2c_start_addr \t\tclr\t\tI2c_rd_pointer   main_loop:  lI2c_get: \tsbi portb,ack \tsbis pinb,scl                                            ;wait for SCL&amp;SDA=1 \trjmp lI2c_get \tsbis pinb,sda \trjmp lI2c_get lI2c_wait_for_start: \tsbis pinb,scl                                            ;wait for SCL=1,SDA=0 (START) \trjmp lI2c_get \tsbic pinb,sda \trjmp lI2c_wait_for_start lI2c_get_0:                                                  ;clear receive area .IF I2C_MODE == MODE_2 \tclr r22 \tsts _I2c_device_inaddr,r22 .ENDIF lI2c_get_1:                                                  ;get 1st byte \tsbi portb,ack lI2c_10:                                           <\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-315165","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/315165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=315165"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/315165\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=315165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=315165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=315165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}