aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2016-05-19 15:55:05 +0200
committerLinus Nordberg <linus@nordberg.se>2016-05-19 15:55:05 +0200
commitc114fb9c06b3547cd90990610cda98cc6e5be495 (patch)
tree31ad3fdcae9dccedd0434a9079ff141cc471f01d
parentb5d1271563e6dc7c1f77def13351e0d025428a36 (diff)
Explain SPI dummy write in comments.
-rw-r--r--tamper.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/tamper.c b/tamper.c
index d4db2b9..2893a6c 100644
--- a/tamper.c
+++ b/tamper.c
@@ -111,14 +111,23 @@ spi_setup(int on_flag)
static inline void
spi_write(uint8_t val)
{
+ /* Move the value to be sent to the SPI slave into the SPI
+ register. This starts the SPI clock. */
SPDR = val;
+
+ /* Wait for the byte to be shifted into the slave. */
loop_until_bit_is_set(SPSR, SPIF);
}
static inline uint8_t
spi_read()
{
+ /* Start clocking the SPI slave by moving a dummy byte (0) into the
+ SPI register and wait for the byte from the slave to be shifted
+ in. */
spi_write(0);
+
+ /* Read the SPI register and return the value. */
return SPDR;
}