WAT-910BD H/W MANUAL
SPI_READ_3W(0x3B, 1) ;
// ST CODE read
wait_ms(1) ;
// 1mS wait
}
if( READ_BUFF[0] == 0x55){
// 0x55 means EXEC.NORMALLY
return TRUE ;
}else{
return FALSE ;
}
}
//----------------------------------------------------------------------
// FUNCTION: SPI_READ_3W
//
// SPI WRITE READ_BUFF[0...(R_Byte-1)]
// In case of 3Wire, it need change GPIO(MISO/MOSI) direction
// input/output.
//----------------------------------------------------------------------
unsigned char SPI_READ_3W(unsigned char R_Adr, unsigned char R_Byte)
{
int
ReadCMD ;
// SPI READ COMMAND
int i ;
// counter
int j ;
unsigned char
SendBit ;
// make SPI READ COMMAND
ReadCMD = ((int)R_Adr << 1) + 1 ;
SEND_BUFF[0] = (unsigned char)ReadCMD ;
// lower 8bit
SEND_BUFF[1] = (unsigned char)(ReadCMD >> 8) ;
// higher 8bit
i = 0 ;
// Byte Counter
// initialize SPI bus
p3_5 = 1 ;
// SS = H
p3_4 = 1 ;
// SCLK = H
wait_nop() ;
// SPI READ COMMAND send start
pd3_3 = 1;
// set port direction MOSI(output)
p3_3 = 1 ;
// MOSI = H
p3_5 = 0 ;
// SS = L
wait_nop() ;
while( i < 2 ){
// 2 byte loop
j = 1 ;
// bit mask
while(j < 0xFF){
// 8bit send
SendBit = SEND_BUFF[i] & j ? 1 : 0 ;
// Bit Test
j = j << 1 ;
// j *= 2 ;
p3_4 = 0 ;
// SCLK = L
p3_3 = SendBit ;
// output LSB first bit data on MOSI
wait_nop() ;
p3_4 = 1 ;
// SCLK = H(latch)
}
- 56 -