USI Clocking for Speed

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is an example from the ATtiny25 data sheet pg 114. for getting the fastest transfer from the USI in three wire mode:

SPITransfer_Fast:
    out   USIDR,r16
    ldi   r16,(1<<USIWM0)|(0<<USICS0)|(1<<USITC)
    ldi   r17,(1<<USIWM0)|(0<<USICS0)|(1<<USITC)|(1<<USICLK)
    out   USICR,r16 ; MSB
    out   USICR,r17
    out   USICR,r16
    out   USICR,r17
    out   USICR,r16
    out   USICR,r17
    out   USICR,r16
    out   USICR,r17
    out   USICR,r16
    out   USICR,r17
    out   USICR,r16
    out   USICR,r17
    out   USICR,r16
    out   USICR,r17
    out   USICR,r16 ; LSB
    out   USICR,r17
    in    r16,USIDR
ret

My question why the alternating clocking calls with one as

ldi   r16,(1<<USIWM0)|(0<<USICS0)|(1<<USITC)

and the other as

ldi   r17,(1<<USIWM0)|(0<<USICS0)|(1<<USITC)|(1<<USICLK)

I would have figured 16 loads of r16 into the control register would have sufficed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Read the datasheet and here's what I found:

Quote:
• Bit 1 – USICLK: Clock Strobe
Writing a one to this bit location strobes the USI Data Register to shift one step and the counter to increment by one, provided that the software clock strobe option has been selected by writing USICS1:0 bits to Zero.
Quote:
• Bit 0 – USITC: Toggle Clock Port Pin
Writing a one to this bit location toggles the USCK/SCL value either from 0 to 1, or from 1 to 0.

So, you need to toggle the clock pin up AND down for each time you strobe the clock once. If you wrote a one to USICLK each time, you'd miss every other bit.

I have too many hobbies.
s-conductor.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmm, so just writing a one to USITC will only toggle the clock pin in this case.

In order to shift the data register, writing a one to USICLK is also required.

***

Oh, the USITC is just for the slave, it has nothing to do with the master operation in this case.

That is it lacks any effect on the counter or the data register.

***

OK, here's another question. What if this was done:

LDI R16, (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC)

Then

OUT USICR, R16

was repeated 16 times.

That sets up external clocking and tells the USI to use the USITC as a software strobe.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What does the manual (datasheet) say it will do with that setup? What do you think it will do?

I have too many hobbies.
s-conductor.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I am expecting that it will read the USCK pin as an external clock input. And because USICS0 is implicitly set to 0, it will read data on the 0 to 1 transition then change data on the 1 to 0 transition.

Although the state of the USCK pin will be controlled by toggling the USITC bit rather than by an external clock.

Also in this case the counter will be incremented a total of sixteen times, as opposed to the first case which would only result in the counter being incremented a total of eight times.

Do you see any errs in that?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Anybody?

Since I have set myself to task of creating the DLL to simulate the ATtiny25's USI peripheral for VMLab, I need to understand all these clocking details.

So if anybody is familiar with this, your help would be appreciated.