这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » SPI,AT45DB081 关于SPI口和AT45DB081连接的问题!

共2条 1/1 1 跳转至

SPI,AT45DB081 关于SPI口和AT45DB081连接的问题!

院士
2006-09-17 18:14:16     打赏
SPI,AT45DB081 关于SPI口和AT45DB081连接的问题!



关键词: AT45DB081     关于     口和     连接     问题    

院士
2006-12-22 22:43:00     打赏
2楼
问 #define SPIbaud 5000000    //5M
void Spi_iic(void)//初始化,对吗???
{
    uint32 a;
    SPI_SPCCR    =8;    //(Fpclk/SPIbaud)&0xfe;    //时钟计数 7.5M
    a    =SPI_SPSR;
    SPI_SPINT    =1;    //中断寄存器
    SPI_SPCR    =0x30;    //控制寄存器,main mode
}
uint8 Read_AT_status(void)读状态读不出???
{
    IOCLR = 1<<ATCS;        //片选AT45DB161
    while((SPIRW(0x57)&0x80)==0)DelayNS(1);    //    
    IOSET = 1<<ATCS;        //释放AT45DB161
    return 1;
}
指点一下。芯片确保是好的 1: 放一段程序吧。读写没优化过,但保证能用INT8U   AT45DBBuf[528];
static  OS_EVENT* AT45DBSem;

void AT45DBInit(void)
{
#if OS_CRITICAL_METHOD == 3
  OS_CPU_SR  cpu_sr;
#endif

  AT45DBSem = OSSemCreate(1);
  OS_ENTER_CRITICAL();
  PCONP   |= 0x00000100;
  PINSEL0 &= 0xFFFF00FF;
  PINSEL0 |= 0x00005500;
  IO0DIR  |= AT45DB_CS;
  IO0SET   = AT45DB_CS;
  OS_EXIT_CRITICAL();
}

void AT45DBRead(INT16U u16_page)
{
#if OS_CRITICAL_METHOD == 3
  OS_CPU_SR  cpu_sr;
#endif
  INT16U u16_cnt;
  INT8U  u8_err;

  OSSemPend(AT45DBSem,0,&u8_err);
  OS_ENTER_CRITICAL();
  S0PCR  = 0x38;
  S0PCCR = FPCLK/2000000*2;
  
  IO0CLR = AT45DB_CS;
  S0PDR  = 0x52;
  while(0 == (S0PSR&0x80));
  S0PDR = (INT8U)(u16_page>>6);
  while(0 == (S0PSR&0x80));
  S0PDR = ((INT8U)(u16_page))<<2;
  while(0 == (S0PSR&0x80));
  S0PDR = 0x00;
  while(0 == (S0PSR&0x80));
  
  S0PDR = 0x00;
  while(0 == (S0PSR&0x80));
  S0PDR = 0x00;
  while(0 == (S0PSR&0x80));
  S0PDR = 0x00;
  while(0 == (S0PSR&0x80));
  S0PDR = 0x00;
  while(0 == (S0PSR&0x80));
  
  for(u16_cnt=0;u16_cnt<528;u16_cnt++)
  {
    S0PDR = 0x00;
    while(0 == (S0PSR&0x80));
    AT45DBBuf[u16_cnt] = S0PDR;
  }
  IO0SET = AT45DB_CS;
  
  OS_EXIT_CRITICAL();
  OSSemPost(AT45DBSem);
}

void AT45DBWrite(INT16U u16_page)
{
#if OS_CRITICAL_METHOD == 3
  OS_CPU_SR  cpu_sr;
#endif
  INT16U u16_cnt;
  INT8U  u8_err;
  
  OSSemPend(AT45DBSem,0,&u8_err);
  OS_ENTER_CRITICAL();
  S0PCR  = 0x38;
  S0PCCR = FPCLK/2000000*2;
  IO0CLR = AT45DB_CS;
  
  S0PDR = 0x82;
  while(0 == (S0PSR&0x80));
  S0PDR = (INT8U)(u16_page>>6);
  while(0 == (S0PSR&0x80));
  S0PDR = ( (INT8U)(u16_page))<<2;
  while(0 == (S0PSR&0x80));
  S0PDR = 0x00;
  while(0 == (S0PSR&0x80));
    
  for(u16_cnt=0;u16_cnt<528;u16_cnt++)
  {
    S0PDR = AT45DBBuf[u16_cnt];
    while(0 == (S0PSR&0x80));
  }
  
  IO0SET = AT45DB_CS;
  OS_EXIT_CRITICAL();
  
  OSTimeDly(20);
  OSSemPost(AT45DBSem);   
} 2: 谢谢!我参考参考!

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]