你好啊!!我最近也在用这颗芯片做毕业设计~~板子也是自己画的,然后我自己写了SPI的程序后读写寄存器没有成功,因为读出来的数据一直是0。
我现在不知道是我的硬件有问题还是程序有问题,所以可不可以给你读写寄存器的程序我参考一些啊。。。。。或者我们可以讨论一下。万分感谢啊,,,,,
我再贴上我的程序,能帮我看看有什么问题么
//spi WRITE a byte.
void SPI_WRITE_BYTE(int data)
[
int i;
for(i=0;i<8;i++)[
if(data&0x80)SIMO->DATA=1;
else SIMO->DATA=0;
usleep(10); //set up time
SCLK->DATA=1;
data<<=1;
usleep(10); //hold time
SCLK->DATA=0;
]
]
//SPI read a byte
char SPI_READ_BYTE()
[
int i;
char data;
data=0;
for(i=0;i<8;i++)[
data<<=1;
SCLK->DATA=1;
usleep(10);
data |=SOMI->DATA;
// printf("the SOMI is %d n",SOMI->DATA);
SCLK->DATA=0;
usleep(10);
]
SIMO->DATA=0;
return(data);
]
//addr is a byte,but value is a 24-bit data
void SPI_WRITE_REG(int addr,int value)
[
int value1,value2;
STE->DATA=0;
usleep(1);
SPI_WRITE_BYTE(addr);
printf("The written addr is %d n",addr);
value1=value>>16;
printf("value1 is %d n",value1);
SPI_WRITE_BYTE(value1);
value2=value>>8;
printf("value2 is %d n",value2);
SPI_WRITE_BYTE(value2);
printf("value is %d n",value);
SPI_WRITE_BYTE(value);
usleep(1);
STE->DATA=1;
]
//READ THE REGISTER
int SPI_READ_REG(int addr)
[
int value=0;
STE->DATA=0;
usleep(1);
SPI_WRITE_BYTE(addr);
printf("the read addr is %d n",addr);
value |=SPI_READ_BYTE();
printf("the 1 read value is %d n",SPI_READ_BYTE());
value<<=8;
printf("the 2 read value is %d n",value);
value |=SPI_READ_BYTE();
printf("the 3 read value is %d n",SPI_READ_BYTE());
value<<=8;
printf("the 4 read value is %d n",value);
value |=SPI_READ_BYTE();
printf("the 5 read value is %d n",SPI_READ_BYTE());
usleep(1);
STE->DATA=1;
return(value);
]