int Mpu9250AuxRead(uint8_t DevAddr, uint8_t *pCmdAddr, int CmdAddrLen, uint8_t *pBuff, int BuffLen) { int retval = 0; uint8_t regaddr; uint8_t d[8]; d[0] = MPU9250_AG_I2C_SLV0_ADDR; d[1] = DevAddr | MPU9250_AG_I2C_SLV0_ADDR_I2C_SLVO_RD; d[2] = *pCmdAddr; while (BuffLen > 0) { int cnt = min(15, BuffLen); d[3] = MPU9250_AG_I2C_SLV0_CTRL_I2C_SLV0_EN |cnt; g_pSpi->Write(0, d, 4, NULL, 0); // Delay require for transfer to complete usDelay(300 + (cnt << 4)); regaddr = MPU9250_AG_EXT_SENS_DATA_00; cnt = g_pSpi->Read(0, ®addr, 1, pBuff, cnt); if (cnt <=0) break; pBuff += cnt; BuffLen -= cnt; retval += cnt; } return retval; }
//-------------------------------------------------------------------------- // Description: // Delay for at least 'len' ms // void msDelay(unsigned int delay) { while(delay--) { usDelay(1030); } }
//--------------------------------------------------------------------------- // Attempt to acquire a 1-Wire net // // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to // indicate the symbolic port number. // 'port_zstr' - zero terminated port name. // // Returns: TRUE - success, port opened // SMALLINT owAcquire(int portnum, char *port_zstr) { port_zstr = 0; portnum = 0; OW_PORT = 1; // drive bus high. usDelay(500); // give time for line to settle // checks to make sure the line is idling high. return (OW_PORT==1?TRUE:FALSE); }
//--------------------------------------------------------------------------- // Attempt to acquire a 1-Wire net using a com port and a DS2480 based // adapter. // // 'port_zstr' - zero terminated port name. For this platform // use format COMX where X is the port number. // // Returns: The portnum or -1 if the port wasn't acquired. // int owAcquireEx(char *port_zstr) { int portnum = 0; port_zstr = 0; OW_PORT = 1; // drive bus high. usDelay(500); // give time for line to settle // checks to make sure the line is idling high. if(OW_PORT != 1) { OWERROR(OWERROR_OPENCOM_FAILED); return -1; } return portnum; }
void calibrate_zero_torque() { uint16_t last_raw_torque = read_raw_torque(); uint16_t this_raw_torque; while(1) { // Wait 500ms usDelay(500000); // See how much the torque has changed this_raw_torque = read_raw_torque(); int16_t torque_change = (this_raw_torque - last_raw_torque); torque_change = (torque_change < 0) ? (torque_change * -1) : torque_change; // If it's changed less than +/- 4mV, we're calibrated if(torque_change < 5) { break; } // Else, try again last_raw_torque = this_raw_torque; } torque_zero = (double)this_raw_torque; }
void HardwareInit() { // Set this only if nRF is power at 2V or more //nrf_power_dcdcen_set(true); NRF_POWER->DCDCEN = 1; IOPinCfg(s_GpioPins, s_NbGpioPins); IOPinClear(0, BLUEIO_TAG_BME680_LED2_BLUE_PIN); IOPinClear(0, BLUEIO_TAG_BME680_LED2_GREEN_PIN); IOPinClear(0, BLUEIO_TAG_BME680_LED2_RED_PIN); g_Timer.Init(s_TimerCfg); // Initialize I2C #ifdef NEBLINA_MODULE g_Spi.Init(s_SpiCfg); #else g_I2c.Init(s_I2cCfg); #endif bsec_library_return_t bsec_status; // NOTE : For BME680 air quality calculation, this library is require to be initialized // before initializing the sensor driver. bsec_status = bsec_init(); if (bsec_status != BSEC_OK) { printf("BSEC init failed\r\n"); return; } // Inititalize sensor g_TphSensor.Init(s_TphSensorCfg, g_pIntrf, &g_Timer); // g_TphSensor.Disable(); // g_I2c.Disable(); // while(1) __WFE(); if (g_TphSensor.DeviceID() == BME680_ID) { g_GasSensor.Init(s_GasSensorCfg, g_pIntrf, NULL); } g_TphSensor.StartSampling(); usDelay(300000); // Update sensor data TPHSENSOR_DATA tphdata; g_TphSensor.Read(tphdata); if (g_TphSensor.DeviceID() == BME680_ID) { GASSENSOR_DATA gdata; g_GasSensor.Read(gdata); } g_TphSensor.StartSampling(); g_AdvData.Type = BLEADV_MANDATA_TYPE_TPH; // Do memcpy to adv data. Due to byte alignment, cannot read directly into // adv data memcpy(g_AdvData.Data, ((uint8_t*)&tphdata) + sizeof(tphdata.Timestamp), sizeof(BLEADV_MANDATA_TPHSENSOR)); g_I2c.Disable(); #ifdef NRF52_SERIES g_Adc.Init(s_AdcCfg); g_Adc.OpenChannel(s_ChanCfg, s_NbChan); g_Adc.StartConversion(); #endif #ifdef USE_TIMER_UPDATE // Only with SDK14 uint64_t period = g_Timer.EnableTimerTrigger(0, 500UL, TIMER_TRIG_TYPE_CONTINUOUS); #endif }
void MsDelay (unsigned nMilliSeconds) { usDelay(nMilliSeconds * 1000); }