Evgenij LegotskojAug. 27, 2015, 7 a.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.
Support the author Donate

Comments

Only authorized users can post comments.
Please, Log in or Sign up
Fornex

Let me recommend you a great European Fornex hosting.

Fornex has proven itself to be a stable host over the years.

For Django projects I recommend VPS hosting

Following the link you will receive a 5% discount on shared hosting services, dedicated servers, VPS and VPN

View Hosting
V

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

  • Result:50points,
  • Rating points-4
DK

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

  • Result:20points,
  • Rating points-10
s
  • storm
  • Jan. 20, 2023, 10:30 p.m.

C++ - Тест 003. Условия и циклы

  • Result:0points,
  • Rating points-10
Popular publications in the last 90 Days
Last comments
S

Qt WinAPI - Lesson 004. QtIFW - Automation WinDeployQt and build installers with Qt Installer Framework

Hello Evgenij, regarding the online installer, I've tried many times to use web host for the created repo after repogen step. I tried using github but I found people talking it is not …
  • juvf
  • Jan. 17, 2023, 9:18 a.m.

Qt/C++ - Lesson 051. QMediaPlayer – simple audio player

PS. Почти дописал плеер на QML. Уперся в ограничения QML. Переписываю плеер на с++/qt, а графика останится в qml. Нашел то, что мне надо, а именно индикатор звука. Qt может перехватывать аудиопо…

Qt/C++ - Lesson 039. How to paint stroke in QSqlTableModel by value in the column?

В этом случае вижу только какой-нибудь костыль в стиле перебора по всем индексам в заголовке с помощью методу headerData . То есть пройтись в for цикле пока не будет совпадения н…
a
  • avt
  • Dec. 12, 2022, 8:06 p.m.

Qt/C++ - Lesson 039. How to paint stroke in QSqlTableModel by value in the column?

Спасибо за ответ. Нет, дело не в читаемости кода, в разных таблицах у меня есть столбцы с одинаковым именем, но с разными индексами. Хотел сделать решение по имени столбца для всех таблиц сразу.…
  • juvf
  • Dec. 12, 2022, 3:06 p.m.

Qt/C++ - Lesson 051. QMediaPlayer – simple audio player

Спасибо.
Now discuss on the forum

Как создать уникальное значение поля на основе существующих значений

В принципе это можно сделать так: def unique_field(self): return '{0}_{1}'.format(self.title, self.price)class Tovar(models.Model): title=models.CharField('Наименование',max_length=…
W
  • Wayne
  • Jan. 27, 2023, 12:47 p.m.

Здравствуйте помогите с qml

как сделать так, чтобы зеленая фигура при движения за пределы круга пропадала на qml
AB

Sorting the added QML elements in the ListModel

I am writing an alarm clock in QML, I am required to sort the alarms in ascending order (depending on the date or time (if there are several alarms on the same day). I've done the sorting …

QSqlRelatipnalTabelModel Qt 4.8.1 как получить id внешней связи?

Наконец-то готовы представить полноценное развитие Qt QSqlTableModel и QTableView. Посмотреть можно у нас на сайте здесь На github здесь здесь Радостная новос…
P
  • Pisych
  • Jan. 25, 2023, 10:01 p.m.

Ввод бухгалтерского документа в одной форме

вопрос снят. спасибо за ответы. сообразил, как сделать:)
About
Services
© EVILEG 2015-2022
Recommend hosting TIMEWEB