接收函数有什么问题 我现在用lpc2368控制ad7716,初始化后在drdy管脚能看到波形,说明初始化可以了,但是接收就是不好使。 DWORD SSPInit(void) {
BYTE i, Dummy; PCONP |= (1 << 10); // PINSEL0=(1<<15)| // (1<<17)| // // (1<<19); // PINSEL0 = (0x02 << 12) | (0x02 << 14) | (0x02 << 16) | (0x02 << 18); //p0.7 sclk, P0.8 miso ,P0.9 mosi
PINSEL1 =0X0; //P0.17AS TFS P0.18AS RFS P0.19 AS RST
IODIR0 =rd_cs | wr_cs | rst;
IOSET0 = rd_cs | wr_cs;
/* Set DSS data to 8-bit, Frame format SPI, CPOL = 0, CPHA = 1, and SCR is 15 */ SSP1CR0 = 0x0F87;
/* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */ SSP1CPSR = 0x2;
// for ( i = 0; i < FIFOSIZE; i++ ) // { // Dummy = SSP1DR; /* clear the RxFIFO */ // } /* Device select as master, SSP Enabled, NO loopback operational mode */ SSP1CR1 |= SSPCR1_SSE;
return TRUE;
}
void SSP_SendData(BYTE data) { wr_cs_low(); while ( (SSP1SR & 0x02) == 0 ); // 等待发送FIFO留出空间 SSP1DR = data; while ((SSP1SR & 0x10) == 0x10); // 等待数据帧发送完毕 wr_cs_high(); return ; }
BYTE SSP1Receive( void ) { // DWORD i; BYTE buf; rd_cs_low(); // for ( i = 0; i < Length; i++ ) // { // SSP1DR = 0xAA; while ( !(SSP1SR & SSPSR_RNE) ); buf = SSP1DR; // buf++; // } rd_cs_high(); return buf; } |