项目中用了CC2640协议栈2.1,在SENSORTAG的例程上进行修改的,现在需要在掉电的情况上,存储30个字节的信息,在下次上电后取出使用,这个要如何做到?用SNV能够实现吗?
Susan Yang:
//NV_ID有一定范围// Customer NV Items - Range 0x80 - 0x8F - This must match the number of Bonding entries #define BLE_NVID_CUST_START 0x80 //!< Start of the Customer's NV IDs #define BLE_NVID_CUST_END 0x8F //!< End of the Customer's NV IDs0x80~0x8F都可以用(包含0x80、0x8F),每个ID号最多一次可写入252字节。实际可以写几个ID取决于所剩余SNV空间,并不是说可以把所有ID号都写满252字节。
您可以参考以下代码试试
#define BUF_LEN 1 #define SNV_ID_APP 0x80 uint8 buf[BUF_LEN] = {0,}; // Initialize application simple_peripheral_init(); uint8 status = SUCCESS; //Read from SNV flash status = osal_snv_read(SNV_ID_APP, BUF_LEN, (uint8 *)buf); if(status != SUCCESS) { DISPLAY_WRITE_STRING_VALUE("SNV READ FAIL: %d", status, LCD_PAGE5); //Write first time to initialize SNV ID osal_snv_write(SNV_ID_APP, BUF_LEN, (uint8 *)buf); } //Increment value and write to SNV flash buf[0]++; status = osal_snv_write(SNV_ID_APP, BUF_LEN, (uint8 *)buf);
peak huang:
回复 Susan Yang:
你好,调用status = osal_snv_write(SNV_ID_APP, BUF_LEN, (uint8 *)buf); 返回值是0x02,也就是INVALIDPARAMETER,这个要怎么解决啊?
Viki Shi:
回复 peak huang:
你 NV_ID定义的是多少,有没有按照文档要求?请参考Software Developer's Guide中SNV一节