共2条
1/1 1 跳转至页
SPI,AT45DB081 关于SPI口和AT45DB081连接的问题!
问
#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: 谢谢!我参考参考!
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 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 | |
【FRDM-MCXN947评测】核间通信MUTEX被打赏50分 |