0

I am trying to get a MEMS-module (ISM330DLC) to work together with an Arduino Uno but I can't get it to work. I am using the ism330dlc drivers.

ISM330dlc Drivers: https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/ism330dlc_STdC

ISM330dlc Datasheet: http://www.farnell.com/datasheets/2339632.pdf

ISM330dlc Application Notes: https://www.st.com/content/ccc/resource/technical/document/application_note/group0/68/eb/a3/cd/2c/78/45/41/DM00468454/files/DM00468454.pdf/jcr:content/translations/en.DM00468454.pdf

I have switched out the voltage regulator to a 3.3V on the Arduino following this guide: https://learn.adafruit.com/arduino-tips-tricks-and-techniques/3-3v-conversion

I am using the STEVAL-MKI182V2 board for easier wiring. This is the current wiring:

Arduino Pin<------------->STEVAL Pin

Pin 10 (SS)<------------->CS

Pin 11 (MOSI)<------------->SDA

Pin 12 (MISO)<------------->SDO

Pin 13 (SCK)<------------->SCL

SDx is connected to ground, SCx is connected to VddIO. The board is also connected to ground on the Arduino as well as Vin 3.3V.

Here is the code:

/* SPI Pin config (There are other pins dedicated to SPI I think) */
#define SSpin 10
#define MOSIpin 11
#define MISOpin 12
#define SCKpin 13

/* Variables used to store data */
static axis3bit16_t data_raw_acceleration;
static axis3bit16_t data_raw_angular_rate;
static float acceleration_mg[3];
static float angular_rate_mdps[3];

static int32_t platform_write(void *handle, uint8_t Reg, uint8_t *Bufp, uint16_t len) {
  SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE3));
  digitalWrite(SSpin, LOW);
  SPI.transfer(Reg);
  SPI.transfer(Bufp);
  digitalWrite(SSpin, HIGH);
  SPI.endTransaction();
  return 0;
}
static int32_t platform_read(void *handle, uint8_t Reg, uint8_t     *Bufp, uint16_t len) {
  Reg |= 0x80; //Set bit 0 (MSB) in order to read
  SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE3));
  digitalWrite(SSpin, LOW);
  SPI.transfer(Reg);
  *Bufp = SPI.transfer(0x00); //Dummy send to get value from module
  digitalWrite(SSpin, HIGH);
  SPI.endTransaction();
  return 0;
}

/* Init mems driver interface */
ism330dlc_ctx_t dev_ctx = {platform_write, platform_read, 0};
//dev_ctx.write_reg = platform_write;
//dev_ctx.read_reg = platform_read;
//dev_ctx.handle = 0; //No handler needed

void setup() {
  delay(100);
  Serial.begin(9600);
  pinMode(SSpin, OUTPUT);
  digitalWrite(SSpin, HIGH);

  /* Initialize SPI */
  SPI.begin();
  //SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));     //MSBFIRST, SPI_MODE3


  /* Needed for setup */
  static uint8_t whoamI, rst;

  /* Check if device ID is correct */
  whoamI = 0;
  ism330dlc_device_id_get(&dev_ctx, &whoamI);
  while (whoamI != ISM330DLC_ID) {
    Serial.print("Wrong device ID!! \n"); Serial.print("whoamI: ");     Serial.print(whoamI); Serial.print("\n\n"); delay(50);     ism330dlc_device_id_get(&dev_ctx, &whoamI);
  }

  /*Restore default config */
  ism330dlc_reset_set(&dev_ctx, PROPERTY_ENABLE);
  do {
    Serial.print("reset:"); Serial.print(rst); Serial.print("\n\n");
    ism330dlc_reset_get(&dev_ctx, &rst);
  } while (rst);

The problem is that whenever I run this code I get DeviceID 255 no matter what (ism330dlc device id is 106). One thing I noticed is that if I reset the Arduino and quickly insert the USB cable and upload the code (in the time interval of a second) I can get the right device ID, but then I can't restore the default configuration (i.e not read or write again). Any tips what might cause this? I have tried SPI.setClockDivider() as well as different SPI Modes.

UPDATE: Removing ground from GND, SCx and SDx makes me get the correct deviceID but I still get stuck on trying to restore default configurations.

  • You are powering the STEVAL board from the VIN pin of the Arduino, while powering the Arduino through USB? – Majenko Apr 19 at 12:35
  • No sorry about that, I am powering the STEVAL-board using the 3.3v output on the Arduino. Edit: I have also tried powering it using an extern source at 2.8V. – Nic Apr 19 at 13:33
  • Sorry there was a time limit on editing comments more than once. The Arduino is powered through USB and the STEVAL board is powered through the 3.3v output. – Nic Apr 19 at 17:02
  • I realize now that I have not added any coupling capacitors to Vdd and Vdd_IO, could that affect the data? – Nic Apr 21 at 16:07
  • Unlikely. The STEVAL board will have plenty of decoupling built in. – Majenko Apr 21 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.