共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网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【笔记】生成报错synthdesignERROR被打赏50分 | |
【STM32H7S78-DK评测】LTDC+DMA2D驱动RGBLCD屏幕被打赏50分 | |
【STM32H7S78-DK评测】Coremark基准测试被打赏50分 | |
【STM32H7S78-DK评测】浮点数计算性能测试被打赏50分 | |
【STM32H7S78-DK评测】Execute in place(XIP)模式学习笔记被打赏50分 | |
每周了解几个硬件知识+buckboost电路(五)被打赏10分 | |
【换取逻辑分析仪】RA8 PMU 模块功能寄存器功能说明被打赏20分 | |
野火启明6M5适配SPI被打赏20分 | |
NUCLEO-U083RC学习历程2-串口输出测试被打赏20分 | |
【笔记】STM32CUBEIDE的Noruletomaketarget编译问题被打赏50分 |