/** * @brief Read LSM303DLHC ID. * @param None * @retval ID */ uint8_t LSM303DLHC_AccReadID(void) { uint8_t ctrl = 0x00; /* Low level init */ COMPASSACCELERO_IO_Init(); /* Read value at Who am I register address */ ctrl = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_WHO_AM_I_ADDR); return ctrl; }
/** * @brief Set LSM303DLHC Initialization. * @param InitStruct: Init parameters * @retval None */ void LSM303DLHC_AccInit(uint16_t InitStruct) { uint8_t ctrl = 0x00; /* Low level init */ COMPASSACCELERO_IO_Init(); /* Write value to ACC MEMS CTRL_REG1 register */ ctrl = (uint8_t) InitStruct; COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG1_A, ctrl); /* Write value to ACC MEMS CTRL_REG4 register */ ctrl = (uint8_t) (InitStruct << 8); COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG4_A, ctrl); }
static void HW_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Init STM32F401 discovery LEDs */ BSP_LED_Init(LED3); BSP_LED_Init(LED4); BSP_LED_Init(LED5); BSP_LED_Init(LED6); /* Init SPI and I2C */ GYRO_IO_Init(); COMPASSACCELERO_IO_Init(); /* Init on-board AccelMag */ BSP_ACCELERO_Init(); /* Init BlueNRG CS, Reset, and IRQ pin */ BLUENRG_CS_GPIO_CLK_ENABLE(); GPIO_InitStruct.Pin = BLUENRG_CS_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; HAL_GPIO_Init(BLUENRG_CS_GPIO_PORT, &GPIO_InitStruct); HAL_GPIO_WritePin(BLUENRG_CS_GPIO_PORT, BLUENRG_CS_PIN, GPIO_PIN_SET); BLUENRG_RESET_GPIO_CLK_ENABLE(); GPIO_InitStruct.Pin = BLUENRG_RESET_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(BLUENRG_RESET_GPIO_PORT, &GPIO_InitStruct); BLUENRG_IRQ_GPIO_CLK_ENABLE(); GPIO_InitStruct.Pin = BLUENRG_IRQ_PIN; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(BLUENRG_IRQ_GPIO_PORT, &GPIO_InitStruct); #ifdef WITH_USART /* Init USART port */ UsartHandle.Instance = USART2; UsartHandle.Init.BaudRate = 9600; UsartHandle.Init.WordLength = USART_WORDLENGTH_8B; UsartHandle.Init.StopBits = USART_STOPBITS_1; UsartHandle.Init.Parity = USART_PARITY_NONE; UsartHandle.Init.Mode = USART_MODE_TX_RX; if (HAL_USART_Init(&UsartHandle) != HAL_OK) { ColorfulRingOfDeath(); } #endif #ifdef WITH_VCP /* Init Device Library */ USBD_Init(&hUSBDDevice, &VCP_Desc, 0); /* Add Supported Class */ USBD_RegisterClass(&hUSBDDevice, &USBD_CDC); /* Add CDC Interface Class */ USBD_CDC_RegisterInterface(&hUSBDDevice, &USBD_CDC_fops); /* Start Device Process */ USBD_Start(&hUSBDDevice); #endif }