附件是源代码,请帮我分析一下simple_peripheral.c
Kevin Qiu1:
大概看了下,内容有点多,找起来比较费时间,你把IIC发送和接收部分以及在simple_peripheral.c中修改的部分传上来
user6329192:
回复 Kevin Qiu1:
另外,现象具体是:在上电一段时间后,模块可以正常输出传感器数据,但在一段时间后(具体时长在各个模块、每次上电后均不相同),手机端收到的传感器数据不再变化,仅能通过断电上电模块才能恢复正常,但一段时间后仍会出现相同现象。
主要修改如下:
1、SimplePeripheral_init() 中添加如下 Watchdog_init(); /* Configure the LED and button pins */ /* Open a Watchdog driver instance */ Watchdog_Params_init(¶ms); params.callbackFxn = (Watchdog_Callback) watchdogCallback; params.debugStallMode = Watchdog_DEBUG_STALL_ON; params.resetMode = Watchdog_RESET_ON; watchdogHandle = Watchdog_open(Board_WATCHDOG0, ¶ms); if (watchdogHandle == NULL) { /* Error opening Watchdog */ while (1) {} } reloadValue = Watchdog_convertMsToTicks(watchdogHandle, TIMEOUT_MS); /* * A value of zero (0) indicates the converted value exceeds 32 bits * OR that the API is not applicable for this specific device. */ if (reloadValue != 0) { Watchdog_setReload(watchdogHandle, reloadValue); } I2C_init(); uint32_t uiTempData; Power_setConstraint(PowerCC26XX_SB_DISALLOW); Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW); uiTempData = sensorRead();//函数内容在下面, Power_releaseConstraint(PowerCC26XX_IDLE_PD_DISALLOW); Power_releaseConstraint(PowerCC26XX_SB_DISALLOW); uint8_t charValue5[SIMPLEPROFILE_CHAR5_LEN] = {(0x04),(0x18)}; SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, charValue5);2、SimplePeripheral_taskFxn()的 if (events & SBP_PERIODIC_EVT)部分添加如下 uint32_t uiTempData; uint32_t uiTempData; AONBatMonEnable(); uint32_t sysRSTsrc; uint32_t powerRSTsrc; // <int.frac> format size <3.8> in units of volt //返回值32位中[10:8]代表INT 。[7:0]代表FRAC ,对于小数部分,一个单位代表0.00390625v,小数部分的分辨率只有50mV(TYP) uint32_t batval = AONBatMonBatteryVoltageGet(); uint8_t charValue2[10] = {0}; charValue2[0] = ((batval & 0x00000700)>>8); charValue2[1] = (batval & 0x000000FF); sysRSTsrc = SysCtrlResetSourceGet(); charValue2[2] = (sysRSTsrc & 0xFF000000)>>24; charValue2[3] = (sysRSTsrc & 0x00FF0000)>>16; charValue2[4] = (sysRSTsrc & 0x0000FF00)>>8; charValue2[5] = (sysRSTsrc & 0x000000FF); powerRSTsrc = PowerCtrlResetSourceGet(); charValue2[6] = (powerRSTsrc & 0xFF000000)>>24; charValue2[7] = (powerRSTsrc & 0x00FF0000)>>16; charValue2[8] = (powerRSTsrc & 0x0000FF00)>>8; charValue2[9] = (powerRSTsrc & 0x000000FF); SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR1, SIMPLEPROFILE_CHAR1_LEN, charValue2); Power_setConstraint(PowerCC26XX_SB_DISALLOW); Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW); uiTempData = sensorRead(); Power_releaseConstraint(PowerCC26XX_IDLE_PD_DISALLOW); Power_releaseConstraint(PowerCC26XX_SB_DISALLOW); advertData[3] = 0; advertData[4] = 0; advertData[5] = 0; advertData[3] = ((uiTempData & 0xFF0000) >> 16); advertData[4] = (uiTempData & 0xFF00) >> 8; advertData[5] = (uiTempData & 0x00FF); uint8_t charValue5[SIMPLEPROFILE_CHAR5_LEN] = {(advertData[4]+0x04),(advertData[5]+0x18)}; SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, charValue5); Util_startClock(&periodicClock); // Perform periodic application task SimplePeripheral_performPeriodicTask();/******************************************************************************* * @fn sensorTaskInit * * @brief Initialization function for the TMP117 temperature sensor * ******************************************************************************/static void sensorTaskInit(void){ I2C_Params i2cParams; /* Enable Device Pull Up resistors */ /* Create I2C for usage */ I2C_Params_init(&i2cParams); i2cParams.bitRate = I2C_100kHz; i2c = I2C_open(Board_I2C_TMP, &i2cParams); if (i2c == NULL) { while (1); }}/******************************************************************************* * @fn sensorRead * * @brief Reads the data from TMP117 and then starts the next one shot * conversion. * ******************************************************************************/static uint32_t sensorRead(void){ uint32_t temperature; uint8_t txBuffer[3]; uint8_t rxBuffer[7]; //uint8_t sensorStatus; I2C_Transaction i2cTransaction; sensorTaskInit(); Task_sleep(5000 / Clock_tickPeriod); /* Point to the T ambient register and read its 2 bytes */ txBuffer[0] = LWT_CMD_ReadTEMP1; txBuffer[1] = LWT_CMD_ReadTEMP2; txBuffer[2] = LWT_CMD_ReadTEMP3; i2cTransaction.slaveAddress = 0x00; i2cTransaction.writeBuf = txBuffer; i2cTransaction.writeCount = 3; i2cTransaction.readBuf = NULL; i2cTransaction.readCount = 0; //I2C_transfer(i2c, &i2cTransaction); if(I2C_transfer(i2c, &i2cTransaction)==true) Watchdog_clear(watchdogHandle); Task_sleep(12000 / Clock_tickPeriod); i2cTransaction.slaveAddress = 0x00; i2cTransaction.writeBuf = NULL; i2cTransaction.writeCount = 0; i2cTransaction.readBuf = rxBuffer; i2cTransaction.readCount = 7; if(I2C_transfer(i2c, &i2cTransaction)==true) Watchdog_clear(watchdogHandle); temperature = (rxBuffer[0] << 16)|(rxBuffer[4] << 8) | (rxBuffer[5]); I2C_close(i2c); return(temperature);}
Kevin Qiu1:
回复 user6329192:
user6329192 uiTempData = sensorRead(); Power_releaseConstraint(PowerCC26XX_IDLE_PD_DISALLOW); Power_releaseConstraint(PowerCC26XX_SB_DISALLOW); advertData[3] = 0; advertData[4] = 0; advertData[5] = 0; advertData[3] = ((uiTempData & 0xFF0000) >> 16); advertData[4] = (uiTempData & 0xFF00) >> 8; advertData[5] = (uiTempData & 0x00FF); uint8_t charValue5[SIMPLEPROFILE_CHAR5_LEN] = {(advertData[4]+0x04),(advertData[5]+0x18)}; SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, charValue5); Util_startClock(&periodicClock); // Perform periodic application task SimplePeripheral_performPeriodicTask();
应该是这部分的问题,后面事件每五秒钟(SBP_PERIODIC_EVT_PERIOD)执行一次
user6329192:
回复 Kevin Qiu1:
对,是每5秒读一次传感器数据,然后发送出去,传感器数据一直不变的情况是指某次数据刷新后,数据再也不变了,例如:当前时刻读到数据位0xAABB,此时刻之后手机读到的数据都是0xAABB。麻烦您了
user6329192:
回复 Kevin Qiu1:
我换一种说法,比如M3核在当前时刻触发RF发送0xAABB,之后M3死机或是处于其他无法触发RF发送新数据0xBBCC时,RF是否一直发送0xAABB?
Kevin Qiu1:
回复 user6329192:
if (events & SBP_PERIODIC_EVT)这个下面就是每5秒执行一次,读取温度的话可以创建一个新的任务