高中生
最后登录1970-1-1
在线时间 小时
注册时间2019-1-10
|
对SPI Flash W25Q64进行写操作时,改变发送的数据的字节数,读取到的id居然是变化的,比如字节数为10时id是0xef4017,是对的,把字节数改成255时,就变成了0xef40ff等等。在出现的几次错误中0xef和0x40都是对的,就是低8位总是变。请问各位大神这是怎么回事呢?
main()代码(其他函数与例程一致):
[mw_shl_code=c,true]#include "stm32f10x.h"
#include "bsp_led.h"
#include "bsp_key.h"
#include "bsp_usart.h"
#include "bsp_spi_flash.h"
#define DATA_SIZE 240
#define DATA_ADDR 0x01010a
int main(void)
{
uint32_t i = 0;
uint8_t flag = 0;
uint8_t data_write[DATA_SIZE];
uint8_t data_read[DATA_SIZE];
uint32_t flash_id_seq;
for(i = 0; i < DATA_SIZE; i++)
{
data_write = i & 0xff;
}
Key_GPIO_Config();
USART_Config();
FLASH_SPI_Config();
flash_id_seq = FLASH_SPI_ReadJEDECID();
printf("flash id: %#x\n", flash_id_seq);
if(flash_id_seq == FLASH_ID_SEQ)
{
printf("Flash is ready!\n\n");
}
while(1)
{
if(GPIO_ReadInputDataBit(KEY1_GPIO_PORT, KEY1_GPIO_PIN) == SET)
{
while(GPIO_ReadInputDataBit(KEY1_GPIO_PORT, KEY1_GPIO_PIN) == SET)
{
if(flag == 0)
{
#if 1
//read
printf("read data before erase:\n");
FLASH_SPI_ReadData(data_read, DATA_SIZE, DATA_ADDR);
for(i = 0; i < DATA_SIZE; i++)
{
printf("%#x\n", data_read);
}
FLASH_SPI_SectorErase(DATA_ADDR);
printf("read data after erase:\n");
FLASH_SPI_ReadData(data_read, DATA_SIZE, DATA_ADDR);
for(i = 0; i < DATA_SIZE; i++)
{
printf("%#x\n", data_read);
}
//write
printf("write data\n");
FLASH_SPI_PageProgram(data_write, DATA_SIZE, DATA_ADDR);
//FLASH_SPI_Program(data_write, DATA_SIZE, DATA_ADDR);
for(i = 0; i < DATA_SIZE; i++)
{
printf("%#x\n", data_write);
}
//read
printf("read data after write:\n");
FLASH_SPI_ReadData(data_read, DATA_SIZE, DATA_ADDR);
for(i = 0; i < DATA_SIZE; i++)
{
printf("%#x\n", data_read);
}
#endif
flag = 1;
}
}
}
flag = 0;
}
}
[/mw_shl_code]
|
|