STM32 SPI FLASH 读写问题 20
用人家的代码修改的后读写好像不行,但这段代码确实是可以读写FLASH的,这是我的修改版本:voidflash_write(void*address,void*data,l...
用人家的代码修改的后读写好像不行,但这段代码确实是可以读写FLASH 的,这是我的修改版本:
void flash_write(void* address,void* data,long length) {
char print_string[20];
u16 write_index=0;
spi_flash_write_enable();
select_spi();
flash_command(W25X_PAGE_PROGRAM);
flash_command((u8)(long)address>>16);
flash_command((u8)(long)address>>8);
flash_command((u8)(long)address);
for(;write_index<length;++write_index) {
flash_command(*(char*)((long)data+write_index));
sprintf(print_string,"%c",*(char*)((long)data+write_index));
lcd_print(print_string);
}
unselect_spi();
while (spi_flash_is_busy());
}
void flash_read(void* address,void* data,long length) {
char print_string[20];
u16 read_index=0;
sprintf(print_string,"addr=%ld",(long)address);
lcd_print(print_string);
select_spi();
flash_command(W25X_READ_DATA);
flash_command((u8)(long)address>>16);
flash_command((u8)(long)address>>8);
flash_command((u8)(long)address);
for(;read_index<length;++read_index) {
*(char*)((long)data+read_index)=flash_command(0xFF);
sprintf(print_string,"%c",*(char*)((long)data+read_index));
lcd_print(print_string);
}
unselect_spi();
}
就算是数据被正确写入,但修改版的代码一直读不出数据(原来的代码是可以的).不知道哪儿出错了.. 展开
void flash_write(void* address,void* data,long length) {
char print_string[20];
u16 write_index=0;
spi_flash_write_enable();
select_spi();
flash_command(W25X_PAGE_PROGRAM);
flash_command((u8)(long)address>>16);
flash_command((u8)(long)address>>8);
flash_command((u8)(long)address);
for(;write_index<length;++write_index) {
flash_command(*(char*)((long)data+write_index));
sprintf(print_string,"%c",*(char*)((long)data+write_index));
lcd_print(print_string);
}
unselect_spi();
while (spi_flash_is_busy());
}
void flash_read(void* address,void* data,long length) {
char print_string[20];
u16 read_index=0;
sprintf(print_string,"addr=%ld",(long)address);
lcd_print(print_string);
select_spi();
flash_command(W25X_READ_DATA);
flash_command((u8)(long)address>>16);
flash_command((u8)(long)address>>8);
flash_command((u8)(long)address);
for(;read_index<length;++read_index) {
*(char*)((long)data+read_index)=flash_command(0xFF);
sprintf(print_string,"%c",*(char*)((long)data+read_index));
lcd_print(print_string);
}
unselect_spi();
}
就算是数据被正确写入,但修改版的代码一直读不出数据(原来的代码是可以的).不知道哪儿出错了.. 展开
2个回答
展开全部
传送的参数为什么要用void型啊?address用uint32_t不行么?data用uint8_t不行么?
还有,在写入或读出数据的时候别干多余的事情,把sprintf和lcd_print删掉。
还有,在写入或读出数据的时候别干多余的事情,把sprintf和lcd_print删掉。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
www.openedv.com里面有,你找找
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询