This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640R2F: No output at LSM303AGR Sensor Controller Code.

Part Number: CC2640R2F

Hi,

    I am using a 4x4mm CC2640R2F Custom Board with a LSM303AGR Acceleromter+Magnetometer I2C Sensor. Using Simple Peripheral Stack Library example program I have read the LSM303AGR Accelerometer + Magnetometer using RTOS. I am trying to do the same using Sensor Controller. At Sensor Controller I able to read the correct value of LSM303AGR Who Am I register, so meaning my I2C communication is okay. The problem is at Sensor Controller when I read the Accelerometer X, Y, Z registers there is no output. Here is my code below.

Initialization:

// Schedule the first execution
fwScheduleTask(1);

Execution Code:

// Enable the LSM303AGR Sensor
gpioSetOutput(AUXIO_O_LSM303AGR_EN);
// 30 MS delay to make sure LSM303AGR is powered on.
fwDelayUs(30000, FW_DELAY_RANGE_100_MS);

i2cStart();

i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_WRITE);
i2cTx(LSM303AGR_WHO_AM_I_A);     // ID register
    
if (state.i2cStatus == 0x0000) {
    i2cRepeatedStart();
    i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_READ);
    i2cRxAck(output.whoami);    
    i2cStop();
}

i2cStart();
// Set LSM303AGR Accelerometer I2C Slave Address
i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_WRITE);
// Output registers not updated until MSB and LSB are read
// Full scale +/- 2g
i2cTx(LSM303AGR_CTRL_REG4_A);     
//i2cTx(0x80);
i2cTx(0x00);
i2cStop();

i2cStart();
// Set LSM303AGR Accelerometer I2C Slave Address
i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_WRITE);
// Set FIFO Bypass Mode
i2cTx(LSM303AGR_FIFO_CTRL_REG_A); 
i2cTx(0x00);
i2cStop();

i2cStart();
// Set LSM303AGR Accelerometer I2C Slave Address
i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_WRITE);
// Initialize the LSM303AGR Accelerometer
// X, Y and Z-axis enable, power on mode, o/p data rate 10 Hz(0x57)
i2cTx(LSM303AGR_CTRL_REG1_A);     
i2cTx(0x27);
i2cStop();

// Sleep 120 miliseconds then start event
evhSetupTimer1Trigger(0, 120, 2);

// Schedule the next execution
fwScheduleTask(1);

Event Handler A Code:

// If a measurement was successfully started during the last execution ...
if (state.i2cStatus == 0x0000) {
    
    output.whoami = 0xFFFF;
    // Select the result register
    i2cStart();
    i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_WRITE);
    i2cTx(LSM303AGR_WHO_AM_I_A);     // ID register
    
    if (state.i2cStatus == 0x0000) {
        i2cRepeatedStart();
        i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_READ);
        i2cRxAck(output.whoami);
    }
    i2cStop();
    
    
    if (state.i2cStatus == 0x0000) {// Read the result
        
        i2cStart();
        // Set LSM303AGR Accelerometer I2C Slave Address
        // Read the Accelerometer X Low
        i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_WRITE);
        i2cTx(LSM303AGR_OUT_X_L_A);    
    
         // If successful ...
        if (state.i2cStatus == 0x0000) {// Read the result
            i2cRepeatedStart();
            i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_READ);
            i2cRxAck(output.accbuffer[0]); 
           
        }
        i2cStop();
           
        i2cStart();
        // Set LSM303AGR Accelerometer I2C Slave Address
        // Read the Accelerometer X Low
        i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_WRITE);
        i2cTx(LSM303AGR_OUT_X_H_A);    
    
         // If successful ...
        if (state.i2cStatus == 0x0000) {// Read the result
            i2cRepeatedStart();
            i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_READ);
            i2cRxAck(output.accbuffer[1]); 
           
        }
        i2cStop();  
         
        i2cStart();
        // Set LSM303AGR Accelerometer I2C Slave Address
        // Read the Accelerometer Y Low
        i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_WRITE);
        i2cTx(LSM303AGR_OUT_Y_L_A);    
    
         // If successful ...
        if (state.i2cStatus == 0x0000) {// Read the result
            i2cRepeatedStart();
            i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_READ);
            i2cRxAck(output.accbuffer[2]); 
           
        }
        i2cStop();
           
        i2cStart();
        // Set LSM303AGR Accelerometer I2C Slave Address
        // Read the Accelerometer Y Low
        i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_WRITE);
        i2cTx(LSM303AGR_OUT_Y_H_A);    
    
         // If successful ...
        if (state.i2cStatus == 0x0000) {// Read the result
            i2cRepeatedStart();
            i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_READ);
            i2cRxAck(output.accbuffer[3]); 
           
        }
        i2cStop();   
        
        i2cStart();
        // Set LSM303AGR Accelerometer I2C Slave Address
        // Read the Accelerometer Z Low
        i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_WRITE);
        i2cTx(LSM303AGR_OUT_Z_L_A);    
    
         // If successful ...
        if (state.i2cStatus == 0x0000) {// Read the result
            i2cRepeatedStart();
            i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_READ);
            i2cRxAck(output.accbuffer[4]); 
           
        }
        i2cStop();
           
        i2cStart();
        // Set LSM303AGR Accelerometer I2C Slave Address
        // Read the Accelerometer Z Low
        i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_WRITE);
        i2cTx(LSM303AGR_OUT_Z_H_A);    
    
         // If successful ...
        if (state.i2cStatus == 0x0000) {// Read the result
            i2cRepeatedStart();
            i2cTx((LSM303AGR_ACC_I2C_ADDRESS << 1) | I2C_OP_READ);
            i2cRxAck(output.accbuffer[5]); 
           
        }
        i2cStop();  
         
        output.accX = ((output.accbuffer[1] << 8) | output.accbuffer[0]);
        output.accY = ((output.accbuffer[3] << 8) | output.accbuffer[2]);
        output.accZ = ((output.accbuffer[5] << 8) | output.accbuffer[4]);
    }
           
    fwGenAlertInterrupt();  
      
    fwScheduleTask(1);
  
} else {
    i2cStop();
    
}    
    

Termination Code:

// Cancel the potentially active event trigger
evhCancelTrigger(0);
gpioClearOutput(AUXIO_O_LSM303AGR_EN);

-kel