From f37236fa01469050714f89f839a1fac51a824096 Mon Sep 17 00:00:00 2001 From: Abhishek Malik Date: Mon, 28 Aug 2017 16:40:08 -0700 Subject: [PATCH] MMA7660: changed mraa i2c read call The mraa_i2c_read_bytes_call didn't work with firmata based platforms and was changed to mraa_i2c_read_bytes_data call which worked. Signed-off-by: Abhishek Malik --- src/mma7660/mma7660.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mma7660/mma7660.c b/src/mma7660/mma7660.c index 7ffe47a2..c27e9e68 100644 --- a/src/mma7660/mma7660.c +++ b/src/mma7660/mma7660.c @@ -99,13 +99,14 @@ upm_result_t mma7660_write_byte(const mma7660_context dev, upm_result_t mma7660_read_byte(const mma7660_context dev, uint8_t reg, uint8_t *byte) { + uint8_t data[11]; assert(dev != NULL); - int x = mraa_i2c_read_byte_data(dev->i2c, reg); + int ret = mraa_i2c_read_bytes_data(dev->i2c, 0x00, data, 11); - if (x < 0) - { - printf("%s: mraa_i2c_read_byte_data() failed.\n", __FUNCTION__); + if (ret != 11) { + printf("%s: mraa_i2c_read_bytes_data() failed.\n", __FUNCTION__); + printf("returned %d bytes upon read\n", ret); if (byte) *byte = 0; @@ -113,7 +114,7 @@ upm_result_t mma7660_read_byte(const mma7660_context dev, uint8_t reg, } if (byte) - *byte = (uint8_t)(x & 0xff); + *byte = (uint8_t)(data[reg] & 0xff); return UPM_SUCCESS; }