The USIDR register for serial communication on the Attiny85 is 8-bit. If I need to send 32-bits, can I write each byte sequentially as fast as the program can run, or do I need to delay between each write operation?
-
1\$\begingroup\$ What does the data sheet and examples there say how and when you are allowed to write to that register? \$\endgroup\$– JustmeMay 13 at 9:17
-
\$\begingroup\$ You do need to wait for the register to shift out before writing the next value as @asdfesx points out. I think the very fastest you can do is using the technique in this article... wp.josh.com/2015/09/29/bare-metal-fast-spi-on-avr ...which describes cycle counting to do sequential blind writes to the SPI buffer, but same trick should work with the USI buffer. \$\endgroup\$– bigjoshMay 15 at 4:24
1 Answer
The USI in these old Attiny controllers is a very basic building block. It's not able to send data on its own after putting data to a register. That's a major difference to the USART, UART, SPI or TWI blocks available in most newer Attiny and Atmega controllers.
USIDR is just a register to put data to - there is no buffering and no automatic start of sending data. That means you can write a byte to this register, then you need to start the actual sending (by setting USIOIF to 1), wait for the end of transmission (USIOIF is read as 1) and then you can write another byte. The data sheet shows a block of code for this in chapter 15.3.2 on page 110.
Note that in this example even the clock for transmitting the data is generated in software! That's very unusual for any integrated serial interface module - although you can automate it by using the TIMER0 as the source of the clock.