本帖最后由 453044814@qq.com 于 2017-1-13 10:07 编辑
#define ErrorObjSize 7
#define FLASH_HISTORICAL_EVENT_START_ADDR 0X08050000
typedef struct{
uint8_t error_type;
uint8_t error_bus;
uint16_t error_term_id;
uint8_t error_term_type;
uint8_t light_type;
uint16_t error_year;
uint8_t error_month;
uint8_t error_day;
uint8_t error_hour;
uint8_t error_min;
uint8_t error_sec;
}_EVENT_LOG_LIST_obj;
uint16_t NewEventSavrFlashAddr=0;
/*****************************************************************************************************/
/*记录日志*/
void record_new_event(_EVENT_LOG_LIST_obj* data)
{
static uint16_t j=0;
uint16_t buffer[ErrorObjSize];
uint32_t addr32;
buffer[0] = (data->error_type)<<8 | (data->error_bus);
buffer[1] = data->error_term_id;
buffer[2] = (data->error_term_type)<<8 | (data->light_type);
buffer[3] = calendar.w_year;
buffer[4] = (calendar.w_month)<<8 | (calendar.w_date);
buffer[5] = (calendar.hour)<<8 | (calendar.min);
buffer[6] = (calendar.sec)<<8;
addr32 = FLASH_HISTORICAL_EVENT_START_ADDR + NewEventSavrFlashAddr*ErrorObjSize*2;
if(j==146)
{
delay_ms(20);
/*
addr = FLASH_HISTORICAL_EVENT_START_ADDR+2044 = 0x08507fc 要跨扇区了
写入buffer = {0xe801,0x0007,0x080a,0x07e1,0x010b,0x1311,0x2000}
读出buffer = {0xe801,0x0007,0xffff,0xffff,0xffff,0xffff,0xffff}
*/
}
STMFLASH_Write(addr32,buffer,ErrorObjSize);
j++;
delay_ms(50);
STMFLASH_Read(addr32,buffer,ErrorObjSize);
if(NewEventSavrFlashAddr<8000-1)
{
NewEventSavrFlashAddr++;
}
else
{
NewEventSavrFlashAddr = 0;
}
}
int main(void)
{
_EVENT_LOG_LIST_obj data;
data.error_bus = 1;
data.error_day = 2;
data.error_hour = 3;
data.error_min = 4;
data.error_month = 5;
data.error_sec = 6;
data.error_term_id = 7;
data.error_term_type = 8;
data.error_year = 9;
data.light_type = 10;
while(1)
{
record_new_event(&data);
delay_ms(50);
}
}
flash驱动来自精英版
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
#define ErrorObjSize 8
ok
#define FLASH_HISTORICAL_EVENT_START_ADDR 0X08050000
void record_new_event(_EVENT_LOG_LIST_obj* data)
{
static uint16_t j=0;
uint8_t i;
uint16_t buffer[ErrorObjSize];
uint32_t addr32;
buffer[0] = 7;
buffer[1] = 8;
buffer[2] = 9;
buffer[3] = 10;
buffer[4] = 11;
buffer[5] = 12;
buffer[6] = 13;
addr32 = FLASH_HISTORICAL_EVENT_START_ADDR + j*ErrorObjSize*2;
if(j==146)
{
delay_ms(20);
/*
addr = FLASH_HISTORICAL_EVENT_START_ADDR+2044 = 0x08507fc 要跨扇区了
写入buffer = {0x0007,0x0008,0x00009,0x0a,0x0b,0x0c,0x0d}
读出buffer = {0x0001,0x0007,0xffff,0xffff,0xffff,0xffff,0xffff}
*/
}
STMFLASH_Write(addr32,buffer,ErrorObjSize);
j++;
delay_ms(10);
STMFLASH_Read(addr32,buffer,ErrorObjSize);
}
int main(void)
{
_EVENT_LOG_LIST_obj data;
while(1)
{
record_new_event(&data);
}
}
if(j==146)
{
delay_ms(20);
/*
addr = FLASH_HISTORICAL_EVENT_START_ADDR+2044 = 0x08507fc 要跨扇区了
写入buffer = {0x0001,0x0007,0x080a,0,0,0,0}
读出buffer = {0x0001,0x0007,0x080a,0xffff,0,0,0}
*/
j++;
}
else
{
STMFLASH_Write(addr32,buffer,ErrorObjSize);
j++;
delay_ms(10);
STMFLASH_Read(addr32,buffer,ErrorObjSize);
}
跳过跨页的那一段,接下的都没有问题
不跳过,以后读出全是ffff
估计是奇数地址的问题
一周热门 更多>