josantoniojl wrote on Wednesday, February 20, 2019:
Hi,
I performed two tasks, one for obtaining values and the second for the control of servomotors, that works perfectly. The priority level of the i2c task is high while that of the motors is above normal.
However, I don’t know if they have a recommendation for you to perform better task management. I was thinking about using a semaphore but I’m not sure how to use it.
void I2Communication(void const * argument)
{
/* USER CODE BEGIN I2Communication */
/* Infinite loop */
for(;;)
{
HAL_I2C_Mem_Read (&hi2c1, SLAVEI2C_ADD,0x28, 1,(uint8_t *)OUT_X_L, 1, 100);
HAL_I2C_Mem_Read (&hi2c1, SLAVEI2C_ADD,0x29, 1,(uint8_t *)OUT_X_H, 1, 100);
HAL_I2C_Mem_Read (&hi2c1, SLAVEI2C_ADD,0x2A, 1,(uint8_t *)OUT_Y_L, 1, 100);
HAL_I2C_Mem_Read (&hi2c1, SLAVEI2C_ADD,0x2B, 1,(uint8_t *)OUT_Y_H, 1, 100);
HAL_I2C_Mem_Read (&hi2c1, SLAVEI2C_ADD,0x2C, 1,(uint8_t *)OUT_Z_L, 1, 100);
HAL_I2C_Mem_Read (&hi2c1, SLAVEI2C_ADD,0x2D, 1,(uint8_t *)OUT_Z_H, 1, 100); // Registre OUT_Z_H
x = ((OUT_X_H[0]<<8)|OUT_X_L[0]);
y = ((OUT_Y_H[0]<<8)|OUT_Y_L[0]);
z = ((OUT_Z_H[0]<<8)|OUT_Z_L[0]);
osDelay(500);
}
/* USER CODE END I2Communication */
}
void PWMControl(void const * argument)
{
/* USER CODE BEGIN PWMControl */
/* Infinite loop */
for(;;)
{
TIM2->CCR1=x;
TIM2->CCR2=y;
TIM2->CCR4=z;
osDelay(500);
}
/* USER CODE END PWMControl */
}