SPI Master receive?

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

Hey guys, Im trying to make a nice little project that will allow people to use USART to reset chips to factory fusebits, using of course SPI... now I really have not started the project execpt some simple code for just testing spi sending and master stuff like that... now I have been studying the serial downloading information inside datasheets (mainly attiny13, its going to be my ginny pig) and Im pretty sure I understand how it works just fine like here is the 'read fuse bits' command

|  byte 1 |  byte 2  |  byte 3  |  byte4  |
 0101 0000--0000 0000--xxxx xxxx--oooo oooo

x = Doesent matter, so Ill just send 1's
o = fuse bits, 1 = unprogrammed

my question is, when in master mode, can you read bits as well? or am i going to have to switch between master to slave before the fourth byte? I havent really ever used SPI before!

Last Edited: Fri. Feb 9, 2007 - 08:53 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think that when ever a byte is sent by the master, say a command, it is expected that something will be returned, as well.

So, the master sends a dummy to the slave. The current status of the slave might come back from at the same time, assuming that it was recently updated. If the slave status is ok, a command is sent and, again, the current slave status might be returned. The command gets processed and, hopefully after a very short processing delay, the the data is sent to the slave. A dummy is sent to the slave and the newly updated status is returned to the master.

While this might not be exactly correct, it is close.

It has been at least 5 years since I hace messed with SPI so, there is much room for error here.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

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

SPI uses the master/slave system, where the master provides the clock and the slave responds. It's rigged as a simple ringbuffer, thus for each bit shifted out a bit is shifted in.

The master is the only device that can initiate a byte transfer, and it does that by sending a byte to the slave. Each time the master's data bit is shifted in, the slave's response to the previous command is shifted in. If you only wish to receive data from the slave, you need to send a dummy byte (0x00) to the slave.

The latest ButtLoad firmware contains a fuse recovery mode, which provides a guaranteed (via cycle-correct assembly code) Fspi*8 clock to the slave to allow for the recovery of borked fuses. You might want to have a look at it for the "Enter programming" code and fuse writing code.

Note that if you want to be able to reset the SPIEN fuse (if it was accidentally disabled) you will have to support the HVPP or HVSP protocols.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!