+tested IMU, +tested PCA9685, fail to work together
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
set(KPI_Rover_Arbiter_I2C_Inc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
set(KPI_Rover_Arbiter_I2C_Src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hwI2C.c
|
||||
)
|
||||
|
||||
add_library(KPI_Rover_Arbiter_I2C STATIC)
|
||||
|
||||
target_include_directories(KPI_Rover_Arbiter_I2C PRIVATE
|
||||
${KPI_Rover_Arbiter_I2C_Inc}
|
||||
)
|
||||
|
||||
target_sources(KPI_Rover_Arbiter_I2C PRIVATE
|
||||
${KPI_Rover_Arbiter_I2C_Src}
|
||||
)
|
||||
|
||||
target_link_libraries(KPI_Rover_Arbiter_I2C PRIVATE
|
||||
HAL_H
|
||||
)
|
||||
|
||||
add_library(KPI_Rover_Arbiter_I2C_H INTERFACE)
|
||||
target_include_directories(KPI_Rover_Arbiter_I2C_H INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
@@ -0,0 +1,81 @@
|
||||
#include "main.h"
|
||||
|
||||
extern I2C_HandleTypeDef hi2c1;
|
||||
extern I2C_HandleTypeDef hi2c2;
|
||||
|
||||
void HW_I2C1_Init(void)
|
||||
{
|
||||
hi2c1.Instance = I2C1;
|
||||
hi2c1.Init.ClockSpeed = 100000;
|
||||
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
hi2c1.Init.OwnAddress1 = 0;
|
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c1.Init.OwnAddress2 = 0;
|
||||
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
void HW_I2C2_Init(void)
|
||||
{
|
||||
hi2c2.Instance = I2C2;
|
||||
hi2c2.Init.ClockSpeed = 100000;
|
||||
hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
hi2c2.Init.OwnAddress1 = 0;
|
||||
hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c2.Init.OwnAddress2 = 0;
|
||||
hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
if (HAL_I2C_Init(&hi2c2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if (i2cHandle->Instance == I2C1)
|
||||
{
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
}
|
||||
else if (i2cHandle->Instance == I2C2)
|
||||
{
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF4_I2C2;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
__HAL_RCC_I2C2_CLK_ENABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle)
|
||||
{
|
||||
if (i2cHandle->Instance == I2C1)
|
||||
{
|
||||
__HAL_RCC_I2C1_CLK_DISABLE();
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6);
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
|
||||
}
|
||||
else if (i2cHandle->Instance == I2C2)
|
||||
{
|
||||
__HAL_RCC_I2C2_CLK_DISABLE();
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10);
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_11);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "main.h"
|
||||
|
||||
extern I2C_HandleTypeDef hi2c1;
|
||||
extern I2C_HandleTypeDef hi2c2;
|
||||
|
||||
void HW_I2C1_Init(void);
|
||||
void HW_I2C2_Init(void);
|
||||
void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle);
|
||||
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle);
|
||||
Reference in New Issue
Block a user