Adding I2C interrupt

This commit is contained in:
Pcornat 2025-02-13 13:19:19 +01:00
parent ee42fc0bbc
commit 40edb62e44
Signed by: Pcornat
GPG key ID: E0326CC678A00BDD
7 changed files with 49 additions and 12 deletions

View file

@ -54,6 +54,8 @@ static void MX_GPIO_Init(void);
static void MX_I2C1_Init(void);
static void MX_NVIC_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
@ -134,6 +136,7 @@ int main(void) {
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C1_Init();
MX_NVIC_Init();
/* USER CODE BEGIN 2 */
// TODO: configs
configure_sensor(); {
@ -158,6 +161,7 @@ int main(void) {
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void) {
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
@ -195,6 +199,15 @@ void SystemClock_Config(void) {
}
}
/**
* @brief NVIC Configuration.
*/
static void MX_NVIC_Init(void) {
/* I2C1_EV_IRQn interrupt configuration */
HAL_NVIC_SetPriority(I2C1_EV_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(I2C1_EV_IRQn);
}
/**
* @brief I2C1 Initialization Function
*/

View file

@ -109,7 +109,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
*/
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
@ -148,6 +148,8 @@ void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_9);
/* I2C1 interrupt DeInit */
HAL_NVIC_DisableIRQ(I2C1_EV_IRQn);
/* USER CODE BEGIN I2C1_MspDeInit 1 */
/* USER CODE END I2C1_MspDeInit 1 */

View file

@ -55,7 +55,7 @@
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
extern I2C_HandleTypeDef hi2c1;
/* USER CODE BEGIN EV */
/* USER CODE END EV */
@ -198,6 +198,20 @@ void SysTick_Handler(void)
/* please refer to the startup file (startup_stm32l4xx.s). */
/******************************************************************************/
/**
* @brief This function handles I2C1 event interrupt.
*/
void I2C1_EV_IRQHandler(void)
{
/* USER CODE BEGIN I2C1_EV_IRQn 0 */
/* USER CODE END I2C1_EV_IRQn 0 */
HAL_I2C_EV_IRQHandler(&hi2c1);
/* USER CODE BEGIN I2C1_EV_IRQn 1 */
/* USER CODE END I2C1_EV_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */