[SOLVED] EEPROM: I2C connection [FAIL]

Firmware/software/electronics/mechanics
Duncan
Beginner
Posts: 9
Joined: Mon Aug 27, 2018 1:13 am

[SOLVED] EEPROM: I2C connection [FAIL]

Post by Duncan » Thu Aug 30, 2018 2:30 am

Hi,
I am trying to add a sensor which would send the data back to crazyflie via the I2C bus so I wrote a deck driver. After I connected the cables (sensor SDA->crazyflie SDA, sensor SCL->crazyflie SCL), the crazyflie couldn't start normally(only two blue LEDs light solidly). There were two times I actually got it started and console showed "EEPROM: I2C connection [FAIL]" and I couldn't get the data from my sensor.

Is that because of my connection that made the EEPROM I2C connection fail? And are there any built-in pull up resistors for the crazyflie I2C bus?

Thank you in advance.

Duncan

Here is the main part of my driver code:

Code: Select all

static void scannerTask(void *param)
{
  systemWaitStart();

  TickType_t lastWakeTime = xTaskGetTickCount(); //get tick time count

  while(1) {
    vTaskDelayUntil(&lastWakeTime, M2T(50));   //delay some time get next data

    if(i2cdevReadByte(I2CX,0x74,I2CDEV_NO_MEM_ADDR,&rssi_value))
    {
    	DEBUG_PRINT("Data received.\n");
    	DEBUG_PRINT("rssi: %d.\n",rssi_value);
    }
  }
}

arnaud
Bitcraze
Posts: 1706
Joined: Tue Feb 06, 2007 12:36 pm

Re: EEPROM: I2C connection [FAIL]

Post by arnaud » Thu Aug 30, 2018 7:36 am

Hi,

it does look like your connections are disturbing the I2C bus, the configuration EEPROM in the Crazyflie is connected to the deck-port I2C bus and so yes there is pull-ups in the Crazyflie on this I2C bus. You can look at the schematic if you want to see more precisely how things are cabled: https://wiki.bitcraze.io/_media/project ... matics.pdf.

Since you are calling systemWaitStart() in your driver, you are not affecting the boot of the system so the driver is most likely not causing that problem.

Duncan
Beginner
Posts: 9
Joined: Mon Aug 27, 2018 1:13 am

Re: EEPROM: I2C connection [FAIL]

Post by Duncan » Fri Aug 31, 2018 1:45 am

arnaud wrote:
Thu Aug 30, 2018 7:36 am
Hi,

it does look like your connections are disturbing the I2C bus, the configuration EEPROM in the Crazyflie is connected to the deck-port I2C bus and so yes there is pull-ups in the Crazyflie on this I2C bus. You can look at the schematic if you want to see more precisely how things are cabled: https://wiki.bitcraze.io/_media/project ... matics.pdf.

Since you are calling systemWaitStart() in your driver, you are not affecting the boot of the system so the driver is most likely not causing that problem.
Thank you, arnaud. But I can sure that my connection is right as it is so straightforward. I couldn't figure out where the problem would be.

arnaud
Bitcraze
Posts: 1706
Joined: Tue Feb 06, 2007 12:36 pm

Re: EEPROM: I2C connection [FAIL]

Post by arnaud » Fri Aug 31, 2018 6:06 am

Can you test with the stock firmware to start the Crazyflie with and without your connections, that would verify if the problem is there or not.

If it is, it would be useful to look at the signals with an oscilloscope to see what goes wrong with it. Are you attaching long cables or extra capacitor/resistors to the lines? Are you sure the I2C address of that you are attaching is not in collision with the I2C EEPROM?

Duncan
Beginner
Posts: 9
Joined: Mon Aug 27, 2018 1:13 am

Re: EEPROM: I2C connection [FAIL]

Post by Duncan » Thu Sep 06, 2018 12:27 am

Hi arnaud,
Can you test with the stock firmware to start the Crazyflie with and without your connections, that would verify if the problem is there or not.

If it is, it would be useful to look at the signals with an oscilloscope to see what goes wrong with it. Are you attaching long cables or extra capacitor/resistors to the lines? Are you sure the I2C address of that you are attaching is not in collision with the I2C EEPROM?
It turned out it might be the problem of the sensor. I change the sensor and the EEPROM problem is solved. But now all the values read by the crazyflie are 0 and I guess I might never truly read the data from the sensor. I used exact the same connection to the arduino and the arduino can read the values.

Thank you in advance.
Duncan

arnaud
Bitcraze
Posts: 1706
Joined: Tue Feb 06, 2007 12:36 pm

Re: EEPROM: I2C connection [FAIL]

Post by arnaud » Thu Sep 13, 2018 8:15 am

One thing that could be happening is that the bus speed is configured too fast. It is currently configured at 400KHz: https://github.com/bitcraze/crazyflie-f ... _drv.c#L60

If your sensor does not support 400KHz I2C you can change the code above to set the bus at 100KHz.

Duncan
Beginner
Posts: 9
Joined: Mon Aug 27, 2018 1:13 am

Re: EEPROM: I2C connection [FAIL]

Post by Duncan » Thu Sep 13, 2018 8:53 pm

One thing that could be happening is that the bus speed is configured too fast. It is currently configured at 400KHz: https://github.com/bitcraze/crazyflie-f ... _drv.c#L60

If your sensor does not support 400KHz I2C you can change the code above to set the bus at 100KHz.
Hi arnaud,
I change the bus at 100KHz but it still didn't work. And I check the signal through the oscilloscope and found there was no acknowledgment signal coming back from the I2C slave.
Image

I used the same slave connecting to Arduino and it worked normally.
Image

I guess it must be something wrong in my code but I couldn't figure out where it is.

Code: Select all

#include "deck.h"
#include "param.h"

#define DEBUG_MODULE "SCANNER"

#include "system.h"
#include "debug.h"
#include "log.h"
#include "i2cdev.h"
#include "FreeRTOS.h"
#include "task.h"
#include <stdlib.h>
static bool isInit = false;
static bool isTested = false;


typedef I2C_Dev *I2CX;  //pointer to the I2C peripheral
static uint8_t rssi_value;

static void scannerTask(void *param)
{
  systemWaitStart();

  TickType_t lastWakeTime = xTaskGetTickCount(); //get tick time count

  while(1) {
    vTaskDelayUntil(&lastWakeTime, M2T(50));   //delay some time get next data

    if(i2cdevReadByte(I2CX,0x74,I2CDEV_NO_MEM_ADDR,&rssi_value))
    {
    	DEBUG_PRINT("Data received.\n");
    	DEBUG_PRINT("rssi: %d.\n",rssi_value);
    }
  }
}

static void scannerInit()             //initialize the pins, every deck has these funtion
{
  if (isInit) {
    return;
  }
  I2CX=I2C1_DEV;
  i2cdevInit(I2CX);
  
  isInit = true;
//create a task thread which execute the detect task function
  xTaskCreate(scannerTask, "scanner", 2*configMINIMAL_STACK_SIZE, NULL,
              /*priority*/3, NULL);
}

static bool scannerTest()
{
  bool pass = isInit;

  if (isTested) {
    DEBUG_PRINT("Cannot test scanner deck a second time\n");
    return false;
  }
  DEBUG_PRINT("ScannerTest is good.\n");
  isTested = true;
  return pass;
}

static const DeckDriver scanner_deck = {
  .vid = 0,              //deck id address and name , new name to resolve conflict
  .pid = 0,
  .name = "blescanner",

  .usedGpio = 0,  // FIXME: set the used pins, future editing needed

  .init = scannerInit,
  .test = scannerTest,
};

DECK_DRIVER(scanner_deck);

Duncan
Beginner
Posts: 9
Joined: Mon Aug 27, 2018 1:13 am

Re: EEPROM: I2C connection [FAIL]

Post by Duncan » Thu Sep 13, 2018 8:58 pm

Here is the images of the ocsilloscope.

When my I2C sensor connecting to crazyflie:
Image


When my I2C sensor connecting to the arduino:
Image
Attachments
crazy+sparkfun.PNG
crazy+sparkfun.PNG (7.37 KiB) Viewed 108 times
arduino+sparkfun2.PNG
arduino+sparkfun2.PNG (7.29 KiB) Viewed 108 times

Duncan
Beginner
Posts: 9
Joined: Mon Aug 27, 2018 1:13 am

Re: EEPROM: I2C connection [FAIL]

Post by Duncan » Sat Sep 15, 2018 12:15 am

It turns out that my I2C sensor didn't respond to the "write" command. But I have set it to "I2CDEV_NOMEM_ADDR" and crazyflie should directly send read command instead of sending write command at first. Whatever, I fixed the sensor to make it be able to respond to the write command. After the write command is acknowledged, crazyflie finally started to send read command and my sensor responded to it. I can see the SDA channel actually had data flowing through. However, the "i2cdevreadbyte" function in the crazyflie still returned a "false" and no data was stored to the variable set to receiving the data.

Duncan
Beginner
Posts: 9
Joined: Mon Aug 27, 2018 1:13 am

Re: EEPROM: I2C connection [FAIL]

Post by Duncan » Thu Sep 20, 2018 6:54 pm

It turns out that except the built-in pull up resistors, an external 10k resistor is also needed for SDA and SCL. After adding the external pull-up resistors, the program works and I can get the data from my sensor.

Post Reply