Hi Amforthers,

I was learning a bit about the internals of the SPI driver and finally found 
the "core" word c!@spi

I'm comparing side by side the assembler source with the 328P datasheet 
(=Arduino) and I can't understand completely the purpose of some of this code, 
which I list here for convenicence

do_spirw:
1.    out_ SPDR, tosl
do_spirw1:
2.    in_ temp0, SPSR
3.    cbr temp0,7
4.    out_ SPSR, temp0
5.    in_ temp0, SPSR
6.    sbrs temp0, 7
7.    rjmp do_spirw1   ; wait until complete
8.    in_ tosl, SPDR
9.    ret

In 1) we transmit a byte (and activate sthe SPI clock). Ok.
In 2) we read the status register, so far so good
In 3) we clear thr 3 least significant bits of ths status just read Why ?
In 4) we write the status register with the just modified byte. Why ?
In 5) we again read the stats register. Why ? 
&) to 9) is usual stuff

I don't really understand the purpose of the sequence given by steps 2 to 5.


- Bit 0 is the SPI2X: Double SPI Speed Bit in SPSR, if we clear it and write 
again to etatus register we are possibly changin the SPI clock rate.
- Bits 1 to 5 in SPSR are marked as reserved in 328P datasheet, so why setting 
these as 0 ?
 why the mask cover only three bits and not six bits ?
- Why we write the status register ? I have not seen any other effect of 
writting SPSR in the datasheet other than doubling the clock rate.

The only thing I an think of is that this is needed for other AVR models, so if 
someone can comment on this I would appreciate it.

Another issue

This code does a busy poll. I was wondering if it should instead call PAUSE 
instead
Two reasons that I can think of:

1) SPI is a high speed interface. Using PAUSE would degrade performance for the 
highest clock  rates.
2) We can't invoke PAUSE from inside this assembler word.

Which is the correct assumption ?



Best regards
Rafael
------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel

Reply via email to