Part Number:LAUNCHXL-CC2640R2
Tool/software: TI-RTOS
Hi,
I have a project that was customized by blestack/simple_pheripheral project. Then I need to add Off_Chip OAD Property to that project. To do that, I want to customize blestack/oad_off_chip and I ported my code to that example. In my original code, I used additional thread so I tried to add a thread to that example but somehow I cannot do that (I created another issue about that and its process in progress).
Because of that, I changed my code structure to remove the additional thread and I created a clock. In that clock callback, I tried to read my I2C sensors periodically but I could not.
When I try to read the sensors in "SimplePeripheral_processCharValueChangeEvt" function for example (I used to start my additional thread via BLE command in my old code) for just one time, it works. But, when I tried to read sensors in timer callback function it does not. But timer works because I toggled a led in the callback function.
Here is a code example that explains what I mean;
static void DD_SystemGeneralTimerHandle(UArg arg)
{
#ifdef OLD_STYLE_CODE
GPIO_toggle(Board_GPIO_LED0);
#else
GPIO_toggle(Board_GPIO_LED1);
uint8_t txBuffer[1];
uint8_t rxBuffer[6];
I2C_Transaction i2cTransaction;
txBuffer[0] = WHO_AM_I_REG;
i2cTransaction.slaveAddress = SENSOR_ADDRESS;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 6;
I2C_transfer((*i2c), &i2cTransaction); //there is no stucking, it just cannot read, it return false
#endif
}
static void SimplePeripheral_processCharValueChangeEvt(uint8_t paramID)
{
switch(paramID)
{
case CUSTOM_PROFILE_CHAR1: //Working mode characteristic
SimpleProfile_GetParameter(CUSTOM_PROFILE_CHAR1, Characteristic_1_Run_Time_Read_Value);
if(Characteristic_1_Run_Time_Read_Value[0] == 0xBA) //start sensor reading here for example
{
#ifdef OLD_STYLE_CODE //I used to start additional thread here before
myThread_create();
#else //there is no error in here
GPIO_init();
I2C_init();
SPI_init();
/* Create I2C for usage */
I2C_Params_init(&glb_i2cParams); //glb_i2cParams this is global static variable
glb_i2cParams.bitRate = I2C_400kHz;
glb_i2c = I2C_open(Board_I2C_TMP, &glb_i2cParams); //glb_i2c this is global static variable
if (glb_i2c == NULL)
{
vErrorStateUpdte((uint32_t) __LINE__, (char *)__func__);
while(1){}
}
/////////////////This part is used for I2C sensor search in I2C bus
int ii = 0;
uint8_t rxBuffer[0];
uint8_t txBuffer[0];
I2C_Transaction i2cTransaction;
for(ii=0; ii<256; ii++)
{
rxBuffer[0] = 0;
uint8_t AG_ADDRESS = ii;
txBuffer[0] = WHO_AM_I_XG;
i2cTransaction.slaveAddress = AG_ADDRESS;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 1;
if (I2C_transfer(glb_i2c, &i2cTransaction))
{
if((ii == LSM9DS1_AG_ADDR_FIRST) || (ii == LSM9DS1_M_ADDR_FIRST))
{
glb_sensorExist = true;
break;
}
}
usleep(50000);
}
//////////////////////end of I2C sensor search process
//set up timer here
//clock init, reference link is: coecsl.ece.illinois.edu/.../SYSBIOS_usersguide.pdf
Clock_Params clockParams;
Clock_Handle myClock;
Error_Block eb;
Error_init(&eb);
Clock_Params_init(&clockParams);
clockParams.period = DD_SYSTEM_GENERAL_TIMER_PERIOD;
clockParams.startFlag = TRUE;
clockParams.arg = (UArg)DD_TIMER_ARG;
myClock = Clock_create(DD_SystemGeneralTimerHandle, DD_CLOCK_TIMEOUT, &clockParams, &eb); //one sensor reading sequence takes 15ms approximately. I arranged my timer for bigger than 200ms
if (myClock == NULL)
{
vErrorStateUpdte((uint32_t) __LINE__, (char *)__func__);
while(1){}
}
#endif
}
}
My SDK ver: 3.10.0.15
My ccs ver: 8.3.0.00009
Thanks,
Dogus