现在正在用S3C2440的SPI和CC2420通信,我向寄存器中写数据,再想网出读,检测一下通信好不好用,可是总不读出我写的数据 下面是CC2420寄存器读写程序: unsigned char CC2420_SetReg( char reg, unsigned short data) { char H_byte,L_byte; H_byte=((data&0xFF00)>>8); L_byte=(data&0x00FF); CC2420_CS_ENABLE; /* Write the address to the SPI */ WRITE_SPI(reg); /* Write the data to the spi, stop if there was a SPI error */ WRITE_SPI(H_byte); WRITE_SPI(L_byte); CC2420_CS_DISABLE; return ( 0 ); }
unsigned char CC2420_ReadReg( char reg, char* data, unsigned char length ) { char pos = 0; CC2420_CS_ENABLE; /* Write the address to the SPI */ WRITE_SPI((reg & 0x3F) | 0x40); /*读数据*/ WRITE_SPI(0xff); RX[0]=Read_SPI(); WRITE_SPI(0xff); RX[1]=Read_SPI(); CC2420_CS_DISABLE; return ( 0 ); } 下面是S3C2440的SPI的程序: #include "def.h" #include "option.h" #include "2440addr.h" #include "2440lib.h" #include "cc2420.h" void spi_poll_done(void);
char RXdata[],TXdata[],test=0; extern char RX[4]; /************SPI的初始化程序************* GPG2-----nSS0 GPE11-----MISO GPE12----MOSI GPE13-----SPICLK GPG0-----VREG_EN GPG6------RSTn GPG10-----SFD GPG7------CCA GPG11----FIFO GPG5-----FIFO_P GPG1-----CSn *****************************************/ void Init_SPI(void) { int t; //初始化相关io端口设置 rGPECON=rGPECON&~(3<<22)&~(3<<24)&~(3<<26)|(2<<26)|(2<<24)|(2<<22);//SPI0 configued rGPGCON=rGPGCON&~(3<<10)&~(3<<14)&~(3<<22)&~(3<<20)&~(3<<0)&~(3<<12)&~(3<<2)|(1<<0)|(1<<12)|(1<<2); //nSS0 bit is input,GPG2->nSS0,直接接地 rGPGUP=(~(1<<1)); //disable GPG pull up function,只使能CSn的上拉 rGPEUP=0xffff; //disable GPE pull up function //初始化SPI设置 rSPPRE0=0x18; //PCLK=50M,SPICLK=50/2/(24+1)=1M //rCLKCON|=(1<<18); //使能SPI的时钟模块 rSPCON0=(1<<4)|(1<<3)|(0<<2)|(0<<1)|(0<<0);//enable ENSCK,master,CPOL=0,CPHA=0,normal mode rSPPIN0=(0<<2)|(1<<1)|(0<<0); //dis-ENMUL,SBO,release for(t=0;t<10;t++) rSPTDAT0=0xff; //初始化设备 } /************SPI发送一个字节**************/ void WRITE_SPI(unsigned char data) { spi_poll_done(); rSPTDAT0=data; spi_poll_done(); } /**************轮询SPI状态***************/ void spi_poll_done(void) { while(!(rSPSTA0&0x01)); //SPSTA0的READY是否置位 } /**************SPI接收数据***************/ char Read_SPI(void) { RXdata[0]=rSPRDAT0; return(RXdata[0]); }
弄了将近一个星期了,还是读不出来我写的数据,希望用过SPI河CC2420的朋友给点建议,或者给我S3C2440的SPI的例程也行,感激不尽 |