Skip to content

Commit

Permalink
[#133] Fix data rate bit width
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidZemon committed Feb 28, 2019
1 parent 68e60ad commit c5f3f09
Show file tree
Hide file tree
Showing 11 changed files with 1,511 additions and 2 deletions.
1 change: 1 addition & 0 deletions Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_subdirectory(Libpropeller_Pwm32)
add_subdirectory(libPropelleruino_Blinky)
add_subdirectory(PropWare_ADXL345)
add_subdirectory(PropWare_Blinky)
add_subdirectory(PropWare_BNO055)
add_subdirectory(PropWare_BufferedUART)
add_subdirectory(PropWare_DualPWM)
add_subdirectory(PropWare_Eeprom)
Expand Down
Binary file added Examples/PropWare_BNO055/BNO055.pdf
Binary file not shown.
115 changes: 115 additions & 0 deletions Examples/PropWare_BNO055/BNO055_Demo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* @file BNO055_Demo.cpp
*
* @author David Zemon
*
* @copyright
* The MIT License (MIT)<br>
* <br>Copyright (c) 2013 David Zemon<br>
* <br>Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:<br>
* <br>The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.<br>
* <br>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <PropWare/sensor/fusion/bno055.h>
#include <Simple-Libraries/Learn/Simple Libraries/Protocol/libsimplei2c/simplei2c.h>

using PropWare::I2CMaster;
using PropWare::BNO055;
using PropWare::Pin;

uint8_t get_byte (i2c *bus) {
i2c_start(bus);
i2c_writeByte(bus, BNO055::DEVICE_ADDRESS_A);
i2c_writeByte(bus, BNO055::convert(BNO055::Address::CHIP_ID));
const uint8_t result = static_cast<uint8_t>(i2c_readByte(bus, 1));
i2c_stop(bus);
return result;
}

PropWare::ErrorCode begin (i2c *bus) {
auto id = get_byte(bus);
if (id != BNO055::ID) {
waitcnt(SECOND + CNT); // hold on for boot
id = get_byte(bus);
if (id != BNO055::ID) {
pwOut << "fail 0\n";
return BNO055::FAILED_TO_BOOT;
}
}
return 0;
}

int ping (i2c *bus) {
return i2c_poll(bus, BNO055::DEVICE_ADDRESS_A);
}

/**
* @example BNO055_Demo.cpp
*
*
* @include PropWare_BNO055/CMakeLists.txt
*/
int main () {
PropWare::ErrorCode error;
const Pin resetPin(PropWare::Port::P23, Pin::Dir::OUT);
waitcnt(100 * MILLISECOND + CNT);

i2c bus;
i2c_open(&bus, Pin::from_mask(I2CMaster::DEFAULT_SCL_MASK), Pin::from_mask(I2CMaster::DEFAULT_SDA_MASK), 0);

for (unsigned int i = 0; i < 5; ++i) {
resetPin.clear();
waitcnt(MILLISECOND + CNT);
resetPin.set();

while (ping(&bus))
waitcnt(10 * MILLISECOND + CNT);
int ack = i2c_writeByte(&bus, 0);
i2c_readByte(&bus, 0);
i2c_stop(&bus);
waitcnt(10 * MILLISECOND + CNT);

error = begin(&bus);
if (!error)
break;
}

//BNO055 sensor;
//for (int i = 0; i < 5; ++i) {
// resetPin.clear();
// waitcnt(MILLISECOND + CNT);
// resetPin.set();
//
// while (!pwI2c.ping(BNO055::DEVICE_ADDRESS_A))
// waitcnt(10 * MILLISECOND + CNT);
// pwI2c.send_byte(0);
// pwI2c.get(BNO055::DEVICE_ADDRESS_A, static_cast<uint8_t>(0));
// pwI2c.stop();
// waitcnt(10 * MILLISECOND + CNT);
//
// error = sensor.begin();
// if (!error)
// break;
//}

if (error)
pwOut << "Error: " << error << '\n';
else
while (1) {
pwOut << "Temperature = " << /*sensor.get_temperature() <<*/ '\n';
waitcnt(SECOND + CNT);
}
}
6 changes: 6 additions & 0 deletions Examples/PropWare_BNO055/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.3)
find_package(PropWare REQUIRED)

project(BNO055_Demo)

create_simple_executable(${PROJECT_NAME} BNO055_Demo.cpp)
4 changes: 4 additions & 0 deletions PropWare/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(PROPWARE_SOURCES
${CMAKE_CURRENT_LIST_DIR}/sensor/analog/mcp3xxx.h
${CMAKE_CURRENT_LIST_DIR}/sensor/analog/pcf8591.h
${CMAKE_CURRENT_LIST_DIR}/sensor/distance/ping.h
${CMAKE_CURRENT_LIST_DIR}/sensor/fusion/bno055.h
${CMAKE_CURRENT_LIST_DIR}/sensor/gyroscope/l3g.h
${CMAKE_CURRENT_LIST_DIR}/sensor/temperature/max6675.h
${CMAKE_CURRENT_LIST_DIR}/serial/can/mcp2515.h
Expand All @@ -55,6 +56,9 @@ set(PROPWARE_SOURCES
${CMAKE_CURRENT_LIST_DIR}/utility/comparator.cpp
${CMAKE_CURRENT_LIST_DIR}/utility/comparator.h
${CMAKE_CURRENT_LIST_DIR}/utility/utility.h
${CMAKE_CURRENT_LIST_DIR}/utility/ahrs/matrix.h
${CMAKE_CURRENT_LIST_DIR}/utility/ahrs/quaternion.h
${CMAKE_CURRENT_LIST_DIR}/utility/ahrs/vector.h
${CMAKE_CURRENT_LIST_DIR}/c++allocate.h
${CMAKE_CURRENT_LIST_DIR}/PropWare.cpp
${CMAKE_CURRENT_LIST_DIR}/PropWare.h
Expand Down
2 changes: 1 addition & 1 deletion PropWare/sensor/accelerometer/adxl345.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class ADXL345 {
/**
* Set the data polling rate.
*/
DataRate dataRate: 3;
DataRate dataRate: 4;
/**
* Enable or disable low-power mode. Low power mode has a somewhat higher noise but reduces power
* consumption. True to enable low power mode, false for normal operation.
Expand Down
Loading

0 comments on commit c5f3f09

Please sign in to comment.