Board logo

标题: ZIGBEE SPI口 [打印本页]

作者: yukai    时间: 2007-9-13 09:19     标题: ZIGBEE SPI口

为什么在MC13213通过SPI口读寄存器必须先写,写寄存器必须先读呢?

UINT16 SPIDrvRead(UINT8 u8Addr)
{
UINT8 u8TempValue=0;
UINT16 u16Data=0; /* u16Data[0] is MSB, u16Data[1] is LSB */

SPIClearRecieveStatReg(&u8TempValue); /* Clear status register (possible SPRF, SPTEF) */
SPIClearRecieveDataReg(&u8TempValue); /*
* Clear receive data register. SPI entirely
* ready for read or write
*/
MC13213DisableInterrupts(); /* Necessary to prevent double SPI access */
AssertCE(); /* Enables MC13213 SPI */
SPISendChar((u8Addr & 0x3f) | 0x80); /* Mask address, 6bit addr, Set
* read bit.
*/
SPIWaitTransferDone(); /* For this bit to be set, SPTED MUST be set */
SPIClearRecieveDataReg(&u8TempValue); /*
* Clear receive data register. SPI
* entirely ready for read or write
*/
SPISendChar(u8Addr ); /*
* Dummy write. Receive register of SPI
* will contain MSB
*/
SPIWaitTransferDone(); /*
* For this bit to be set, SPTED MUST be
* set. Get MSB
*/
SPIReadMSB(&u16Data); /* MSB */
SPISendChar(u8Addr); /*
* Dummy write. Waiting until after
* reading received data insures no
* overrun
*/
SPIWaitTransferDone(); /*
* For this bit to be set, SPTED MUST be
* set. Get LSB
*/
((UINT8*)&u16Data)[1] = SPIRead(); /* LSB */
DeAssertCE(); /* Disables MC13213 SPI */
MC13213RestoreInterrupts(); /* Restore MC13213 interrupt status */
return u16Data;
}

作者: seuafu2005    时间: 2007-9-17 10:27

读的话肯定要先写,要给出读的device的地址,另外,MCU对于收发器是master,它提供时钟信号的。 写的话就直接写了
作者: betterday    时间: 2008-8-1 09:08     标题: 凑热闹

是不是芯片的特性,采用什么“读-修改-写”的方式呢?在数据手册里看看




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0