Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.05 KB | None | 0 0
  1.  
  2. #include "main.h"
  3. #include "max30102.h"
  4.  
  5.  
  6. I2C_HandleTypeDef hi2c1;
  7.  
  8.  
  9. //OUR VARIABLES //
  10. uint32_t pun_red_led=0;
  11. uint32_t pun_ir_led=0;
  12. unsigned char uch_temp;
  13. uint8_t ach_i2c_data[6];
  14.  
  15.  
  16. void SystemClock_Config(void);
  17. static void MX_GPIO_Init(void);
  18. static void MX_I2C1_Init(void);
  19.  
  20. int main(void)
  21. {
  22.  
  23.   HAL_Init();
  24.   SystemClock_Config();
  25.   MX_GPIO_Init();
  26.   MX_I2C1_Init();
  27.  
  28.     maxim_max30102_reset(hi2c1);
  29.     HAL_Delay(1000);
  30.     maxim_max30102_read_reg(hi2c1, REG_INTR_STATUS_1, &uch_dummy);
  31.     maxim_max30102_init(hi2c1);
  32.  
  33.   while (1)
  34.   {
  35.  
  36.  
  37. // READING PROCESS START//
  38.  
  39. maxim_max30102_read_reg(hi2c1, REG_INTR_STATUS_1, &uch_temp);
  40. maxim_max30102_read_reg(hi2c1, REG_INTR_STATUS_2, &uch_temp);
  41.  
  42. ach_i2c_data[0]=REG_FIFO_DATA;
  43.  
  44. HAL_I2C_Mem_Read(&hi2c1, I2C_RD117_ADDR, REG_FIFO_DATA, I2C_MEMADD_SIZE_8BIT, &ach_i2c_data[0],6, 100);
  45.  
  46. un_temp=(uint8_t) ach_i2c_data[0];
  47.   un_temp<<=16;
  48.   pun_red_led+=un_temp;
  49.   un_temp=(uint8_t) ach_i2c_data[1];
  50.   un_temp<<=8;
  51.   pun_red_led+=un_temp;
  52.   un_temp=(uint8_t) ach_i2c_data[2];
  53.   pun_red_led+=un_temp;
  54.  
  55.   un_temp=(uint8_t) ach_i2c_data[3];
  56.   un_temp<<=16;
  57.   pun_ir_led+=un_temp;
  58.   un_temp=(uint8_t) ach_i2c_data[4];
  59.   un_temp<<=8;
  60.   pun_ir_led+=un_temp;
  61.   un_temp=(uint8_t) ach_i2c_data[5];
  62.   pun_ir_led+=un_temp;
  63.   pun_red_led&=0x03FFFF;  //Mask MSB [23:18]
  64.   pun_ir_led&=0x03FFFF;  //Mask MSB [23:18]
  65.  
  66.   // READING PROCESS END//
  67.   //TO TRANSMIT: pun_ir_led & pun_red_led
  68.  
  69.   // TRANSMIT TO UART //
  70.  
  71.   // END OF TRANSMIT TO UART //
  72.   HAL_Delay(100);
  73.  
  74.   }
  75.  
  76. }
  77.  
  78.  
  79. void SystemClock_Config(void)
  80. {
  81.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  82.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  83.  
  84.   __HAL_RCC_PWR_CLK_ENABLE();
  85.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  86.  
  87.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  88.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  89.   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  90.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  91.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  92.   RCC_OscInitStruct.PLL.PLLM = 8;
  93.   RCC_OscInitStruct.PLL.PLLN = 180;
  94.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  95.   RCC_OscInitStruct.PLL.PLLQ = 4;
  96.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  97.   {
  98.     Error_Handler();
  99.   }
  100.   /** Activate the Over-Drive mode
  101.   */
  102.   if (HAL_PWREx_EnableOverDrive() != HAL_OK)
  103.   {
  104.     Error_Handler();
  105.   }
  106.   /** Initializes the CPU, AHB and APB busses clocks
  107.   */
  108.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  109.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  110.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  111.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  112.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  113.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  114.  
  115.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  116.   {
  117.     Error_Handler();
  118.   }
  119. }
  120.  
  121.  
  122. static void MX_I2C1_Init(void)
  123. {
  124.  
  125.   hi2c1.Instance = I2C1;
  126.   hi2c1.Init.ClockSpeed = 100000;
  127.   hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
  128.   hi2c1.Init.OwnAddress1 = 0;
  129.   hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  130.   hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  131.   hi2c1.Init.OwnAddress2 = 0;
  132.   hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  133.   hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  134.   if (HAL_I2C_Init(&hi2c1) != HAL_OK)
  135.   {
  136.     Error_Handler();
  137.   }
  138.  
  139.   if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
  140.   {
  141.     Error_Handler();
  142.   }
  143.  
  144.   if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
  145.   {
  146.     Error_Handler();
  147.   }
  148.  
  149. }
  150.  
  151.  
  152. static void MX_GPIO_Init(void)
  153. {
  154.   GPIO_InitTypeDef GPIO_InitStruct = {0};
  155.  
  156.   /* GPIO Ports Clock Enable */
  157.   __HAL_RCC_GPIOC_CLK_ENABLE();
  158.   __HAL_RCC_GPIOH_CLK_ENABLE();
  159.   __HAL_RCC_GPIOA_CLK_ENABLE();
  160.   __HAL_RCC_GPIOB_CLK_ENABLE();
  161.   __HAL_RCC_GPIOD_CLK_ENABLE();
  162.   __HAL_RCC_GPIOG_CLK_ENABLE();
  163.  
  164.   /*Configure GPIO pin Output Level */
  165.   HAL_GPIO_WritePin(GPIOB, LD3_Pin|LD2_Pin, GPIO_PIN_RESET);
  166.  
  167.   /*Configure GPIO pin Output Level */
  168.   HAL_GPIO_WritePin(USB_PowerSwitchOn_GPIO_Port, USB_PowerSwitchOn_Pin, GPIO_PIN_RESET);
  169.  
  170.   /*Configure GPIO pin Output Level */
  171.   HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8|LD1_Pin, GPIO_PIN_RESET);
  172.  
  173.   /*Configure GPIO pin : USER_Btn_Pin */
  174.   GPIO_InitStruct.Pin = USER_Btn_Pin;
  175.   GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  176.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  177.   HAL_GPIO_Init(USER_Btn_GPIO_Port, &GPIO_InitStruct);
  178.  
  179.   /*Configure GPIO pins : RMII_MDC_Pin RMII_RXD0_Pin RMII_RXD1_Pin */
  180.   GPIO_InitStruct.Pin = RMII_MDC_Pin|RMII_RXD0_Pin|RMII_RXD1_Pin;
  181.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  182.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  183.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  184.   GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
  185.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  186.  
  187.   /*Configure GPIO pins : RMII_REF_CLK_Pin RMII_MDIO_Pin RMII_CRS_DV_Pin */
  188.   GPIO_InitStruct.Pin = RMII_REF_CLK_Pin|RMII_MDIO_Pin|RMII_CRS_DV_Pin;
  189.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  190.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  191.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  192.   GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
  193.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  194.  
  195.   /*Configure GPIO pin : RMII_TXD1_Pin */
  196.   GPIO_InitStruct.Pin = RMII_TXD1_Pin;
  197.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  198.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  199.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  200.   GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
  201.   HAL_GPIO_Init(RMII_TXD1_GPIO_Port, &GPIO_InitStruct);
  202.  
  203.   /*Configure GPIO pins : LD3_Pin LD2_Pin */
  204.   GPIO_InitStruct.Pin = LD3_Pin|LD2_Pin;
  205.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  206.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  207.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  208.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  209.  
  210.   /*Configure GPIO pins : STLK_RX_Pin STLK_TX_Pin */
  211.   GPIO_InitStruct.Pin = STLK_RX_Pin|STLK_TX_Pin;
  212.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  213.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  214.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  215.   GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
  216.   HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  217.  
  218.   /*Configure GPIO pin : USB_PowerSwitchOn_Pin */
  219.   GPIO_InitStruct.Pin = USB_PowerSwitchOn_Pin;
  220.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  221.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  222.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  223.   HAL_GPIO_Init(USB_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);
  224.  
  225.   /*Configure GPIO pin : USB_OverCurrent_Pin */
  226.   GPIO_InitStruct.Pin = USB_OverCurrent_Pin;
  227.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  228.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  229.   HAL_GPIO_Init(USB_OverCurrent_GPIO_Port, &GPIO_InitStruct);
  230.  
  231.   /*Configure GPIO pins : PC8 LD1_Pin */
  232.   GPIO_InitStruct.Pin = GPIO_PIN_8|LD1_Pin;
  233.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  234.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  235.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  236.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  237.  
  238.   /*Configure GPIO pins : USB_SOF_Pin USB_ID_Pin USB_DM_Pin USB_DP_Pin */
  239.   GPIO_InitStruct.Pin = USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin;
  240.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  241.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  242.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  243.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  244.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  245.  
  246.   /*Configure GPIO pin : USB_VBUS_Pin */
  247.   GPIO_InitStruct.Pin = USB_VBUS_Pin;
  248.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  249.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  250.   HAL_GPIO_Init(USB_VBUS_GPIO_Port, &GPIO_InitStruct);
  251.  
  252.   /*Configure GPIO pins : RMII_TX_EN_Pin RMII_TXD0_Pin */
  253.   GPIO_InitStruct.Pin = RMII_TX_EN_Pin|RMII_TXD0_Pin;
  254.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  255.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  256.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  257.   GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
  258.   HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  259.  
  260. }
  261.  
  262.  
  263. void Error_Handler(void)
  264. {
  265.  
  266. }
  267.  
  268. #ifdef  USE_FULL_ASSERT
  269.  
  270. void assert_failed(uint8_t *file, uint32_t line)
  271. {
  272.  
  273. }
  274. #endif /* USE_FULL_ASSERT */
  275.  
  276. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement