void simulate_spi_write_byte(u8 data)
{
u8 kk;
SPI3_CS(0);
SPI3_SCK(0);
delay_us(1);
//???spi???1/2us=500KHZ ??
for(kk=0;kk<8;kk++)
{
//???????? ?????????
if((data&0x80)==0x80) SPI3_MOSI(1);
else SPI3_MOSI(0);
delay_us(1);
SPI3_SCK(1);
delay_us(1);
SPI3_SCK(0);
data = data<<1;//????????????
}
SPI3_CS(1);
}
u8 simulate_spi_read_byte(void)
{
u8 kk=0, ret=0;
SPI3_CS(0);
SPI3_SCK(0);
delay_us(1);
//???spi???1/2us=500KHZ ??
for(kk=0;kk<8;kk++)
{
ret = ret<<1; //???? ???? ?????????
SPI3_SCK(1);
delay_us(1);
if(SPI3_MISO) ret |= 0x01;
delay_us(1);
SPI3_SCK(0);
delay_us(1);
}
SPI3_CS(1);
return ret;
}
u8 simulate_spi_readwrite_byte(u8 data)
{
u8 kk=0, ret=0;
SPI3_CS(0);
SPI3_SCK(0);
delay_us(1);
//???spi???1/2us=500KHZ ??
for(kk=0;kk<8;kk++)
{
ret = ret<<1; //???? ???? ?????????
if((data&0x80)==0x80) SPI3_MOSI(1);
else SPI3_MOSI(0);
SPI3_SCK(1);
delay_us(1);
if(SPI3_MISO) ret |= 0x01;
delay_us(1);
SPI3_SCK(0);
delay_us(1);
data = data<<1;//????????????
}
SPI3_CS(1);
return ret;
}