Optimize code
Hi, can you help me? I want to optimize execution time of my code: while (1) { // 1. Sending Measure Command buf[0] = AVG_COMMND; //Sensor register HAL_I2C_Master_Transmit(&hi2c1, DLHR_ADDR, buf, 1, 100); // write // 2. Status Read. Statusbuf[0] = AVG_COMMND; //Sensor register HAL_I2C_Master_Receive(&hi2c1, DLHR_ADDR, &Statusbuf[0], 1, 100); // Read //statusByte = Statusbuf[0]; //Read EOL status EOC_Status = 0; EOC_Status = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_10); if (EOC_Status == 1){ buf[0] = AVG_COMMND; //Sensor register ret = HAL_I2C_Master_Receive(&hi2c1, DLHR_ADDR, &buf[0], 7, 100); // Read // If there are data if ( ret == HAL_OK ) { //Combine the bytes for pressure. Combine 4 8-bit into a one 32-bit (but sensor just give a 24-bit) // buf data in hex. statusByte = (int16_t)buf[0] << 8; buf[0] = 0; Press = ((int16_t)buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | (buf[3]); //Scale this output offsetP = 8388608; Press_c = (((float)Press - offsetP)/16777216)*1.25; //Combine the bytes for temp. Combine 4 8-bit into a one 32-bit (but sensor just give a 24-bit) Temp = ((int16_t)buf[0] << 24) | (buf[4] << 16) | (buf[5] << 8) | (buf[6]); //Scale this output Temp_c = ((float)Temp*125/16777216)-40; // Turn on green led HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); } else{ buf[0] = 0xAD; //Sensor register //On error Press_c = 1000; Temp_c = 1000; } // // serial transmission: // char buffer[50] = {}; // sprintf(buffer, "Press: %f Temp: %f \n", Press_c, Temp_c); // HAL_UART_Transmit(&huart2, (uint8_t *)buffer, sizeof(buffer), 10); } else { //No EOC // Turn on green led HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET); } /* USER CODE END WHILE */ }