SX1212API代码详解:
SX1212的MCU驱动程序51黑电子论坛整理(可移植):
- #include "SX1231.h"
- // ======== static fucntion ======== //
- static void InitMCU (void);
- /*====================================================
- main
- =====================================================*/
- void main (void) {
- unsigned char rc;
- InitMCU();
- InitSX1212();
- #if 1 // to test SPI
- SpiWriteCfg(REG_SYNCBYTE4, 0x55);
- if(SpiReadCfg(REG_SYNCBYTE4) != 0x55) {
- while(1); // something wrong with SPI
- }
- SpiWriteCfg(REG_SYNCBYTE4, 0xAA);
- if(SpiReadCfg(REG_SYNCBYTE4) != 0xAA) {
- while(1); // something wrong with SPI
- }
- SpiWriteCfg(REG_SYNCBYTE4, SYNC_WORD4);
- if(SpiReadCfg(REG_SYNCBYTE4) != SYNC_WORD4) {
- while(1); // something wrong with SPI
- }
- #endif
- //.....
- BuildPacket(0x12);
- SendRfFrame((unsigned char *)(&RF_Pkt), sizeof(RF_Pkt));
- while(1) {
- ReceiveRfFrame((unsigned char *)(&RF_Pkt), sizeof(RF_Pkt), &rc);
- if(rc == OK) {
- //got packet
- // ...
- }
- //...
- }
- }
- /*=====================================================
- InitMCU
- =====================================================*/
- static void InitMCU (void) {
- // ....
- /*
- Initiate MCU here
- including clock, IO, .....
- */
- }
复制代码
下载:
Driver.zip
(349.66 KB, 下载次数: 85)
|