OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3321|回复: 1

ucos3中,W25Q64上电初始化后读写成功,然后再在任务中执行读写就不行了

[复制链接]

1

主题

1

帖子

0

精华

新手入门

积分
19
金钱
19
注册时间
2019-3-7
在线时间
5 小时
发表于 2019-4-22 10:27:36 | 显示全部楼层 |阅读模式
1金钱
公司一个项目,因为没有采用eeprom,暂时使用剩余的外部flash空间做变量存储,已经用了一部分作为文件系统的

void LoadParams(void)
{
                uint8_t temp;
                __disable_irq();//禁止中断
//                OS_ENTER_CRITICAL();
//                OSSchedLock(&err);
//                STMFLASH_Read(ADDR_FLASH_SECTOR_21,red_buff,4);
          SPI_FLASH_BufferRead(red_buff,4096,51);
//                u32touint8(red_buff32,red_buff,16);
                memcpy(&PID_kp,&red_buff,2);
                memcpy(&PID_t,&red_buff[2],2);
                memcpy(&PID_td,&red_buff[4],2);
                memcpy(&PID_ti,&red_buff[6],2);
                memcpy(&Modbus_LocalAddr,&red_buff[8],1);
                memcpy(&Modbus_Bandrate,&red_buff[9],1);
                memcpy(&Modbus_Parity,&red_buff[10],1);
                memcpy(&Modbus_switch,&red_buff[11],1);
                memcpy(&Flow_Voltage_Ratio,&red_buff[12],4);
                memcpy(&Valve_Initial_Val,&red_buff[16],4);
                memcpy(&temp,&red_buff[20],2);
                Air_Flow_Set=temp*0.01;
                memcpy(&temp,&red_buff[22],2);
                High_Air_Alarm=temp*0.01;
                memcpy(&temp,&red_buff[24],2);
                Low_Air_Alarm=temp*0.01;
                memcpy(&temp,&red_buff[26],2);
                Low_Air_Alarm=temp*0.01;
                memcpy(&temp,&red_buff[28],2);
                Low_Air_Cutoff=temp*0.01;
                memcpy(&Cabinet_Width,&red_buff[30],1);
                memcpy(&temp,&red_buff[31],2);
                Unmanned_Air_PCT=temp*0.01;
                memcpy(&Low_Sash_Air_vol,&red_buff[33],1);
                memcpy(&Sash_High_Max,&red_buff[34],2);
                memcpy(&temp,&red_buff[36],2);
                Air_Leakage_C=temp*0.01;
                memcpy(&temp,&red_buff[38],2);
                Air_Sensitivity=temp*0.01;
                memcpy(&Sample_Num,&red_buff[40],1);
                memcpy(&temp,&red_buff[41],2);
                Air_Fluc_Range=temp*0.01;
                memcpy(&temp,&red_buff[43],2);
                Feedback_Fluc_Range=temp*0.01;
                memcpy(&Alarm_Delay,&red_buff[45],1);
                memcpy(&Sash_Control_Delay,&red_buff[46],1);
                memcpy(&FxOut_Percent_Exp_H,&red_buff[47],1);
                memcpy(&FxOut_Percent_Exp_L,&red_buff[48],1);
                memcpy(&state_switch_flag,&red_buff[49],1);
                memcpy(&Set_password,&red_buff[50],2);
//                OS_EXIT_CRITICAL();
//                OSSchedUnlock(&err);        //开启ucos调度           
                __enable_irq();//恢复中断
}

void SaveParams(void)
{
        uint8_t temp;
        uint8_t j;
        uint8_t s;
        memcpy(&Write_buff,(uint8_t*)&PID_kp,2);
        memcpy(&Write_buff[2],(uint8_t*)&PID_t,2);
        memcpy(&Write_buff[4],(uint8_t*)&PID_td,2);
        memcpy(&Write_buff[6],(uint8_t*)&PID_ti,2);
        memcpy(&Write_buff[8],(uint8_t*)&Modbus_LocalAddr,1);
        memcpy(&Write_buff[9],(uint8_t*)&Modbus_Bandrate,1);
        memcpy(&Write_buff[10],(uint8_t*)&Modbus_Parity,1);
        memcpy(&Write_buff[11],(uint8_t*)&Modbus_switch,1);
        memcpy(&Write_buff[12],(uint8_t*)&Flow_Voltage_Ratio,4);
        memcpy(&Write_buff[16],(uint8_t*)&Valve_Initial_Val,4);
        temp=Air_Flow_Set*100;
        memcpy(&Write_buff[20],(uint8_t*)&temp,2);
        temp=High_Air_Alarm*100;
        memcpy(&Write_buff[22],(uint8_t*)&temp,2);
        temp=Low_Air_Alarm*100;
        memcpy(&Write_buff[24],(uint8_t*)&temp,2);
        temp=Low_Air_Alarm*100;
        memcpy(&Write_buff[26],(uint8_t*)&temp,2);
        temp=Low_Air_Cutoff*100;
        memcpy(&Write_buff[28],(uint8_t*)&temp,2);
        memcpy(&Write_buff[30],(uint8_t*)&Cabinet_Width,1);
        temp=Unmanned_Air_PCT*100;
        memcpy(&Write_buff[31],(uint8_t*)&temp,2);
        memcpy(&Write_buff[33],(uint8_t*)&Low_Sash_Air_vol,1);
        memcpy(&Write_buff[34],(uint8_t*)&Sash_High_Max,2);
        temp=Air_Leakage_C*100;
        memcpy(&Write_buff[36],(uint8_t*)&temp,2);
        temp=Air_Sensitivity*100;
        memcpy(&Write_buff[38],(uint8_t*)&temp,2);
        memcpy(&Write_buff[40],(uint8_t*)&Sample_Num,1);
        temp=Air_Fluc_Range*100;
        memcpy(&Write_buff[41],(uint8_t*)&temp,2);
        temp=Feedback_Fluc_Range*100;
        memcpy(&Write_buff[43],(uint8_t*)&temp,2);
        memcpy(&Write_buff[45],(uint8_t*)&Alarm_Delay,1);
        memcpy(&Write_buff[46],(uint8_t*)&Sash_Control_Delay,1);
        memcpy(&Write_buff[47],(uint8_t*)&FxOut_Percent_Exp_H,1);
        memcpy(&Write_buff[48],(uint8_t*)&FxOut_Percent_Exp_L,1);
        memcpy(&Write_buff[49],(uint8_t*)&state_switch_flag,1);
        memcpy(&Write_buff[50],(uint8_t*)&Set_password,2);
//        u8touint32(Write_buff,Write_buff32,64);
        __disable_irq();//禁止中断,防止读写过程中意外中断导致出错
//        OSSchedLock(&err);
//        OS_ENTER_CRITICAL();
        SPI_FLASH_SectorErase(4096);
        SPI_FLASH_BufferWrite(Write_buff,4096,51);
//        STMFLASH_Write(ADDR_FLASH_SECTOR_21,Write_buff,4);
//        OS_EXIT_CRITICAL();
//        OSSchedUnlock(&err);        //开启ucos调度           
        __enable_irq();//恢复中断
//                       
}

static  void  AppTaskflash ( void * p_arg )
{
    OS_ERR      err;
   (void)p_arg;
    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.       */
                        if(Set_Modify)
                        {
                                        OSSchedLock(&err);
                                        SaveParams();//存储数据  这里写入不成功
                                        Set_Modify=0;
                                  LoadParams();  读出来都是0x00
                                        OSSchedUnlock(&err);        //开启ucos调度           
                        }
                        OSTimeDlyHMSM(0,0,0,150,OS_OPT_TIME_HMSM_STRICT,&err); //延时500ms
    }
               
               
}


/********初始化部分代码*//////////
//        ST7701SELECT();   //选择片选
        ST7701NSELECT();
        sSPI_Init();//模拟SPI初始化,硬件SPI公用   //在触摸前初始化
        ST7701_PanelInitialCode();
        Key_Init();//key
        /* 初始化LED */
        Led_GPIO_Config();
        Led_SPI_init();
        RGB_Rest();//默认状态
//        /* 初始化系统滴答定时器 */
        SysTick_Init();
        SPI_FLASH_Init();      //FLASH  部分版没焊接
//        STMFLASH_Unlock();       
//        W25QXX_Write_SR(0x00);
//        sFLASH_ReadBuffer(temp,2*4096,1);
//        while(temp[0]!=0xff)
//        {
//                temp3[0]=0xff;
//                sFLASH_EraseSector(2*4096);
//                sFLASH_WriteBuffer(temp3, 2*4096, 1);
                Data_reset();//这是数据初始值写入flash  里面调用的也是SaveParams();
//                sFLASH_ReadBuffer(temp,2*4096,1);
//        }
        LoadParams();   //这里出来时正确的
//        SAI_Star();//启动没关闭       添加关闭功能  添加读取文件系统任务   //去掉:2019年2月22日  展厅使用   后期版本添加蜂鸣器
       
        DMA_Cmd(AUDIO_MAL_DMA_STREAM, DISABLE);//关闭音频

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165536
金钱
165536
注册时间
2010-12-1
在线时间
2117 小时
发表于 2019-4-23 02:10:20 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-10 17:37

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表