本帖最后由 sunchaohu1987 于 2014-8-18 22:39 编辑
这几天写一个STM32F103VC与AT45DB642D芯片通信的程序,可是总是数据写不到存储芯片内,哪位高手帮我看下是怎么回事?谢谢了!
void SPI_Configuration(void)
{
SPI_InitTypeDef SPI_InitStructure;
SPI_Cmd(SPI1, DISABLE);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //设置SPI单向或者双向的数据模式:SPI设置为双线双向全双工
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //设置SPI工作模式:设置为主SPI
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //设置SPI的数据大小:SPI发送接收8位帧结构
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //选择了串行时钟的稳态:时钟 悬空低
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //数据捕获于第二个时钟沿
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //NSS信号由硬件(NSS管脚)还是 软件(使用SSI位)管理:内部NSS信号有SSI位控制
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; //定义波特 率预分频的值:波特率预分频值为256
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //指定数据传输从MSB位还是LSB位开始:数据传输从MSB位开始
SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC值计算的多项式
SPI_Init(SPI1, &SPI_InitStructure); //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器
SPI_Cmd(SPI1, ENABLE); //使能SPI外设
}
/***Dataflash_write2flash()*****连续写数据到SPI Flash内部**************/
Dataflash_write2flash(unsigned char* data, unsigned int page, unsigned int address, unsigned int size, FLASH_BUFFER_NUM buffer_num)
{
u16 i;
if(SPI_Data_Flash_Busy_Detect()==0) //==0 Data Flash空闲
{
SPI_Data_Flash_AT_SELECT(); //片选Dataflash
if(buffer_num == FLASH_BUFFER1)
SPI_ReadWrite_Byte(AT45DB_BUFFER_1_WRITE_FLASH );
else
SPI_ReadWrite_Byte(AT45DB_BUFFER_2_WRITE_FLASH);
SPI_ReadWrite_Byte(page>>5);
SPI_ReadWrite_Byte((page<<3)|(address>>8));
SPI_ReadWrite_Byte(address);
for (i=0; i<size; i++)
SPI_ReadWrite_Byte(data);
SPI_Data_Flash_AT_DESELECT();
}
}
|