我用LPC2138的SPI控制TRF7960,能写TRF7960的寄存器(通过写寄存器,SYS_CLK输出不同的频率可以验证),但读寄存器总是读不出来,读出来都是0,看SPISO的波形也总是低.TRF7960在读寄存器的时候需要切换CLK的极性.不知道哪位调试过这个,还请指教哪出了问题.下面是读寄存器的代码.
void
SpiReadSingle(u08_t *pbuf, u08_t number)
{
//uint16 i;
SLAVE_SELECT_LOW; // Start SPI Mode
while(number > 0)
{
*pbuf = (0x40 | *pbuf); // address, read, single
*pbuf = (0x5f & *pbuf); // register address
SPI_SPDR =*pbuf;
while(!(SPI_SPSR &0x80));
SPI_SPCR = 0x30;//CPOL = 1, CPHA = 0
SPI_SPDR =0;
while(!(SPI_SPSR &0x80));
*pbuf = SPI_SPDR;
pbuf++;
number--;
SPI_SPCR = 0x20;//CPOL = 0, CPHA = 0
}
SLAVE_SELECT_HIGH;
} |