Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. uint8_t data_x_l;
  2. uint8_t data_x_h;
  3. uint8_t data_y_l;
  4. uint8_t data_y_h;
  5. uint8_t data_z_l;
  6. uint8_t data_z_h;
  7. /* USER CODE END 0 */
  8.  
  9. /**
  10. * @brief The application entry point.
  11. *
  12. * @retval None
  13. */
  14. int main(void)
  15. {
  16. /* USER CODE BEGIN 1 */
  17.  
  18. /* USER CODE END 1 */
  19.  
  20. /* MCU Configuration----------------------------------------------------------*/
  21.  
  22. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  23. HAL_Init();
  24.  
  25. /* USER CODE BEGIN Init */
  26.  
  27. /* USER CODE END Init */
  28.  
  29. /* Configure the system clock */
  30. SystemClock_Config();
  31.  
  32. /* USER CODE BEGIN SysInit */
  33.  
  34. /* USER CODE END SysInit */
  35.  
  36. /* Initialize all configured peripherals */
  37. MX_GPIO_Init();
  38. MX_I2C1_Init();
  39. MX_SPI1_Init();
  40. MX_USB_DEVICE_Init();
  41. /* USER CODE BEGIN 2 */
  42.  
  43. __HAL_I2C_ENABLE(&hi2c1);
  44. HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_SET); // CS postavimo na 1
  45. initPospeskometer();
  46. /* USER CODE END 2 */
  47.  
  48. /* Infinite loop */
  49. /* USER CODE BEGIN WHILE */
  50. while (1)
  51. {
  52. HAL_Delay(1000);
  53. beriRegistre(0x19, 0x28,(uint8_t*)&meritev, 6);
  54.  
  55. for(int i = 0; i < (sizeof(meritev)/sizeof(meritev[0])); i++){
  56. meritev[i] *= -1;
  57. }
  58.  
  59. HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x28, 1, &data_x_l, 1, 100);
  60. HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x29, 1, &data_x_h, 1, 100);
  61. HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x2A, 1, &data_y_l, 1, 100);
  62. HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x2B, 1, &data_y_h, 1, 100);
  63. HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x2C, 1, &data_z_l, 1, 100);
  64. HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x2D, 1, &data_z_h, 1, 100);
  65.  
  66. accelerometer[0] = (9.81) * (4.0 / 65536) * (int16_t)((data_x_h << 8) | data_x_l);
  67. accelerometer[1] = (9.81) * (4.0 / 65536) * (int16_t)((data_y_h << 8) | data_y_l);
  68. accelerometer[2] = (9.81) * (4.0 / 65536) * (int16_t)((data_z_h << 8) | data_z_l);
  69.  
  70. CDC_Transmit_FS((uint8_t*)&accelerometer, 12);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement