Part Number: TM4C123GH6PM
Tool/software: TI-RTOS
Hi all,
I am new to TI-RTOS.
I'm using following configurations for my project
CCSv8.1.0 , TI-RTOS- 2.16.00.08, TIVA Ware: 2.1.4.178;xdc : 3.32.00.06Laptop OS: Windows 10
I have 4 Tasks in my system. In one of those tasks. I want to get IMU Sensor Data when ever a button is pressed. To acheive this I configured to post Semaphore when ever the button is pressed
Code snippets as follows:
/* Callback function for the GPIO interrupt on up Button.*/
void gpioButtonFxn1(unsigned int index)
{
Semaphore_post(IMUSem);
}
The Task implementation is as follows:
void get_imu()
{
// GPIO_toggle(Board_LED_BLUE);
I2C_Handle i2c;
I2C_Params i2cParams;
uint8_t pwr;
pwr = 0x00;
//Create I2C for usage
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(IMU_SENSOR, &i2cParams);
if (i2c == NULL)
{
System_abort("Error Initializing I2C\n");
}
else
{
System_printf("I2C Initialized!\n");
}
// Initialize the MPU6050
signal.writeRegister(i2c,0x6B, 0x80); // This line making the this Task to go into blocked state and other tasks to terminate state
signal.readRegister(i2c, 0x6B, &pwr, 1);
do {
signal.readRegister(i2c, 0x6B, &pwr, 1);
} while (pwr & 0x40 != 0x40);
// Use PLL with X axis gyroscope reference
signal.writeRegister(i2c,0x6B, 0x01);
// Enable I2C Master mode
signal.writeRegister(i2c,0x6A, 0x20);
// Set sample rate divider
signal.writeRegister(i2c,0x19, 0x13);
signal.writeRegister(i2c,0x67, 0x11);
GPIO_write(Board_LED_RED, Board_LED_OFF);
while(1)
{
Semaphore_pend(IMUSem, BIOS_WAIT_FOREVER);
while (GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_2) == GPIO_PIN_2);
signal.readRegister(i2c, 0x3B, (uint8_t *) &signal.imu.mpu6050, 14);
}
//Deinitialized I2C
I2C_close(i2c);
System_printf("I2C closed!\n");
System_flush();
}
My WriteRegister() as follows:
void writeRegister(I2C_Handle handle, uint16_t regAddr, uint16_t value)
{
uint8_t txBuffer[4];
I2C_Transaction i2cTransaction;
i2cTransaction.slaveAddress = MPU6050_I2C_ADDRESS;
//Write to a 16-bit status register
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 2;
i2cTransaction.readCount = 0;
txBuffer[0] = regAddr & 0xFF; //LB Addr
txBuffer[1] = value & 0xFF;
if (!I2C_transfer(handle, &i2cTransaction)) {
GPIO_write(Board_LED_RED, Board_LED_ON);
System_abort("Bad I2C transfer!");
}
}
and readRegister() as follows:
void readRegister(I2C_Handle handle,
uint16_t regAddr,
uint8_t *data,
size_t length)
{
uint8_t txBuffer[2];
I2C_Transaction i2cTransaction;
i2cTransaction.slaveAddress = MPU6050_I2C_ADDRESS;
//Write to a 16-bit status register
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.readBuf = data;
i2cTransaction.writeCount = 1;
i2cTransaction.readCount = length;
txBuffer[0] = regAddr & 0xFF; //LB Addr
if (!I2C_transfer(handle, &i2cTransaction)) {
GPIO_write(Board_LED_RED, Board_LED_ON);
System_abort("Bad I2C transfer!");
}
}
My .cfg file configuration for Imu task and semaphore as follows:
var task3Params = new Task.Params();
task3Params.instance.name = "imu";
task3Params.priority = 2;
Program.global.imu = Task.create("&get_imu", task3Params);
var semaphore0Params = new Semaphore.Params();
semaphore0Params.instance.name = "IMUSem";
Program.global.IMUSem = Semaphore.create(null, semaphore0Params);
Below is the screen shot of the ROV:
when debugger in main():

After the line in get_imu() task
signal.writeRegister(i2c,0x6B, 0x80);
Kindly some one help me in this.
Thanks in Advance.
Regards,
Yashwanth Gandeti.