I have not been able to find an answer to this question, perhaps someone could help me understand the hardware SPI function as described in the 328 datasheet.
Background
I am trying to use an Arduino UNO R3 as an SPI slave, no response is sent to the master. I do not have a logic analyzer available, however using my oscilloscope incoming data is formatted like this:
SS idles high, goes low for each frame
SCK: idles high, data on leading edge falling, clock pulses are about 300ns wide and 4us apart or 250kHz
A packet of 7 data frames is sent every 750 milliseconds.
The first 3 data frames contain 12 bits each, the remaining 4 contain 17 bits each.
Questions
It is my understanding that the SPIF interrupt flag is set each time a complete byte is received. If I use the SPI interrupt to store bytes received or poll the SPSR register, how do I save the bits received that do not make a complete byte and thus do not set SPIF?
According to the datasheet:
When configured as a Slave, the SPI interface will remain sleeping with MISO tri-stated as long as the SS pin is
driven high. In this state, software may update the contents of the SPI Data Register, SPDR, but the data will not
be shifted out by incoming clock pulses on the SCK pin until the SS pin is driven low. As one byte has been
completely shifted, the end of Transmission Flag, SPIF is set. If the SPI Interrupt Enable bit, SPIE, in the SPCR
Register is set, an interrupt is requested. The Slave may continue to place new data to be sent into SPDR
before reading the incoming data. The last incoming byte will be kept in the Buffer Register for later use.
and also
19.3 SS Pin Functionality
19.3.1 Slave Mode
When the SPI is configured as a Slave, the Slave Select (SS) pin is always input. When SS is held low, the SPI
is activated, and MISO becomes an output if configured so by the user. All other pins are inputs. When SS is
driven high, all pins are inputs, and the SPI is passive, which means that it will not receive incoming data. Note
that the SPI logic will be reset once the SS pin is driven high.
The SS pin is useful for packet/byte synchronization to keep the slave bit counter synchronous with the master
clock generator. When the SS pin is driven high, the SPI slave will immediately reset the send and receive logic,
and drop any partially received data in the Shift Register.
So for example when SS goes low and I begin receiving data for the first frame, I assume that SPIF will be set after the first 8 bits are received and then the remaining 4 bits will be received but SS goes high before SPIF will be set. How do I save those last 4 bits as it seems from the data sheet that the any partially received data in the Shift Register is dropped immediately.
I have carefully studied the example code provided at Gammon Forum : Electronics : Microprocessors : SPI - Serial Peripheral Interface - for Arduino, and many other Google searches but haven't found an answer.
Thanks for any help!




