For Arduino we don't want to re-configure the SPI each time as we assume it's configured elsewhere. We also only want to touch the chip select pin unlike the original driver code.

git-svn-id: svn+ssh://oldsvn/home/mlalondesvn/svn/cral@43 3ee9b42a-b53c-0410-a25e-f0b6218d5d5b
master
follower 17 years ago
parent 0059c0212a
commit 4ac7c1b66e

@ -81,6 +81,7 @@ uint8 IINCHIP_WRITE(uint16 addr,uint8 data)
#elif (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_SPI_MODE__)
//SPI MODE I/F
IINCHIP_ISR_DISABLE();
#ifndef __ARDUINO__
DDRB = 0x07; // MISO=input, etc.=output
// PB3(MISO), PB2(MOSI), PB1(SCK), PB0(/SS)
PORTB = 0x01; // CS=1, waiting for SPI start
@ -88,6 +89,9 @@ uint8 IINCHIP_WRITE(uint16 addr,uint8 data)
SPSR = 0x01; // SPI2X=0
PORTB = 0x00; // CS=0, SPI start
#else
PORTB = PORTB & ~CS_PIN; // CS=0, SPI start
#endif // ifndef __ARDUINO__
SPDR = 0xF0;
while((SPSR&0x80)==0x00);
SPDR = (uint8)((addr & 0xFF00) >> 8);
@ -96,8 +100,12 @@ uint8 IINCHIP_WRITE(uint16 addr,uint8 data)
while((SPSR&0x80)==0x00);
SPDR = data;
while((SPSR&0x80)==0x00);
#ifndef __ARDUINO__
PORTB = 0x01; // SPI end
// CS=1, waiting for SPI start
#else
PORTB = PORTB | CS_PIN; // SPI end
#endif // ifndef __ARDUINO__
IINCHIP_ISR_ENABLE();
#else
#error "unknown bus type"
@ -129,6 +137,7 @@ uint8 IINCHIP_READ(uint16 addr)
#elif (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_SPI_MODE__)
//SPI MODE I/F
IINCHIP_ISR_DISABLE();
#ifndef __ARDUINO__
DDRB = 0x07; // MISO=input, etc.=output
// PB3(MISO), PB2(MOSI), PB1(SCK), PB0(/SS)
PORTB = 0x01; // CS=1, waiting for SPI start
@ -136,6 +145,9 @@ uint8 IINCHIP_READ(uint16 addr)
SPSR = 0x01; // SPI2X=0
PORTB = 0x00; // CS=0, SPI start
#else
PORTB = PORTB & ~CS_PIN; // CS=0, SPI start
#endif // ifndef __ARDUINO__
SPDR = 0x0F;
while((SPSR&0x80)==0x00);
SPDR = (uint8)((addr & 0xFF00) >> 8);
@ -145,8 +157,12 @@ uint8 IINCHIP_READ(uint16 addr)
SPDR = 0x00; // write dummy data
while((SPSR&0x80)==0x00);
data = SPDR; // read data
#ifndef __ARDUINO__
PORTB = 0x01; // SPI end
// CS=1, waiting for SPI start
#else
PORTB = PORTB | CS_PIN; // SPI end
#endif // ifndef __ARDUINO__
IINCHIP_ISR_ENABLE();
#else
#error "unknown bus type"
@ -178,6 +194,7 @@ uint16 wiz_write_buf(uint16 addr,uint8* buf,uint16 len)
for(ii=0;ii<len;ii++)
{
#ifndef __ARDUINO__
DDRB = 0x07; // MISO=input, etc.=output
// PB3(MISO), PB2(MOSI), PB1(SCK), PB0(/SS)
PORTB = 0x01; // CS=1, waiting for SPI start
@ -185,6 +202,9 @@ uint16 wiz_write_buf(uint16 addr,uint8* buf,uint16 len)
SPSR = 0x01; // SPI2X=0
PORTB = 0x00; // CS=0, SPI start
#else
PORTB = PORTB & ~CS_PIN; // CS=0, SPI start
#endif // ifndef __ARDUINO__
SPDR = 0xF0;
while((SPSR&0x80)==0x00);
SPDR = (uint8)(((addr+ii) & 0xFF00) >> 8);
@ -193,8 +213,12 @@ uint16 wiz_write_buf(uint16 addr,uint8* buf,uint16 len)
while((SPSR&0x80)==0x00);
SPDR = buf[ii];
while((SPSR&0x80)==0x00);
#ifndef __ARDUINO__
PORTB = 0x01; // SPI end
// CS=1, waiting for SPI start
#else
PORTB = PORTB | CS_PIN; // SPI end
#endif // ifndef __ARDUINO__
}
IINCHIP_ISR_ENABLE();
#else
@ -226,6 +250,7 @@ uint16 wiz_read_buf(uint16 addr, uint8* buf,uint16 len)
uint16 iii=0;
for (iii=0; iii<len; iii++)
{
#ifndef __ARDUINO__
DDRB = 0x07; // MISO=input, etc.=output
// PB3(MISO), PB2(MOSI), PB1(SCK), PB0(/SS)
PORTB = 0x01; // CS=1, waiting for SPI start
@ -233,6 +258,9 @@ uint16 wiz_read_buf(uint16 addr, uint8* buf,uint16 len)
SPSR = 0x01; // SPI2X=0
PORTB = 0x00; // CS=0, SPI start
#else
PORTB = PORTB & ~CS_PIN; // CS=0, SPI start
#endif // ifndef __ARDUINO__
SPDR = 0x0F;
while((SPSR&0x80)==0x00);
SPDR = (uint8)(((addr+iii) & 0xFF00) >> 8);
@ -245,8 +273,12 @@ uint16 wiz_read_buf(uint16 addr, uint8* buf,uint16 len)
while((SPSR&0x80)==0x00);
buf[iii]=SPDR; // read data
//}
#ifndef __ARDUINO__
PORTB = 0x01; // SPI end
// CS=1, waiting for SPI start
#else
PORTB = PORTB | CS_PIN; // SPI end
#endif // ifndef __ARDUINO__
}
IINCHIP_ISR_ENABLE();
#else

Loading…
Cancel
Save