projects
/
goodfet
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Chipcon: peek and poke of xdata work.
[goodfet]
/
firmware
/
apps
/
spi
/
spi.c
diff --git
a/firmware/apps/spi/spi.c
b/firmware/apps/spi/spi.c
index
b0b5323
..
2ee2d2c
100644
(file)
--- a/
firmware/apps/spi/spi.c
+++ b/
firmware/apps/spi/spi.c
@@
-28,10
+28,13
@@
#define CLRCLK P5OUT&=~SCK
#define READMISO (P5IN&MISO?1:0)
#define CLRCLK P5OUT&=~SCK
#define READMISO (P5IN&MISO?1:0)
+
+
//! Set up the pins for SPI mode.
//! Set up the pins for SPI mode.
-
unsigned char
spisetup(){
+
void
spisetup(){
P5DIR|=MOSI+SCK+SS;
P5DIR&=~MISO;
P5DIR|=MOSI+SCK+SS;
P5DIR&=~MISO;
+ P5OUT|=SS;
}
//! Read and write an SPI bit.
}
//! Read and write an SPI bit.
@@
-39,7
+42,7
@@
unsigned char spitrans8(unsigned char byte){
unsigned int bit;
//This function came from the SPI Wikipedia article.
//Minor alterations.
unsigned int bit;
//This function came from the SPI Wikipedia article.
//Minor alterations.
-
+
for (bit = 0; bit < 8; bit++) {
/* write MOSI on trailing edge of previous clock */
if (byte & 0x80)
for (bit = 0; bit < 8; bit++) {
/* write MOSI on trailing edge of previous clock */
if (byte & 0x80)
@@
-59,7
+62,7
@@
unsigned char spitrans8(unsigned char byte){
byte |= READMISO;
CLRCLK;
}
byte |= READMISO;
CLRCLK;
}
-
+
return byte;
}
return byte;
}
@@
-67,12
+70,16
@@
unsigned char spitrans8(unsigned char byte){
void spihandle(unsigned char app,
unsigned char verb,
unsigned char len){
void spihandle(unsigned char app,
unsigned char verb,
unsigned char len){
+ unsigned char i;
switch(verb){
//PEEK and POKE might come later.
case READ:
case WRITE:
switch(verb){
//PEEK and POKE might come later.
case READ:
case WRITE:
- cmddata[0]=spitrans8(cmddata[0]);
- txdata(app,verb,1);
+ P5OUT&=~SS; //Drop !SS to begin transaction.
+ for(i=0;i<len;i++)
+ cmddata[i]=spitrans8(cmddata[i]);
+ P5OUT|=SS; //Raise !SS to end transaction.
+ txdata(app,verb,len);
break;
case SETUP:
spisetup();
break;
case SETUP:
spisetup();