iNEMO and MEMS

Temporary and unofficial forum dedicated to the ST event "iNemo Design Challenge". Designers that are planning to use ChibiOS/RT for the challenge can use the forum to exchange code and experience.
Locked
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

iNEMO and MEMS

Post by RoccoMarco »

Hi, anyone have started to work with iNEMO? I'm trying to import ST libs. Anyone else is working on this?
gabriele
Posts: 5
Joined: Tue Jan 13, 2015 10:50 am

Re: iNEMO and MEMS

Post by gabriele »

Hi
i am trying to include the INEMOEngineLibrary within my application.
In the comments in the include files I read that i am expected to provide an implementation for the Lsm303dlhcAccI2CBufferRead
function (let's take only the accelerometer as an example).

So i was trying to get started with the I2C communication between the ARM processor and the LSM303DLHC sensor.
I implemented a function to scan all the available I2C addresses.

The following code is in the main thread:

Code: Select all

  

// I2C configuration
I2CConfig i2cconfig;
i2cconfig.op_mode = OPMODE_I2C;
i2cconfig.clock_speed = 400000;
i2cconfig.duty_cycle = FAST_DUTY_CYCLE_2;

i2cStart(&I2CD1, &i2cconfig);

i2c_scanner1();

i2cStop(&I2CD1);


where the i2c_scanner1 function is:

Code: Select all

void i2c_scanner1(void){
   uint8_t x = 0, txbuf[2],rxbuf[2];
   int32_t messages = 0;

   chprintf((BaseSequentialStream *)&SDU1,"inside i2c1 scanner\n");
   chThdSleepMilliseconds(10);
   for(x=1;x<128;x++){

      txbuf[0] = 0x00;
      txbuf[1] = 0x00;

       messages = i2cMasterTransmit(&I2CD1, x, txbuf, 2, rxbuf, 0);

       if(messages == 0)
         chprintf((BaseSequentialStream *)&SDU1, "I2C1: Sensor is available on Address: %x \r\n", x, messages);
       else
         chprintf((BaseSequentialStream *)&SDU1, "%d", x);
      chThdSleepMilliseconds(10);
      }
   chThdSleepMilliseconds(500);
   chprintf((BaseSequentialStream *)&SDU1,"outside i2c1 scanner\n");
   chThdSleepMilliseconds(10);
}


None of the 128 addresses replies to the scanning. I always get the RDY_TIMEOUT message from i2cMasterTransmit().
If i provide the i2cMasterTransmit() with some known addresses of the sensors i get the RDY_TIMEOUT as well.

What am i missing? (i am pretty new with embedded programming... :oops:)

Thanks

Gabriele
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: iNEMO and MEMS

Post by RoccoMarco »

Hi, I have already created a library that allow you to use ST Engine with ChibiOS, its name is PLAY and is released on sourceforge. Anyway try LSM303DLHC is connected on I2CD2 and L3GD20 on SPID2.
Ciao,
RM
gabriele
Posts: 5
Joined: Tue Jan 13, 2015 10:50 am

Re: iNEMO and MEMS

Post by gabriele »

Hi rocco

Thanks for your quick reply!
I have just downloaded your library! I have tried the demos and everything's ok!
Great piece of work! and thanks for sharing!

By the way, i would like to understand what i am missing in the i2c_scanner1 function.
I executed the scanner i2c_scanner1 function on I2C2 and i got 2 replies, at the addresses 0x19 and 0x1E,
which are not the addresses of the accelerometer and magnetometer (0x33 and 0x3D respectively).

Of course i am missing something in my scanner function, since in your library you communicate with
the sensors through the expected addresses.

In addition, i would like to get barometer data as well. If i am not wrong, it is not included in PLAY. And it
would be a good exercise for me to make the ST libraries for LPS331AP work.
That's why i would like to understand what i am missing.

Thanks for your patience!

Gabriele
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: iNEMO and MEMS

Post by RoccoMarco »

Hi,
you could read here (i2cMasterReceiveTimeout doku) that addr must be
slave device address (7 bits) without R/W bit
:mrgreen:

Anyway I will develop pressure sensor, temperature and humidity module ASAP.
gabriele
Posts: 5
Joined: Tue Jan 13, 2015 10:50 am

Re: iNEMO and MEMS

Post by gabriele »

Hi,

ok... :oops: ! without considering the R/W bit everything is ok!

Thanks, and looking forward for the pressure sensor.

Gabriele
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: iNEMO and MEMS

Post by RoccoMarco »

Don't worry, at that time I have been trapped on this point for a couple of days. :D
Good work,
RM
Locked