Read an MMA8451

18 Aug 2017

Hello, I was working on my FRDM KL25 with KDS. I want to try MBED online compiler. For that I have made a small program wich read a MMA8451 accelerometer (adress 0x1D) connected on PTE0 and PTE1. For your information, it's working fine with my KDS program. The program is very simple:

#include "mbed.h"
#define REG_WHO_AM_I 0x0D

I2C i2c2(PTE0,PTE1);
Serial pc(USBTX,USBRX);
 
int main() {
char    v;
char    cmd;
cmd    = REG_WHO_AM_I;
pc.baud(115200);
i2c2.write(0x1D, &cmd, 1 );
i2c2.read(0x1D, &v, 1 );
pc.printf("received=%d\n",v);
}

I should received 0x1A and I received 0x4D Here follow the DataAnalyzer picture:

/media/uploads/michastro/p4.jpg

Thanks for your Help Michel

17 Aug 2016

you should use device of softbank.

27 Mar 2017

Hi,

According to the I2C function class document,
read
address 8bit I2C slave address [ addr | 1 ]
so it should be ((0x1D << 1) | 0x01 ) = 0x3B

write
address 8bit I2C slave address [ addr | 0 ]
so it should be ((0x1D << 1) | 0x00) = 0x3A

So why don't you try
i2c2.write(0x3A, &cmd, 1 ) ;
i2c2.read(0x3B, &v, 1 ) ;

In case it does not work, I'm sorry.

moto

29 Mar 2017

Wickr : weeddrop 대마,대마초,떨팝니다,떨판매,확실한인증,수도권떨,서울떨,드랍형식판매 장기거래 가능