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

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

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

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

[求助] sst25vf080

[复制链接]
发表于 2010-10-20 09:43:51 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 hpdell 于 2010-10-20 09:48 编辑

请问有没有谁使用过SST25VF080的这个芯片啊????我现在在弄这个程序,只能读写状态寄存器的,不能够读写数据(单个字节或连续的读写都不行),请高人们指点!!!!!!!
我的程序如下:

sbit SPI_CS = P2^2;
sbit SPI_CK = P3^4;
sbit SPI_DI = P3^5;
sbit SPI_DO = P2^1;
sbit SPI_WP = P2^0;
sbit SPI_HOLD = P2^3;

unsigned char write_buff[]={0xed,0xcd,0xa4,0xc9,0xbe,0x8b,0x2c,0xa9,0xce,0x9a,0xed,0xcd,0xa4,0xc9,0xbe,0x8b,0x2c,0xa9,0xce,0x9a};
unsigned char read_buff[20]=0;
unsigned char read_dat_static=0;


#define SPI_WP_H SPI_WP=1   //写保护关闭
#define SPI_WP_L SPI_WP=0   //写保护开启
#define SPI_CS_H SPI_CS=1
#define SPI_CS_L SPI_CS=0
#define SPI_CK_H SPI_CK=1
#define SPI_CK_L SPI_CK=0
#define SPI_DI_H SPI_DI=1
#define SPI_DI_L SPI_DI=0
#define SPI_DO_H SPI_DO=1
#define SPI_DO_L SPI_DO=0
#define SPI_WP_H SPI_WP=1
#define SPI_WP_L SPI_WP=0
#define SPI_HOLD_H SPI_HOLD=1
#define SPI_HOLD_L SPI_HOLD=0
#define DELAY10US delay_us(30)    //延时10us


#define ReadStatusRegister        0x05       //读状态寄存器
#define Enable_Write_Status_Register 0x50   //写状态寄存器使能 or 0x06
#define WriteStatusRegister       0x01       //写状态寄存器
#define WriteEnable               0x06       //写使能,设置状态寄存器 or 0x50
#define WriteDisable              0x04       //写禁止
#define Read_Data                 0x03       //读取存储器数据
#define Page_Program              0x02       //页面编程--写数据
#define ChipErase                 0xC7       //片擦除
#define SectorErase_4K            0x20       //扇区擦除 ,4kb
#define BlockErase_32K            0x52       //块擦除,32kb
#define BlockErase_64K            0xD8       //块擦除,64kb
#define AAI_Word_Program     0xAD       //连续编程


void Spi_init();
void Spi_send_byte(unsigned char byte);
unsigned char Spi_get_byte();
unsigned char Spi_read_StatusRegister();
void Spi_wait_busy();
void Spi_write_StatusRegister(unsigned char byte);
void Spi_Write_Enable();
void Spi_Write_Disable();

unsigned char Spi_Read_Byte(unsigned long addr);
void Spi_Read_nByte(unsigned long addr,unsigned long nByte,unsigned char *p);
unsigned char Spi_FasttRead_Byte(unsigned long addr);
void spi_FastRead_nByte(unsigned long addr,unsigned char nByte,unsigned char *p);

void Spi_Write_Byte(unsigned long addr,unsigned char dat);
void Spi_Write_PageByte(unsigned long addr,unsigned char *dat,unsigned char nByte);
void Spi_Write_Buffrer(unsigned long addr,unsigned char *dat,unsigned int nByte);
void Spi_Erase_Chip();
void Spi_Erase_Sector_4k(unsigned long addr);
void Spi_Erase_Block_64k(unsigned long addr);
void Auto_Add_IncB(unsigned char byte);
void Auto_Add_IncA(unsigned long Dst, unsigned char byte);


void Spi_init()
{
SPI_CK_L;   /* set clock to low initial state for SPI operation mode 0 */
// SPI_CK_H;  /* set clock to low initial state for SPI operation mode 3 */
SPI_WP_L;
SPI_HOLD_H;
SPI_CS_H;

Spi_Write_Disable();
}

void Spi_send_byte(unsigned char byte)
{
uchar i=0;
for(i=0;i<8;i++)
{
  if((byte & 0x80) == 0x80) /* check if MSB is high */
   SPI_DI_H;
  else
   SPI_DI_L;
  SPI_CK_H;
  byte <<= 1;
  SPI_CK_L;
}
}
unsigned char Spi_get_byte()
{
uchar i=0,dat=0,temp=0;
for(i=0;i<8;i++)
{
  dat <<= 1;
  temp=SPI_DO;
  SPI_CK_H;
  if(temp==1)
   dat |= 0x01;
  SPI_CK_L;
}
return dat;
}

void Spi_Write_Enable()
{
SPI_CK_L;
SPI_CS_L;
Spi_send_byte(WriteEnable);  /* select write to status register */
SPI_CK_L;
SPI_CS_H;
}

void Spi_Write_Disable()
{
SPI_CK_L;
SPI_CS_L;
Spi_send_byte(WriteDisable);  // select write to status register
SPI_CK_L;
SPI_CS_H;  
}


unsigned char Spi_read_StatusRegister()
{
uchar StatusRegister=0;  
SPI_CS_L;
SPI_CK_L;
Spi_send_byte(ReadStatusRegister);
StatusRegister =  Spi_get_byte();
SPI_CK_L;
SPI_CS_H;   
return StatusRegister;
}

void Spi_write_StatusRegister(unsigned char byte)
{
SPI_CK_L;
Spi_Write_Enable();
delay_us(10);
SPI_CK_L;
SPI_CS_L;
SPI_CK_L;
delay_us(5);
Spi_send_byte(WriteStatusRegister);  /* select write to status register */
Spi_send_byte(byte);  /* data that will change the status(only bits 2,3,7 can be written) */
SPI_CK_L;
delay_us(5);
SPI_CS_H;
}

void Spi_wait_busy()
{
while(Spi_read_StatusRegister() == 0X03)
  Spi_read_StatusRegister();   /*  waste time until not busy WEL & Busy bit all be 1 (0x03). */
}
void Spi_wait_busy_AAI()
{
while(Spi_read_StatusRegister() == 0X43)
  Spi_read_StatusRegister();   /*  waste time until not busy WEL & Busy bit all be 1 (0x03). */
}


/*------------------------------------------------------
从芯片内读出一个字节的数据
addr是读取数据的地址
------------------------------------------------------*/
unsigned char Spi_Read_Byte(unsigned long addr)
{
unsigned char byte=0;
// SPI_CK_L;
// Spi_Write_Enable();   // set WEL
// delay_us(10);


SPI_CK_H;
SPI_CS_L;
delay_us(10);  
Spi_send_byte(Read_Data);  // read command
delay_us(10);
Spi_send_byte((unsigned char)((addr&0xFFFFFF)>>16));
delay_us(10);
Spi_send_byte((unsigned char)((addr&0xFFFF)>>8));
delay_us(10);
Spi_send_byte((unsigned char)(addr&0xFF));
// delay_us(10);
byte = Spi_get_byte();
delay_us(10);
SPI_CK_L;
SPI_CS_H;
delay_us(10);
return byte;   // return one byte read
}

/*------------------------------------------------------
写一个字节的数据
addr是写入数据的地址
dat 是写入的数据
------------------------------------------------------*/
void Spi_Write_Byte(unsigned long addr,unsigned char dat)
{
SPI_CK_L;
Spi_Write_Enable();   // set WEL
SPI_CK_L;
SPI_CS_L;
delay_us(10);
Spi_send_byte(Page_Program);  // send Byte Program command
delay_us(10);
Spi_send_byte((addr&0xFFFFFF)>>16);
delay_us(10);
Spi_send_byte((addr&0xFFFF)>>8);
delay_us(10);
Spi_send_byte(addr&0xFF);
delay_us(10);
Spi_send_byte(dat);
delay_us(10);
SPI_CK_L;
delay_us(10);
SPI_CS_H;
delay_us(10);
Spi_wait_busy();
SPI_CK_L;
delay_us(10);
Spi_Write_Disable();
}


void Spi_Erase_Chip()
{
Spi_Write_Enable();
SPI_CS_L;
SPI_CS_L;
Spi_send_byte(ChipErase);
SPI_CS_H;
Spi_wait_busy();
}

/*******************************************************************************
* Function Name  : Spi_Erase_Sector
* Description    : Erases the specified FLASH sector.
* Input          : addr: address of the sector to erase.(24位的bit地址)
* Output         : None
* Return         : None
扇区擦除 ,4kb
*******************************************************************************/
void Spi_Erase_Sector_4k(unsigned long addr)
{
SPI_CK_L;
Spi_Write_Enable();
SPI_CK_L;
SPI_CS_L;
SPI_CS_L;
Spi_send_byte(SectorErase_4K);
Spi_send_byte((unsigned char)((addr&0xFFFFFF)>>16));
Spi_send_byte((unsigned char)((addr&0xFFFF)>>8));
Spi_send_byte((unsigned char)(addr&0xFF));
SPI_CK_L;
SPI_CS_H;
Spi_wait_busy();
}
/*******************************************************************************
* Function Name  : Spi_Erase_Block
* Description    : Erases the entire FLASH.
* Input          : addr:Bulk的地址(24位的bit地址)
* Output         : None
* Return         : None
块擦除,64kb
*******************************************************************************/
void Spi_Erase_Block_64k(unsigned long addr)
{
SPI_CK_L;
Spi_Write_Enable();
SPI_CK_L;
SPI_CS_L;
SPI_CS_L;
Spi_send_byte(BlockErase_64K);
Spi_send_byte((addr & 0xff0000) >> 16);
Spi_send_byte((addr & 0xff00) >> 8);
Spi_send_byte(addr & 0xff);
SPI_CK_L;
SPI_CS_H;
Spi_wait_busy();
}

void Spi_Erase_Block_32k(unsigned long addr)
{
SPI_CK_L;
Spi_Write_Enable();
SPI_CK_L;
SPI_CS_L;
SPI_CS_L;
Spi_send_byte(BlockErase_32K);
Spi_send_byte((addr & 0xff0000) >> 16);
Spi_send_byte((addr & 0xff00) >> 8);
Spi_send_byte(addr & 0xff);
SPI_CK_L;
SPI_CS_H;
Spi_wait_busy();
}



void main()
{
unsigned char i=0;

delay_ms(1000);
Uart0_Init();   //串口初始化
Spi_init();    //SPI初始化

//----------------------------------
read_dat_static = Spi_read_StatusRegister();  //读寄存器状态测试OK
printexp("read_dat_static",read_dat_static,16);

Spi_write_StatusRegister(0x1C);   //写寄存器状态测试OK

read_dat_static = Spi_read_StatusRegister();
printexp("写寄存器状态测试OK",read_dat_static,16);
//---------------------------*/



Spi_Erase_Sector_4k(0);
Spi_Erase_Chip();

Spi_Write_Byte(0,0xec);    //写一个字节数据
read_dat_static = Spi_read_StatusRegister();  //此处读出的数据总是0XFF ???????????????
printexp("读出来的数据",read_dat_static,16);


for(;;)
{
  ;
}
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

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

GMT+8, 2024-5-10 02:15 , Processed in 0.033379 second(s), 9 queries , Gzip On, Redis On.

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