This is my first time posting to this form. I am trying to access data from an IMU
(SparkFun 9DoF SEN-13944), focusing on the Magnetometer. The I2C address is listed as 0X1e. I have borrowed and adapted code that had been posted by others on this form working on I2c communication (thanks to all those who have shared their efforts). I am receiving data from this address. However, the data does not change as I move the sensor and does not make sense when translated from hex to decimal. I have tried changing the transmission speed for the code and for the serial monitor with no luck. I have also changed the number of Bytes being read - this does change the output but does not make the data any more reasonable.
The code I am using is:
#include <stdio.h>
#include <string.h>
#include "daisy_seed.h"
#include "daisy_core.h"
using namespace daisy;
DaisySeed hw;
{
static DaisySeed seed;
unsigned char address = 0x1e;
uint8_t testData[33];
long counter = 1L;
seed.Configure();
seed.Init();
seed.StartLog(false);
System::Delay(5000);
static constexpr I2Cint main(void)Handle::Config _i2c_config
= {I2CHandle::Config::Peripheral::I2C_1,
{{DSY_GPIOB, 8}, // SCL op Daisy Seed Pin 12
{DSY_GPIOB, 9}}, // SDA op Daisy Seed Pin 13
I2CHandle::Config::Speed::I2C_100KHZ,
I2CHandle::Config::Mode::I2C_MASTER};
I2CHandle _i2c;
_i2c.Init(_i2c_config);
while(1) {
// Ask for 31 bytes.
uint8_t number = 32;
uint8_t sensor_Data = 0;
seed.PrintLine("%05ld Asking for %d bytes on address %0x.", counter, number, address);
I2CHandle::Result i2cResult = _i2c.TransmitBlocking(address, &number, 1, 500);
if (i2cResult == I2CHandle::Result::OK) {
seed.PrintLine("%05ld Successfully transmitted requested number of bytes: %0x.", counter, number);
// Receive the requested number of bytes + CRC
seed.PrintLine("%05ld Receiving %0d bytes from address %0x.", counter, number + 1, address);
i2cResult = _i2c.ReceiveBlocking(address, testData, number + 1, 500);
if(i2cResult == I2CHandle::Result::OK) {
seed.PrintLine("%05ld %0d bytes were received from address %0x.", counter, number, address);
seed.PrintLine("%05ld Received %0x.", counter, testData);
for(int i = 0; i < 32; i++) {
//uint8_t digit = &testData[i];
seed.PrintLine("assel digit %0x", testData[i]);
}
}
} else {
seed.PrintLine("%05ld Request for data not acknowledged.", counter);
}
System::Delay(1000);
counter++;
}
}
The data I am receiving looks like this
00013 Asking for 32 bytes on address 1e.
00013 Successfully transmitted requested number of bytes: 20.
00013 Receiving 33 bytes from address 1e.
00013 32 bytes were received from address 1e.
00013 Received 2001ffb0.
assel digit 18
assel digit 0
assel digit 3
assel digit 0
assel digit 0
assel digit 0
assel digit 0
assel digit 0
assel digit 8b
assel digit 8
assel digit 5b
assel digit ff
assel digit 4
assel digit f5
assel digit 8b
assel digit 8
assel digit 5b
assel digit ff
assel digit 4
assel digit f5
assel digit 8b
assel digit 8
assel digit 5b
assel digit ff
assel digit 4
assel digit f5
assel digit 8b
assel digit 8
assel digit 5b
assel digit ff
assel digit 4
assel digit f5
Any suggestions would be greatly appreciated.