summaryrefslogtreecommitdiffhomepage
path: root/digital/avr/modules/spi
diff options
context:
space:
mode:
authorNicolas Schodet2008-03-02 11:26:02 +0100
committerNicolas Schodet2008-03-02 11:26:02 +0100
commita87ddfd43ed21ce3227b41624066d2b4ea468e7e (patch)
treeecacfaa3b54ecf8417dc6b0c2609331df2c67bab /digital/avr/modules/spi
parenta276fe77c7289d4955b947250a778cf780287147 (diff)
* digital/avr/modules/spi, digital/avr/modules/flash:
- master should drive SS. - to receive, master should send something. - testing SPIF before the first sent does not work. - fixed flash test.
Diffstat (limited to 'digital/avr/modules/spi')
-rw-r--r--digital/avr/modules/spi/spi.c14
-rw-r--r--digital/avr/modules/spi/spi.h2
2 files changed, 11 insertions, 5 deletions
diff --git a/digital/avr/modules/spi/spi.c b/digital/avr/modules/spi/spi.c
index 9039e267..73cb1706 100644
--- a/digital/avr/modules/spi/spi.c
+++ b/digital/avr/modules/spi/spi.c
@@ -26,8 +26,6 @@
#include "common.h"
#include "spi.h"
-#define SPI_DIRVER_SIGNAL SIGNAL_SPI
-
/** For host */
#ifdef HOST
static uint8_t SPCR;
@@ -50,6 +48,9 @@ spi_init(uint8_t sprc)
/* Master configuration. */
if (sprc & _BV(MSTR))
{
+ SPI_PORT |= _BV(SPI_BIT_SS);
+ SPI_DDR |= _BV(SPI_BIT_SS);
+
SPI_DDR &= ~_BV(SPI_BIT_MISO);
SPI_PORT &= ~_BV(SPI_BIT_MISO);
@@ -61,6 +62,9 @@ spi_init(uint8_t sprc)
}
else
{
+ SPI_DDR &= ~_BV(SPI_BIT_SS);
+ SPI_PORT |= _BV(SPI_BIT_SS);
+
SPI_PORT |= _BV(SPI_BIT_MISO);
SPI_DDR |= _BV(SPI_BIT_MISO);
@@ -81,10 +85,9 @@ spi_init(uint8_t sprc)
void
spi_send(uint8_t data)
{
+ SPDR = data;
// Wait the end of the transmission.
while(!(SPSR & _BV(SPIF)));
-
- SPDR = data;
}
/** Receive a data from the SPI bus.
@@ -93,6 +96,7 @@ spi_send(uint8_t data)
uint8_t
spi_recv(void)
{
+ SPDR = 0;
/* Wait for reception complete */
while(!(SPSR & _BV(SPIF)));
@@ -107,10 +111,10 @@ spi_recv(void)
uint8_t
spi_send_and_recv (uint8_t data)
{
+ SPDR = data;
// Wait the end of the transmission.
while(!(SPSR & _BV(SPIF)));
- SPDR = data;
return SPDR;
}
diff --git a/digital/avr/modules/spi/spi.h b/digital/avr/modules/spi/spi.h
index e7e2caa8..9d43eec0 100644
--- a/digital/avr/modules/spi/spi.h
+++ b/digital/avr/modules/spi/spi.h
@@ -30,10 +30,12 @@
#define SPI_PORT PORTB
#if defined (__AVR_ATmega128__)
+#define SPI_BIT_SS 0
#define SPI_BIT_SCK 1
#define SPI_BIT_MOSI 2
#define SPI_BIT_MISO 3
#elif defined (__AVR_ATmega16__)
+#define SPI_BIT_SS 4
#define SPI_BIT_SCK 7
#define SPI_BIT_MOSI 5
#define SPI_BIT_MISO 6