-2

I am working on a project where I'm trying to implement I2C master-slave communication so as to read some data from a magnetic sensor. That's all OK and I have written the code. However, I am not quite sure about the slave address needed for the communication to actually happen. The board I'm using can hold STM32 ARM® Cortex™-M3 and Cortex™-M4 MCU's. I don't know if it matters, but the MCU I'm using is STM32F107VCT6.

The part of the code where I need to enter the address is in the following function marked as "SLAVE_ADDRESS_GOES_HERE":

uint8_t Magnet_readReg(const uint8_t regAdd)
  {
    uint8_t pom[1] = {0};
    pom[0] = regAdd;
    I2C1_Start();
    I2C1_Write(SLAVE_ADDRESS_GOES_HERE, pom, 1, END_MODE_RESTART);
    I2C1_Read(SLAVE_ADDRESS_GOES_HERE, pom, 1, END_MODE_STOP);

    return pom[0];
  }

The results should be some numbers which tell me how strong the magnetic field is. It has three different values as an output because it calculates a value for each of the three axes (yes, it's the correct plural of the word axis), so it can could be used as a compass for example.

Now the trick is that I don't get any results because I don't know the actual address of the sensor. Therefore, I will share the datasheet of the sensor I'm using. I am not sure if i'm reading it correctly.

Here is the datasheet:

https://www.memsic.com/userfiles/files/Datasheets/Magnetic-Sensors-Datasheets/MMC3416xPJ_Rev_C_2013_10_30.pdf


Solved.
As it turns out, there was something wrong with the board itself. Therefore, a connection couldn't be established. And the address is 60H for writing and 61H for reading. 30H is the address, but when you add a zero or a one in the LSB position you get 60H or 61H.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Strale030
  • 1
  • 4
  • There should be two numbers on the sensor - the first one is your slave address. – tofro Dec 01 '17 at 21:04
  • 1
    The slave address is explained on page 4 of the datasheet you linked. What don't you understand? What is the complete part number for your device? Or what number is printed on the device? – kkrambo Dec 01 '17 at 22:04
  • Ok, thanks for the quick replies. I can try this out on monday. That's when I'll have access to the hardware ( you know, university equipment and such). I'll deffinitely try it and post the answer. – Strale030 Dec 01 '17 at 23:16
  • 1
    I'm not familiar with the library for STM32 devices, but do be wary about how you write the slave address into the function - it's not clear whether you write the slave address as a 7-bit number (0XXXXXXX), or you bit-shift the 7-bit number left by one before passing to the function (XXXXXXX0). – Ed King Dec 02 '17 at 09:36
  • I solved the problem. The description is in the edited post. Thanks for taking the time to read this. :) @EdKing – Strale030 Dec 04 '17 at 21:23

1 Answers1

0

The I2C address of your sensor is described on page 4 of the datasheet you provided. You must read the marking on your device package, then use the table from "Number" to "Part number" in the datasheet to determine your exact part. Finally, use the table under the "Ordering Guide" to find the factory-programmed I2C slave address of your device.

Given that you later specified that your 7-bit I2C slave address is 0x30, then you must have part number MMC34160PJ, which should be marked:

0 •
XX

jskroch
  • 333
  • 2
  • 8