Evgenii Legotckoi
Evgenii LegotckoiAug. 26, 2015, 9 p.m.

USI in Attiny24 - settings of Two-wire mode

USI - Universal Serial Interface (Universal Serial Interface) is actually a workpiece for hardware serial transmit and receive data. This interface is not a ready-made solution for some specific data transmission protocol, but provides a more convenient way to transfer data than in the case of full software solution.

The essence of this interface is that it offers a level of hardware to transmit and receive serial data and protocol operation logic is the responsibility of the software implementation.


Interface Register Description USI

This interface contains only four registers, which are responsible for its operation:

  • USIDR - Data register
  • USIBR - register for data buffering
  • USISR - interface status register
  • USICR - control and interface configuration register

USIDR – USI Data Register

Data from this register is accessed directly, with a copy of the data can be found USIBR register. This register is used for both transmit and receive information.

USIBR – USI Data Buffer

This register is read-only, as opposed to USIDR. This register is copied data that fall into the register USIDR when receiving information from the outside. This minimizes data loss during high load on the system of reception and transmission, as well as give time microcontroller processor time to perform the preceding tasks that he is busy.

USISR – USI Status Register

USI interface status register contains the interrupt flags, flags of the status of data lines, and a counter that counts the number of bits to be transmitted in a data transmission line.

  • Bit 7 - USISIF: Start Condition Interrupt Flag - Flag determining the starting premise. Used in Two-wire mode. Cleared unit record.
  • Bit 6 - USIOIF: C ounter Overflow Interrupt Flag - interrupt flag overflow counter. This flag is raised when all the data bits transmitted in the transmission line. Cleared unit record.
  • Bit 5 - USIPF: Stop Condition Flag - Flag determining foot parcel, which is also used in the Two-Wire mode. Remarkably, this flag is not a flag of the interrupt. Cleared unit record.
  • Bit 4 - USIDC: Data Output Collision - This bit is used for master arbitration in Two-wire mode.
  • Bits 3: 0 - USICNT3: 0: Counter Value - counter bits. The counter value is taken from 0 to 15 for transmitting 8 bits. The counter can be incremented by external influences, by timer or by the software switch, namely the installation of USITC bit in USICR register. As used in this article.

USICR – USI Control Register

Register control and customization include the interrupt enable bits, set the operation mode, count source selection of gating data.

  • Bit 7 - USISIE: Start Condition Interrupt Enable - including interruption at a starting premise.
  • Bit 6 - USIOIE: Counter Overflow Interrupt Enable - including overflow interrupt counter.
  • Bit 5: 4 - USIWM1, USIWM0: Wire Mode - setting the data transfer mode.
  • Bit 3: 2 - USICS1, USICS0: Clock Source Select - installation source bits gating counter.
  • Bit 1 - USICLK: Clock Strobe - Bit strobe signal for the promotion of data link.
  • Bit 0 - USITC: Toggle Clock Port Pin - If this bit is set in the unit of a change in the status of the selected pin from 0 to 1 or from 1 to 0 (which is in the Two-Wire mode, works as SCL line).

Using the USI interface

This article shows a variant of the transmission bytes of information to the target device. Promotion of bits of information is carried out by changing the SCL line state from 0 to 1. The interface itself works in the Two-Wire mode. Data is transmitted on the SDA line. Given that the counter is incremented each time the USITC bit, then to transfer 8-bit data is required 16 times to set a bit USITC, as to set up Below is an option, in which the bit is transmitted to the data line only when you change the line state from 0 to 1.

;======= The initialization routine in USI TWO-wire mode operation ========================
 usi_init:
     sbi    PORTA,4       ; Is reset PORT SCL
     sbi    PORTA,6       ; Is reset PORT SDA
     sbi    DDRA,4        ; Is reset DDR SCL
     sbi    DDRA,6        ; Is reset DDR SDA
     ldi    r16,0xFF
     out    USIDR,r16
     ldi    r16,(0<<USISIE)|(0<<USIOIE)|(1<<USIWM1)|(0<<USIWM0)|(1<<USICS1)|(0<<USICS0)|(1<<USICLK)|(0<<USITC)  
                ; (0<<USISIE)|(0<<USIOIE) Disable interrupts on the counter and the start
                ; (1<<USIWM1)|(0<<USIWM0) Install the two-wire mode
                ; (1<<USICS1)|(0<<USICS0)|(1<<USICLK) Counter mode setting
                ; bit is transmitted by changing the SCL line state from 0 to 1
                ; (0<<USITC) the initial state of the output clock signal
     out    USICR,r16       ; Submitting byte received in USICR
     ldi    r16,(1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|(0x0<<USICNT0) ; Cleaning the flags and the counter is reset
     out    USISR,r16       ;Submitting byte received in USISR
     ret
 ;======= Sending information via the USI byte interface =================================
 usi_send:
     out    USIDR,r16       ; Loading data to USIDR
     ldi    r16,0xF0        ; Installing USISR counter to transfer 8 bits of data
     out    USISR,r16       ; Submitting byte received in USISR
     ldi    r16,(0<<USISIE)|(0<<USIOIE)|(1<<USIWM1)|(0<<USIWM0)|(1<<USICS1)|(0<<USICS0)|(1<<USICLK)|(1<<USITC)  
                ; (0<<USISIE)|(0<<USIOIE) Disable interrupts on the counter and the start
                ; (1<<USIWM1)|(0<<USIWM0) Install the two-wire mode
                ; (1<<USICS1)|(0<<USICS0)|(1<<USICLK) Counter mode setting
                ; (1<<USITC) the initial state of the output clock signal
 transfer:
     out    USICR,r16       ; Submitting byte received in USICR
     out    USICR,r16       ; Submitting byte received in USICR
     in     r17,USISR
     sbrs   r17,6
     rjmp   transfer
     ldi    r16,(1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|(0x0<<USICNT0) ; Cleaning flags
     out    USISR,r16       ; Submitting byte received in USISR
     ret
 ;========================================================================================
We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
d
  • dsfs
  • April 26, 2024, 1:56 a.m.

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:80points,
  • Rating points4
d
  • dsfs
  • April 26, 2024, 1:45 a.m.

C++ - Test 002. Constants

  • Result:50points,
  • Rating points-4
d
  • dsfs
  • April 26, 2024, 1:35 a.m.

C++ - Test 001. The first program and data types

  • Result:73points,
  • Rating points1
Last comments
k
kmssrFeb. 8, 2024, 3:43 p.m.
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
Qt WinAPI - Lesson 007. Working with ICMP Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
EVA
EVADec. 25, 2023, 7:30 a.m.
Boost - static linking in CMake project under Windows Ошибка LNK1104 часто возникает, когда компоновщик не может найти или открыть файл библиотеки. В вашем случае, это файл libboost_locale-vc142-mt-gd-x64-1_74.lib из библиотеки Boost для C+…
J
JonnyJoDec. 25, 2023, 5:38 a.m.
Boost - static linking in CMake project under Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
G
GvozdikDec. 18, 2023, 6:01 p.m.
Qt/C++ - Lesson 056. Connecting the Boost library in Qt for MinGW and MSVC compilers Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
Now discuss on the forum
G
GarApril 22, 2024, 2:46 a.m.
Clipboard Как скопировать окно целиком в clipb?
DA
Dr Gangil AcademicsApril 20, 2024, 4:45 a.m.
Unlock Your Aesthetic Potential: Explore MSC in Facial Aesthetics and Cosmetology in India Embark on a transformative journey with an msc in facial aesthetics and cosmetology in india . Delve into the intricate world of beauty and rejuvenation, guided by expert faculty and …
a
a_vlasovApril 14, 2024, 3:41 a.m.
Мобильное приложение на C++Qt и бэкенд к нему на Django Rest Framework Евгений, добрый день! Такой вопрос. Верно ли следующее утверждение: Любое Android-приложение, написанное на Java/Kotlin чисто теоретически (пусть и с большими трудностями) можно написать и на C+…
Павел Дорофеев
Павел ДорофеевApril 13, 2024, 11:35 p.m.
QTableWidget с 2 заголовками Вот тут есть кастомный QTableView с многорядностью проект поддерживается, обращайтесь
f
fastrexApril 4, 2024, 1:47 a.m.
Вернуть старое поведение QComboBox, не менять индекс при resetModel Добрый день! У нас много проектов в которых используется QComboBox, в версии 5.5.1, когда модель испускает сигнал resetModel, currentIndex не менялся. В версии 5.15 при resetModel происходит try…

Follow us in social networks