我正在尝试使用InvenSense的运动驱动程序6.12从MPU-6050的DMP读取数据。
dmp_load_motion_driver_firmware();
此代码也来自动作驱动程序源代码。
初始化mpu后,我正在调用/**
* @brief Load and verify DMP image.
* @param[in] length Length of DMP image.
* @param[in] firmware DMP code.
* @param[in] start_addr Starting address of DMP code memory.
* @param[in] sample_rate Fixed sampling rate used when DMP is enabled.
* @return 0 if successful.
*/
int mpu_load_firmware(unsigned short length, const unsigned char *firmware,
unsigned short start_addr, unsigned short sample_rate)
{
unsigned short ii;
unsigned short this_write;
/* Must divide evenly into st.hw->bank_size to avoid bank crossings. */
#define LOAD_CHUNK (16)
unsigned char cur[LOAD_CHUNK], tmp[2];
if (st.chip_cfg.dmp_loaded)
/* DMP should only be loaded once. */
return -1;
if (!firmware)
return -1;
for (ii = 0; ii < length; ii += this_write) {
this_write = min(LOAD_CHUNK, length - ii);
if (mpu_write_mem(ii, this_write, (unsigned char*)&firmware[ii]))
return -1;
if (mpu_read_mem(ii, this_write, cur))
return -1;
if (memcmp(firmware+ii, cur, this_write))
return -2;
}
/* Set program start address. */
tmp[0] = start_addr >> 8;
tmp[1] = start_addr & 0xFF;
if (i2c_write(st.hw->addr, st.reg->prgm_start_h, 2, tmp))
return -1;
st.chip_cfg.dmp_loaded = 1;
st.chip_cfg.dmp_sample_rate = sample_rate;
return 0;
}
,看起来像这样。
mpu_read_mem
如您所见,这会将固件写入MPU,读回数据并检查它们是否匹配。不幸的是他们不匹配,我不知道为什么。 foo = {unsigned char [16]}
[0] = {unsigned char} 0 '\000'
[1] = {unsigned char} 255 '�'
[2] = {unsigned char} 255 '�'
[3] = {unsigned char} 255 '�'
[4] = {unsigned char} 255 '�'
[5] = {unsigned char} 255 '�'
[6] = {unsigned char} 255 '�'
[7] = {unsigned char} 255 '�'
[8] = {unsigned char} 255 '�'
[9] = {unsigned char} 255 '�'
[10] = {unsigned char} 255 '�'
[11] = {unsigned char} 255 '�'
[12] = {unsigned char} 255 '�'
[13] = {unsigned char} 255 '�'
[14] = {unsigned char} 255 '�'
[15] = {unsigned char} 255 '�'
读取的值如下所示
object LocalDateEx {
/**an alternative of LocalDate.now(), as it requires initialization using AndroidThreeTen.init(context), which takes a bit time (loads a file)*/
@JvmStatic
fun getNow(): LocalDate = Calendar.getInstance().toLocalDate()
}
fun Calendar.toLocalDate(): LocalDate = LocalDate.of(get(Calendar.YEAR), get(Calendar.MONTH) + 1, get(Calendar.DAY_OF_MONTH))
官方开发者论坛上有一些帖子存在完全相同的问题,但没有一个提供此问题的解决方案。
也许有些人有同样的问题,可以帮助我。