微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > at45db161驱动

at45db161驱动

时间:11-29 来源:互联网 点击:
unsigned char AT45DBXX_STATUS(void)
{unsigned char temp;spi_cs(0);SPI_Send_Data(0Xd7);temp =  SPI_Send_Data(0Xff);spi_cs(1);return temp; //bit7 0=busy  bit6 1=Compare// bit1 1=PROTECT bit0 0=528byte 1=512byte}unsigned char AT45XX_ID(void){unsigned char temp;spi_cs(0);SPI_Send_Data(0X9F);temp=SPI_Send_Data(0xff);temp=SPI_Send_Data(0xff);spi_cs(1);return temp;}void ContinuousArrayLowRead(unsigned int page,unsigned int addrs,unsigned char *dat,unsigned int lenght){spi_cs(0);SPI_Send_Data(0X03);page<=1;if(addrs&0x100)page=page+1;SPI_Send_Data((page>>8));SPI_Send_Data(page);SPI_Send_Data(addrs);while(lenght){*dat = SPI_Send_Data(0Xff);dat++;lenght--;}spi_cs(1);}void Buffer1ToMainWithErase(unsigned int page){spi_cs(0);SPI_Send_Data(0X83);SPI_Send_Data((page>>7));SPI_Send_Data(page<1);SPI_Send_Data(0x00);spi_cs(1);}void AT45Buffer1Write(unsigned int addrs,unsigned char *dat,unsigned int lenght){spi_cs(0);SPI_Send_Data(0X84);SPI_Send_Data(0x00);SPI_Send_Data(addrs>>8);SPI_Send_Data(addrs);while(lenght){SPI_Send_Data(*dat);dat++;lenght--;}spi_cs(1);}void AT45Buffer1Read(unsigned int addrs,unsigned char *dat,unsigned int lenght){spi_cs(0);SPI_Send_Data(0Xd1);SPI_Send_Data(0x00);SPI_Send_Data(addrs>>8);SPI_Send_Data(addrs);while(lenght){*dat = SPI_Send_Data(0xff);dat++;lenght--;}spi_cs(1);}void MainToBuffer1AT45(unsigned int page){spi_cs(0);SPI_Send_Data(0X53);SPI_Send_Data((page>>7));SPI_Send_Data(page<1);SPI_Send_Data(0x00);spi_cs(1);}void Buffer2ToMainWithErase(unsigned int page){spi_cs(0);SPI_Send_Data(0X86);SPI_Send_Data((page>>7));SPI_Send_Data(page<1);SPI_Send_Data(0x00);spi_cs(1);}				   void AT45Buffer2Write(unsigned int addrs,unsigned char *dat,unsigned int lenght){spi_cs(0);SPI_Send_Data(0X87);SPI_Send_Data(0x00);SPI_Send_Data(addrs>>8);SPI_Send_Data(addrs);while(lenght){SPI_Send_Data(*dat);dat++;lenght--;}spi_cs(1);}void AT45Buffer2Read(unsigned int addrs,unsigned char *dat,unsigned int lenght){spi_cs(0);SPI_Send_Data(0Xd3);SPI_Send_Data(0x00);SPI_Send_Data(addrs>>8);SPI_Send_Data(addrs);while(lenght){*dat = SPI_Send_Data(0xff);dat++;lenght--;}spi_cs(1);}void MainToBuffer2AT45(unsigned int page){spi_cs(0);SPI_Send_Data(0X55);SPI_Send_Data((page>>7));SPI_Send_Data(page<1);SPI_Send_Data(0x00);spi_cs(1);}void ChipErase(void){spi_cs(0);SPI_Send_Data(0Xc7);SPI_Send_Data(0x94);SPI_Send_Data(0x80);SPI_Send_Data(0x9a);spi_cs(1);}void PowerOfPage256(void){spi_cs(0);SPI_Send_Data(0X3d);SPI_Send_Data(0x2a);SPI_Send_Data(0x80);SPI_Send_Data(0xa6);spi_cs(1);}void test_at45xx(void){unsigned char status,i;unsigned int n;unsigned char rx_dat[153];const unsigned char leab[10]={0x00,0x01,0x02,0x03,0x55,0xaa,0x88,0x99,0x88,0xaa};status = AT45XX_ID();SCI_Send_dat(status);//ChipErase();do{status = AT45DBXX_STATUS();SCI_Send_dat(status);}while((status&0x80)==0);ContinuousArrayLowRead(0,1, rx_dat,100);//0x03for(i=0;i<100;i++){SCI_Send_dat(rx_dat[i]);rx_dat[i]=0;}/*for(n=0;n<512;n++){AT45Buffer1Write(n,&n,1);//0x84  0x87status = AT45DBXX_STATUS();//SCI_Send_dat(status);while((status&0x80)==0);}AT45Buffer1Read(0x00,rx_dat,10);for(i=0;i<10;i++){SCI_Send_dat(rx_dat[i]);rx_dat[i]=0;}do{status = AT45DBXX_STATUS();SCI_Send_dat(status);}while((status&0x80)==0);Buffer1ToMainWithErase(0);do{status = AT45DBXX_STATUS();SCI_Send_dat(status);}while((status&0x80)==0);MainToBuffer1AT45(0);//0x53do{status = AT45DBXX_STATUS();SCI_Send_dat(status);}while((status&0x80)==0);AT45Buffer1Read(0x00,rx_dat,150);for(i=0;i<150;i++)SCI_Send_dat(rx_dat[i]);*/}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top