我在LPC2214上使用该芯片,但出现了一些问题,现象描述如下:不论我向芯片的寄存器写入什么数据,读到的一直是0或者0xFF,从示波器的波形看,波形很工整,没发现有什么问题,以下是我的代码,请帮忙看看
void SPIInit( INT8U ch ) { if( ch == 0 ) { } else if( ch == 1 ) { // 设置 P0.17~20 为 SPI 功能 PINSEL1 = ( PINSEL0 & 0xFFFFFC03 ) | 0x00002A8;
// 设置片选(P1.18) PINSEL2 &= 0xFFFFFFF7; IO1DIR |= 1<<18; IO1SET = 1<<18; S1PCCR = 12; // 时钟分频 S1PCR = 0x20; // CPHA = 0 CPOL = 0 SPIWrite( 1, SC16IS752IPW_LCR, 0x80); SPIWrite( 1, SC16IS752IPW_DLL, 0x0C); SPIWrite( 1, SC16IS752IPW_DLH, 0x00); SPIWrite( 1, SC16IS752IPW_LCR, 0xBF); SPIWrite( 1, SC16IS752IPW_EFR, 0X10); SPIWrite( 1, SC16IS752IPW_LCR, 0x03); SPIWrite( 1, SC16IS752IPW_FCR, 0x06); SPIWrite( 1, SC16IS752IPW_FCR, 0x01); } }
INT8U SPISend( INT8U ch, INT8U data ) { INT8U ret; if( ch == 0 ) { } else if( ch == 1 ) { S1PDR = data ; while( (S1PSR & 0x80) == 0 ); ret = S1PDR ; } return ret; }
/* * 从SPI接口读入数据 */ INT8U SPIRead( INT8U ch, INT8U reg ) { INT8U ret; IO1CLR = 1<<18; SPISend( ch, reg ); ret = SPISend( ch, 0 ); IO1SET = 1<<18; return ret; }
/* * 写入数据至SPI接口 */ void SPIWrite(INT8U ch, INT8U reg, INT8U data ) { IO1CLR = 1<<18; SPISend( ch, reg ); SPISend( ch, data ); IO1SET = 1<<18; }
void TaskSPI( void *pdata ) { INT8U buf[10]; SPIInit( 1 ); for(;;) { buf[0] = UART4RegRead( SC16IS752IPW_LCR ); buf[1] = UART4RegRead( SC16IS752IPW_DLL ); buf[3] = UART4RegRead( SC16IS752IPW_DLH ); buf[4] = UART4RegRead( SC16IS752IPW_LSR ); buf[5] = UART4RegRead( SC16IS752IPW_IER ); buf[6] = UART4RegRead( SC16IS752IPW_IIR ); OSTimeDly( 10 ); } }
|