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.
I used the same slave connecting to Arduino and it worked normally.
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);