工具/软件:TI-RTOS
大家好、
我不熟悉 TI-RTOS。
我将为项目使用以下配置
CCSv8.1.0、TI-RTOS-2.16.00.08、Tiva Ware:2.1.4.178;XDC:3.32.00.06Laptop OS:Windows 10
我的系统中有4个任务。 执行其中一项任务。 我希望在按下按钮时获取 IMU 传感器数据。 为了实现这一点、我配置为在按下按钮时发布信标
代码片段如下所示:
//
向上按钮上 GPIO 中断的回调函数。*/ void gpioButtonFxn1 (无符号 int 索引)
{
semaphore_post (IMUSem);
}
任务执行如下:
void get_IMU ()
{
// GPIO_toggle (Board_LED_blue);
I2C_Handle i2c;
I2C_Params i2cParams;
uint8_t pwr;
pwr = 0x00;
//创建 I2C 以供使用
I2C_Params_init (&i2cParams);
i2cParams.bitrate = I2C_400kHz;
i2c = I2C_open (IMU_sensor、&i2cParams);
if (i2c =
2c){System_abort (" Error Initializing I2C_n");否则}{System_open (IMU_sensor、&i2cParams);if (0x2c = 0x2C 初始化0x60b)、0x60f (0x60b)! //此行使该任务进入被阻止状态,并执行其他任务以终止状态
SIGNAL。readRegister (i2c、0x6B、&pwr、1);
执行{
SIGNAL。readRegister (i2c、 0x6B、&pwr、1);
}while (pwr & 0x40!= 0x40);
//将 PLL 与 X 轴陀螺仪参考
信号配合使用。writeRegister (i2c、0x6B、0x01);
//启用 I2C 主模式
信号.writeRegister (i2c、0x6A、0x20);
//设置采样率分频
器信号。0x2c、0x13
、iLED、0x13、writeRegister (i2c、0x13、0x13);iwriteRegister 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 ();
}
我的 WriteRegister()如下所示:
void writeRegister (I2C_Handle handle、uint16_t regAddr、uint16_t value)
{
uint8_t txBuffer[4];
I2C_Transaction i2c 交易;
i2cTransaction.slaveAddress = MPU6050_I2C_address;
//写入16位状态寄存器
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 2;
i2cTransaction.ReadCount = 0;
txBuffer[0]= regAddr & 0xFF;//LB Addr
TxBuffer[1]=值和0xFF;
if (!I2C_transfer (handle、&i2cTransaction)){
GPIO_WRITE (Board_LED_RED、Board_LED_ON);
system_abort (" I2C 传输错误!");
}
}
和 readRegister()如下所示:
空 readRegister (I2C_Handle handle、
uint16_t regAddr、
uint8_t *数据、
size_t length)
{
uint8_t txBuffer[2];
I2C_Transaction i2c 交易;
i2cTransaction.slaveAddress = MPU6050_I2C_address;
//写入16位状态寄存器
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.readBuf =数据;
i2cTransaction.writeCount = 1;
i2cTransaction.ReadCount =长度;
txBuffer[0]= regAddr & 0xFF;//LB Addr
if (!I2C_transfer (handle、&i2cTransaction)){
GPIO_WRITE (Board_LED_RED、Board_LED_ON);
system_abort (" I2C 传输错误!");
}
}
针对 IMU 任务和信号量的.cfg 文件配置如下:
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 (空、Semaphore0Params);
下面是 ROV 的屏幕截图:
当在 main()中使用调试器时:

在 get_IMU()任务中的行之后
signal.writeRegister (i2c、0x6B、0x80);
在此过程中、有人帮我解决了。
提前感谢。
此致、
Yashwanth Gandeti。