accessing i2c-interface of the STM32F4

Firmware/software/electronics/mechanics
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

accessing i2c-interface of the STM32F4

Post by Che. »

Hi everyone,

can someone explain to me how it is possible to access the i2c-interface of the STM32 on the Crazyflie 2.0?

Is it possible to access it via the given python library for instance? I've found the topic with the VL6180 viewtopic.php?f=6&t=1423&hilit=i2c already, but it seems that it's a more specific solution to this sensor there. I'd like to know how to use the interface more generally (for different sensors).

I also read the code of the i2cdev-drivers but i cant seem to understand much of it at this point.

Any answer is greatly appreciated! :)

Greets,
Che.
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: accessing i2c-interface of the STM32F4

Post by Che. »

@mods: maybe its better to move this post to the developers?

greets
che.
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: accessing i2c-interface of the STM32F4

Post by tobias »

To read from the I2C port you currently need to alter the firmware and implement you reading code using the i2cdev interface similar to what is done in the vl6180 thread. Reading from I2C can be a bit complex if it is your first time so it might be wise to read up on how i2c works before you start.
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: accessing i2c-interface of the STM32F4

Post by Che. »

hi tobias,
i chose to stay in the c-environment.
while using the i2cdev library, do i have to worry about the RTOS-environment when implementing a simple read-write function for my i2c peripheral?


edit:

i am working through the code and got some questions:
  • is it true, that I2C2 is the only available i2c-interface that is still unused? the pins on the extension board belong to this one, right? it seems like I2C1 is used for the eeprom and I2C3 is used for the mpu.
  • when using the function i2cdevInit, RTOS-management is automatically started with all needed configurations?
  • do i have to worry about the i2c-protocoll of my i2c peripheral? i think i need to write a driver for the device.
thanks for all answers.

greets, Che
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: accessing i2c-interface of the STM32F4

Post by tobias »

is it true, that I2C2 is the only available i2c-interface that is still unused? the pins on the extension board belong to this one, right? it seems like I2C1 is used for the eeprom and I2C3 is used for the mpu
The availible i2c interface on the deck port is I2C1 which is shared with the EEPROM. The EEPROM is currently only read at startup. Since the EEPROM will init i2c1 device you don't have to do that again.
when using the function i2cdevInit, RTOS-management is automatically started with all needed configurations?
Yes and see above. However it might currently be wise to try to use the stabilizer task (where i2c3 is used) when using the i2c1 bus as we have seen issues using them in parallel (issue with the i2cdev driver).
do i have to worry about the i2c-protocoll of my i2c peripheral? i think i need to write a driver for the device.
You should be OK using the i2cdev functions as they are the HAL.
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: accessing i2c-interface of the STM32F4

Post by Che. »

hi tobias, thanks for your replies to my questions.

i have a problem to understand how the initialization of the device actually works.
The EEPROM is currently only read at startup. Since the EEPROM will init i2c1 device you don't have to do that again.
i assume this happens in system.c in the function systemInit() when calling configblockInit().

configblockInit() however calls two functions:

Code: Select all

i2cdevInit(I2C1_DEV);
eepromInit(I2C1_DEV);
in the vl6180x thread you posted following code:

Code: Select all

uint8_t VL6180xInit(I2C_Dev *i2cPort)
{
  uint8_t data; //for temp data storage

  if (isInit)
    return 0;

  I2Cx = i2cPort;
  devAddr = 0x29; // Check if it is the correct initial I2C address

  data = VL6180x_getRegister(VL6180X_SYSTEM_FRESH_OUT_OF_RESET);

  if(data != 1) return VL6180x_FAILURE_RESET;

  //Required by datasheet
  //http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf
  VL6180x_setRegister(0x0207, 0x01);
  VL6180x_setRegister(0x0208, 0x01);
  VL6180x_setRegister(0x0096, 0x00);
  VL6180x_setRegister(0x0097, 0xfd);
  VL6180x_setRegister(0x00e3, 0x00);
  VL6180x_setRegister(0x00e4, 0x04);
  VL6180x_setRegister(0x00e5, 0x02);
  VL6180x_setRegister(0x00e6, 0x01);
  VL6180x_setRegister(0x00e7, 0x03);
  VL6180x_setRegister(0x00f5, 0x02);
  VL6180x_setRegister(0x00d9, 0x05);
  VL6180x_setRegister(0x00db, 0xce);
  VL6180x_setRegister(0x00dc, 0x03);
  VL6180x_setRegister(0x00dd, 0xf8);
  VL6180x_setRegister(0x009f, 0x00);
  VL6180x_setRegister(0x00a3, 0x3c);
  VL6180x_setRegister(0x00b7, 0x00);
  VL6180x_setRegister(0x00bb, 0x3c);
  VL6180x_setRegister(0x00b2, 0x09);
  VL6180x_setRegister(0x00ca, 0x09);
  VL6180x_setRegister(0x0198, 0x01);
  VL6180x_setRegister(0x01b0, 0x17);
  VL6180x_setRegister(0x01ad, 0x00);
  VL6180x_setRegister(0x00ff, 0x05);
  VL6180x_setRegister(0x0100, 0x05);
  VL6180x_setRegister(0x0199, 0x05);
  VL6180x_setRegister(0x01a6, 0x1b);
  VL6180x_setRegister(0x01ac, 0x3e);
  VL6180x_setRegister(0x01a7, 0x1f);
  VL6180x_setRegister(0x0030, 0x00);

  isInit = true;
  return 0;
}
and you wrote
Also the VL6180 is connected to I2C1 so it should be initialized with VL6180xInit(I2C1_DEV)
That is, in my opinion, because one has to set the devAddr, is that right?

Now my question is, where in the code do i call my Init-function, that sets the device address for my device?

thanks for your answers.

Greets, Che



Edit:

Is it necessary to configure the I2C-Port for my own sensor? I am using the LIDAR LITE 2 by PulsedLight http://pulsedlight3d.com/.
It has a special I2C-protocoll which i want to use. I am really stuck and my head is spinning because of all those structs :D

I am not able to read any registers as i am not sure the I2C-accessing lib is compatible to the device in the first place.
___
UPDATE 1:
Now I cleaned up with my pointers and get some readings from the lidar-registers.
Trying to get some proper distance readings now.

UPDATE 2:
Seems like I hit the same bug as mwall002 in his posts (updating of ToC didnt work), fixed it and now i am back the old problem.

Its hard to get the Device I2C1 to work as my sensor.
In my opinion we get in trouble when trying to stay in eeprom.c and modifying it.

Code: Select all

bool eepromInit(I2C_Dev *i2cPort)
{
  if (isInit)			//I think this part isn't necessary, because isInit is a global variable
    return true;		//s.o.

  I2Cx = i2cPort;	//s.o.
  devAddr = EEPROM_I2C_ADDR; //here should be the lidar-adress

  isInit = true;		//s.o.

  return true;		//s.o.
}
When calling this function my crazyflie freezes.
can anybody help me?
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: accessing i2c-interface of the STM32F4

Post by Che. »

after looking through the VL6180x-Branch i think i need to implement the proximity-hal in my project. seems like most work is already done by tobbeanton, i assume its you tobias?

also pushing.
:)
greets, Che

Edit:

after initializing, when reading i get the AF-Error by the CPAL.
I get the error even if i did not connect the SCL/SDA Port to my Sensor. Is it even possible to produce this error, when no device is connected?

I am still happy about any answer :D
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: accessing i2c-interface of the STM32F4

Post by tobias »

Well you seem to have some difficult problems and I wish I could provide an easy answer. I can't say we are happy with the CPAL library. It is big and complex and we are thinking about switching to the CubeMX lib instead (that is a lot of work though).

If you have access to any i2c analyser I think that would be the easiest way to debug. Without it, it is hard to know where the problem lies.
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: accessing i2c-interface of the STM32F4

Post by Che. »

hi tobias,

thanks for your answer!
tobias wrote:If you have access to any i2c analyser I think that would be the easiest way to debug. Without it, it is hard to know where the problem lies.
Do you have an example for an i2c analyser for me? I cant quite imagine what that looks like. Possibly an oscilloscope?

I might switch to my raspberry pi to get on with the driver for my i2c device as it seems that my crazyflie is somehow broken (as discussed in the other thread).

I'd be grateful if you have any solution for my I2C-Clock-Problem.
viewtopic.php?f=6&t=1733
atomicdog
Expert
Posts: 105
Joined: Tue Mar 12, 2013 2:50 am
Location: San Diego

Re: accessing i2c-interface of the STM32F4

Post by atomicdog »

Che. wrote:
Do you have an example for an i2c analyser for me? I cant quite imagine what that looks like. Possibly an oscilloscope?
The Aardvark is one. I'm sure there's cheaper ones but I like the Aardvark a lot.

You can use an O-scope of course but it's very tedious work that way.
6-DOF CF | wireless xbox 360 controller
Post Reply