使用STM32的SPI读取TDC7200的值,读出来的全是0
main.c文件中
uint8_t Q;
uint16_t W;
TDC7200_Init();
TDC7200_TIME1(&Q,&W);
OLED_Init();
OLED_ShowNum(16,16,Q,4,16,1);
OLED_ShowNum(0,32,W,4,16,1);
spi.c文件中
uint8_t MySPI_SwapByte(uint8_t ByteSend){
uint8_t i , ByteReceive = 0x00;
for(i = 0; i < 8; i++){
MySPI_W_MOSI(ByteReceive&(0x80>>i));
MySPI_W_SCK(1);
if(MySPI_R_MISO()==1){ByteReceive|=(0x80>>i);}
MySPI_W_SCK(0);
}
return ByteReceive;
}
void TDC7200_TIME1(uint8_t *q,uint16_t *w)
{
MySPI_Start();
MySPI_SwapByte(0x11);//读取时钟计数器值
*q = MySPI_SwapByte(0xFF);
*w = MySPI_SwapByte(0xFF);
*w <<= 8;
*w |= MySPI_SwapByte(0xFF);
MySPI_Stop();
}
电路图如下