Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint8_t data_x_l;
- uint8_t data_x_h;
- uint8_t data_y_l;
- uint8_t data_y_h;
- uint8_t data_z_l;
- uint8_t data_z_h;
- /* USER CODE END 0 */
- /**
- * @brief The application entry point.
- *
- * @retval None
- */
- int main(void)
- {
- /* USER CODE BEGIN 1 */
- /* USER CODE END 1 */
- /* MCU Configuration----------------------------------------------------------*/
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
- HAL_Init();
- /* USER CODE BEGIN Init */
- /* USER CODE END Init */
- /* Configure the system clock */
- SystemClock_Config();
- /* USER CODE BEGIN SysInit */
- /* USER CODE END SysInit */
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_I2C1_Init();
- MX_SPI1_Init();
- MX_USB_DEVICE_Init();
- /* USER CODE BEGIN 2 */
- __HAL_I2C_ENABLE(&hi2c1);
- HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_SET); // CS postavimo na 1
- initPospeskometer();
- /* USER CODE END 2 */
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- HAL_Delay(1000);
- beriRegistre(0x19, 0x28,(uint8_t*)&meritev, 6);
- for(int i = 0; i < (sizeof(meritev)/sizeof(meritev[0])); i++){
- meritev[i] *= -1;
- }
- HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x28, 1, &data_x_l, 1, 100);
- HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x29, 1, &data_x_h, 1, 100);
- HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x2A, 1, &data_y_l, 1, 100);
- HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x2B, 1, &data_y_h, 1, 100);
- HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x2C, 1, &data_z_l, 1, 100);
- HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x2D, 1, &data_z_h, 1, 100);
- accelerometer[0] = (9.81) * (4.0 / 65536) * (int16_t)((data_x_h << 8) | data_x_l);
- accelerometer[1] = (9.81) * (4.0 / 65536) * (int16_t)((data_y_h << 8) | data_y_l);
- accelerometer[2] = (9.81) * (4.0 / 65536) * (int16_t)((data_z_h << 8) | data_z_l);
- CDC_Transmit_FS((uint8_t*)&accelerometer, 12);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement