在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
芯片精品文章合集(500篇!)    创芯人才网--重磅上线啦!
查看: 3846|回复: 8

[求助]关于AT45DB041B的问题,请大虾们帮个忙

[复制链接]
发表于 2007-5-9 08:56:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
我现有的条件如下:
一台PC机,一台示波器,一只电压表.一个JTAG下载器,一块目标实验板(M128+AT45DB041+8255+串口,还有一些其他的与本实验无关的器件)
问题如下:
1、给BUFFER1写入一串字符,然后再对BUFFER1进行读操作,不论我写入的是什么,读出的总是FF
2、用示波器观察SI,发现有数据,观察SO,始终为高电平,SCK是有的
3、我用的是模拟SPI接口(AT45DB041B是SPI接口的FLASH存储芯片)
4、如何借助现有的条件判断出是我的程序的问题还是芯片有问题?
5、附上工程文件,哪位大虾有空的话帮我看看,在下感激不尽
我加了免费代码,应该是免费的



at45db041b.rar (396.51 KB, 下载次数: 6 )



[ 本帖最后由 shinea8868 于 2007-5-9 09:01 编辑 ]
 楼主| 发表于 2007-5-9 09:07:55 | 显示全部楼层
下面是对AT45DB041的操作程序
#define F_CSSET   DDRB |= (1<<0); PORTB |= (1<<0)
#define F_CS   DDRB |= (1<<0); PORTB &=~(1<<0)
#define F_RSTSET  DDRB |= (1<<4); PORTB |= (1<<4)
#define F_RST   DDRB |= (1<<4); PORTB &=~(1<<4) //低电平复位
#define F_CHKBSY  DDRB &=~(1<<5)
#define F_BSYST   PINB & 0x20
/*读命令*/
/*SPI MODE 0  MODE 3*/
#define F_PGREAD  0xd2             //主存储器页读
#define F_CONRD   0xe8        //连续读
#define F_BUF1RD  0xD4        //读BUFFER1
#define F_BUF2RD  0xD6        //读BUFFER2
#define F_STREGRD 0xD7        //读状态积存器
/*写和擦除命令*/
#define F_BUF1WR             0x84     //写缓存1
#define F_BUF2WR       0x87     //写缓存2
#define BUF1TOMMEMPAGWITHERA 0x83     //缓存1到页带擦除
#define F_PAGERASE       0x81     //页擦除命令
#define F_BLKERASE       0x50     //块擦除命令
/*附加命令*/
#define MEMPAGTOBUF1   0x53       //Main Memory Page to Buffer 1 Transfer
#define MEMPAGTOBUF2   0x55       //Main Memory Page to Buffer 2 Transfer
#define SPISET  DDRB  |= (1<<1)|(1<<3); DDRB &=~(1<<2)
#define SCKSET PORTB |= (1<<1)
#define SCKCLR  PORTB &=~(1<<1)
#define SPISO PINB & 0x04
#define MOSISET PORTB |= (1<<3)
#define MOSICLR PORTB &=~(1<<3)
/******************************************************************************/
/*正常操作电压为2.7~3.6V,实验中发现当电压超过4.25V后读出的状态字节为9A(正常 */
/*的状态字节值为9D),并且读写数据均不准确,所以应当保证卡片的供电电压不超过  */
/*4.25V。                                                                     */
/*SPI规范:Data is always clocked into the device on the rising edge of SCK a-*/
/*    nd clocked out of the device on the falling edge of SCK.All instruction-*/
/*    s,addresses and data are transferred with the most significant bit(MSB) */
/*    first.                                                                  */
/*                                                                  2005-06-02*/
/******************************************************************************/

#define    UCHAR                      unsigned char
#define    UINT                       unsigned int
extern void WDTO(void);
//sbit       SPI_CS                   = P2^0;
//sbit       SPI_SCK                  = P2^2;
//sbit       SPI_SO                   = P2^3;
//sbit       SPI_SI                   = P2^4;
void dt(void)
{
  uchar i = 200;
while(i--);
}
unsigned char SPI_HostReadByte(void)
{
    unsigned char i,rByte=0;
   
    for(i=0;i<8;i++){
        SCKCLR;
//  dt();
        SCKSET;
//        dt();
        rByte<<=1;
  if(SPISO)
        {
     rByte |= 0x01;
  }
  else
   rByte &= 0xfe;
//  dt();
    }
    return rByte;   
}
void SPI_HostWriteByte(unsigned char wByte){
    unsigned char i;
   
    for(i=0;i<8;i++){
        if((wByte<<i)&0x80){MOSISET;}
        else{MOSICLR;}
//        dt();
        SCKCLR;
//  dt();
        SCKSET;
    }   
}
/******************************************************************************/
/*Status Register Format:                                                     */
/*   -----------------------------------------------------------------------  */
/*  |  bit7  |  bit6  |  bit5  |  bit4  |  bit3  |  bit2  |  bit1  |  bit0  | */
/*  |--------|--------|--------|--------|--------|--------|--------|--------| */
/*  |RDY/BUSY|  COMP  |   0    |   1    |   1    |   1    |   X    |   X    | */
/*   -----------------------------------------------------------------------  */
/*  bit7 - 忙标记,0为忙1为不忙。                                             */
/*         当Status Register的位0移出之后,接下来的时钟脉冲序列将使SPI器件继续*/
/*         将最新的状态字节送出。                                             */
/*  bit6 - 标记最近一次Main Memory Page和Buffer的比较结果,0相同,1不同。     */
/*  bit5                                                                      */
/*  bit4                                                                      */
/*  bit3                                                                      */
/*  bit2 - 这4位用来标记器件密度,对于AT45DB041B,这4位应该是0111,一共能标记 */
/*         16种不同密度的器件。                                               */
/*  bit1                                                                      */
/*  bit0 - 这2位暂时无效                                                      */
/******************************************************************************/
unsigned char AT45DB041B_StatusRegisterRead(void)
{
    unsigned char i;
               
    F_CS;   
    SPI_HostWriteByte(0xd7);
    i=SPI_HostReadByte();
    F_CSSET;
   
    return i;   
}
/******************************************************************************/
/*描述:                                                                      */
/*    When the last bit in the main memory array has been read,the device will*/
/*    continue reading back at the beginning of the first page of memory.As w-*/
/*    ith crossing over page boundaries,no delays will be incurred when wrapp-*/
/*    ing around from the end of the array to the beginning of the array.     */
/*参数:                                                                      */
/*    PA      - 页地址,0~2047                                                */
/*    BFA     - 指定BUFFER中的起始写入地址                                    */
/*    pHeader - 指定数据的首地址                                              */
/*    len     - 指定数据的长度                                                */
/******************************************************************************/
void AT45DB041B_ContinuousArrayRead(UINT PA,UINT BFA,uchar *pHeader,UINT len)
{      
    unsigned int i;      
   
    while(i++<255){if(AT45DB041B_StatusRegisterRead()&0x80){break;}}
    F_CS;   
    SPI_HostWriteByte(0xe8);   
    SPI_HostWriteByte((unsigned char)(PA>>7));   
    SPI_HostWriteByte((unsigned char)((PA<<1)|(BFA>>8)));
    SPI_HostWriteByte((unsigned char)BFA);
    for(i=0;i<4;i++){SPI_HostWriteByte(0x00);}
   
    for(i=0;i<len;i++){pHeader=SPI_HostReadByte();}
    F_CSSET;
}
/******************************************************************************/
/*描述:                                                                      */
/*    将指定数据写入从某个地址(0~263)开始的BUFFER中。                       */
/*参数:                                                                      */
/*    buffer  - 选择BUFFER,01H选择BUFFER 1,02H选择BUFFER 2                  */
/*              在该指令序列中,操作码84H选择BUFFER 1,87H选择BUFFER 2        */
/*    BFA     - BUFFER中的起始地址,0~263                                     */
/*    pHeader - 待存数据的头指针                                              */
/*    len     - 待存数据的长度1~264                                           */
/******************************************************************************/
void AT45DB041B_BufferWrite(UCHAR buffer,UINT BFA,UCHAR *pHeader,UINT len){
    unsigned int i;
   
    while(i++<255){if(AT45DB041B_StatusRegisterRead()&0x80){break;}}
    F_CS;   
    switch(buffer){
        case 1:SPI_HostWriteByte(0x84);break;
        case 2:SPI_HostWriteByte(0x87);break;
    }
    SPI_HostWriteByte(0x00);
    SPI_HostWriteByte((unsigned char)(BFA>>8));
    SPI_HostWriteByte((unsigned char)BFA);
   
    for(i=0;i<len;i++){SPI_HostWriteByte(pHeader);}
    F_CSSET;        
}
/******************************************************************************/
/*描述:                                                                      */
/*    将指定数据写入从某个地址(0~263)开始的页中:包含2个动作,首先将指定数据*/
/*    写入到BUFFER 1或者BUFFER 2中,其中可以指定BUFFER中的起始写入地址,此写入*/
/*    动作不影响BUFFER中其它地址中的数据,然后再将BUFFER中的整个数据写入到某指*/
/*    定页中(带预擦除)。                                                      */
/*参数:                                                                      */
/*    buffer  - 选择BUFFER,01H选择BUFFER 1,02H选择BUFFER 2                  */
/*    PA      - 页地址,0~2047                                                */
/*    BFA     - 指定BUFFER中的起始写入地址                                    */
/*    pHeader - 指定数据的首地址                                              */
/*    len     - 指定数据的长度                                                */
/******************************************************************************/
void AT45DB041B_BufferToMainMemoryPageProgramWithBuilt_inErase(UCHAR buffer,UINT PA,UINT BFA,UCHAR *pHeader,UINT len){
    unsigned int i;
    AT45DB041B_BufferWrite(buffer,BFA,pHeader,len);
    while(i++<1000){if(AT45DB041B_StatusRegisterRead()&0x80){break;}}
            
    F_CS;        
    switch(buffer){
        case 1:SPI_HostWriteByte(0x83);break;
        case 2:SPI_HostWriteByte(0x86);break;
    }
    SPI_HostWriteByte((unsigned char)(PA>>7));
    SPI_HostWriteByte((unsigned char)(PA<<1));
    SPI_HostWriteByte(0x00);
    F_CSSET;
}
/******************************************************************************/
/*描述:                                                                      */
/*    与上一个函数的唯一区别是不带预擦除。                                    */
/******************************************************************************/
void AT45DB041B_BufferToMainMemoryPageProgramWithoutBuilt_inErase(UCHAR buffer,UINT PA,UINT BFA,UCHAR *pHeader,UINT len){
    unsigned int i=0;
    AT45DB041B_BufferWrite(buffer,BFA,pHeader,len);
    while(i++<1000){if(AT45DB041B_StatusRegisterRead()&0x80){break;}}
   
    F_CS;
    SPI_HostWriteByte(0x88+buffer);
    SPI_HostWriteByte((unsigned char)(PA>>7));
    SPI_HostWriteByte((unsigned char)(PA<<1));
    SPI_HostWriteByte(0x00);
   
    for(i=0;i<len;i++){SPI_HostWriteByte(pHeader);}
    F_CSSET;
}

void buff1write(uint BFA,uchar data)
{
  F_CS;
F_RSTSET;
SPI_HostWriteByte(0x84);
SPI_HostWriteByte(0);
SPI_HostWriteByte((uchar)(BFA>>8));
SPI_HostWriteByte((uchar)(BFA));
SPI_HostWriteByte(data);
F_CSSET;
}
void buff1rd(uint BFA,uchar *data)
{
  F_CS;
F_RSTSET;
SPI_HostWriteByte(0xd4);
SPI_HostWriteByte(0);
SPI_HostWriteByte((uchar)(BFA>>8));
SPI_HostWriteByte((uchar)(BFA));
SPI_HostWriteByte(0);
*data = SPI_HostReadByte();
F_CSSET;
}
发表于 2007-5-9 11:37:17 | 显示全部楼层

注意一下复位和写保护

这芯片有复位和写保护引脚,
复位状态时忽略一切操作,
写保护时忽略保护页的写操作,
也许有这类问题
 楼主| 发表于 2007-5-10 10:31:20 | 显示全部楼层
写保护引脚我接了上拉电阻,始终为高电平,复位引脚也是为高电平,所以这两个问题应该不会有的,我有的时候感觉莫名其妙的,写的程序我没改什么东西,但是结果在不知道的情况下又对了,很是郁闷
发表于 2008-6-17 14:31:31 | 显示全部楼层
问题和我一样的!唉2!
发表于 2010-12-29 11:26:59 | 显示全部楼层
请问大虾有在吗???我出现的也是跟你帖子里一样的问题,想问一下你后来是怎么解决的,谢谢了
发表于 2015-5-20 11:08:02 | 显示全部楼层
感谢分享资料 !!! 谢谢。
发表于 2015-7-27 13:41:45 | 显示全部楼层
好东西感谢分享.
发表于 2015-11-14 16:14:20 | 显示全部楼层
AT45DB041B的问题
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-29 01:22 , Processed in 0.042771 second(s), 11 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表