打印

那位做过at45db161d

[复制链接]
1353|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
chuandaoxy|  楼主 | 2009-5-26 23:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
下面的代码,是从c++的代码转化过来的

#include <reg51.h> 


#define    uint                     unsigned int
#define    uchar                    unsigned char



#define AT45DB161D_READ_MANUFACTURER_AND_DEVICE_ID 0x9F 


 struct ATD45DB161D_ID 

 { 
   uint     manufacturer;        
   uint     device[2];           
   uint     extendedInfoLength;  

  }; 


void ReadManufacturerAndDeviceID(struct ATD45DB161D_ID *id); 



/****************************************************/     

unsigned char SPI_HostReadByte(void)

{
    unsigned char i,rByte=0;

    for(i=0;i<8;i++){
        SPI_SCK=0;
        SPI_SCK=1;

        rByte<<=1;
        rByte|=SPI_SO;
    }
    return rByte;
}

/****************************************************/

void SPI_HostWriteByte(unsigned char wByte)

{
    unsigned char i;

    for(i=0;i<8;i++){
        if((wByte<<i)&0x80){SPI_SI=1;}
        else{SPI_SI=0;}

        SPI_SCK=0;
        SPI_SCK=1;
    }
}

/****************************************************/

 void ReadManufacturerAndDeviceID(struct  ATD45DB161D_ID *id)
 
 {
    
   SPI_CS=1;
       
   SPI_CS=0;
  
   SPI_HostWriteByte(0x9f);

   id->manufacturer = SPI_HostReadByte();

   SPI_HostWriteByte(0xff);

   id->device[0] = SPI_HostReadByte(); 

   SPI_HostWriteByte(0xff);

   id->device[1] = SPI_HostReadByte(); 

   SPI_HostWriteByte(0xff);

   id->extendedInfoLength = SPI_HostReadByte();
    
  } 

ReadManufacturerAndDeviceID(struct  ATD45DB161D_ID *id)这个函数只能读出厂家id;1f,而容量id,无法读出,错在那呢

结构体里定义的变量都是uint型,改称uchar才能读出厂家id;1f,这是为啥?

相关帖子

沙发
mxh0506| | 2009-5-27 14:53 | 只看该作者

改成下面这样:

void ReadManufacturerAndDeviceID(struct  ATD45DB161D_ID *id)

{
    
   SPI_CS=1;
       
   SPI_CS=0;
  
   SPI_HostWriteByte(0x9f);

   id->manufacturer = SPI_HostReadByte();

   id->device[0] = SPI_HostReadByte(); 

   id->device[1] = SPI_HostReadByte(); 

   id->extendedInfoLength = SPI_HostReadByte();
    
  } 

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

851

主题

1039

帖子

4

粉丝