主要目的是想從i2c1(pb6,7)發送一組字串,讓i2c2(pb10,11)接收一組從i2c1發送的訊息
但不清楚為什麼debug mode 總會死在
/*receive an amount of data in slave mode*/
if(HAL_I2C_Slave_Receive_IT(&hi2c2,(uint8_t*)slave_buffer_rx,MASTER_TX_SIZE)!=HAL_OK)
{
if(HAL_I2C_GetError(&hi2c2)!=HAL_I2C_ERROR_AF)
{
Error_Handler();
}
}
還請大大幫忙 謝謝平台
完整的:
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f4xx_hal.h"
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C1_Init();
MX_I2C2_Init();
/* USER CODE BEGIN 2 */
/*waithing for blue button on board*/
while(HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_13)!=GPIO_PIN_RESET)
{
}
/*transmit an amount of data in master mode*/
if(HAL_I2C_Master_Transmit_IT(&hi2c1,(uint16_t)I2C_ADDRESS,(uint8_t*)master_buffer_tx,MASTER_TX_SIZE)!=HAL_OK)
{
if(HAL_I2C_GetError(&hi2c1)!=HAL_I2C_ERROR_AF)
{
Error_Handler();
}
}
/*receive an amount of data in slave mode*/
if(HAL_I2C_Slave_Receive_IT(&hi2c2,(uint8_t*)slave_buffer_rx,MASTER_TX_SIZE)!=HAL_OK)
{
if(HAL_I2C_GetError(&hi2c2)!=HAL_I2C_ERROR_AF)
{
Error_Handler();
}
}
}
/*transmit an amount data in slave mode*/
if(HAL_I2C_Slave_Transmit_IT(&hi2c2,(uint8_t*)slave_buffer_rx,SLAVE_TX_SIZE)!=HAL_OK)
{
if(HAL_I2C_GetError(&hi2c2)!=HAL_I2C_ERROR_AF)
{
Error_Handler();
}
}
/*receive an amount of data in master mode*/
if(HAL_I2C_Master_Receive_IT(&hi2c1,(uint16_t)I2C_ADDRESS,(uint8_t*)master_buffer_rx,SLAVE_TX_SIZE)!=HAL_OK)
{
if(HAL_I2C_GetError(&hi2c1)!=HAL_I2C_ERROR_AF)
{
Error_Handler();
}
}
while(HAL_I2C_GetState(&hi2c1)!=HAL_I2C_STATE_READY)
{
}
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
HAL_Delay(500);
}
/* USER CODE END 3 */
}
/** System Clock Configuration
*/
void SystemClock_Config(void)
{
/**
* @brief This function is executed in case of error occurrence.
* @param None
* @retval None
*/
void _Error_Handler(char * file, int line)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
while(1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/