2021-06-16 10:25 AM
Hi,
i'm trying to send data from an stm32f446-nucleo board ( as a master ) to an stm32f469-disco board ( as a slave ) but it is not working correctly,
PS: Each board is connected separately to a USB Port from PC.
MASTER Code :
int main(void)
{
SystemClock_Config();
MX_GPIO_Init();
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
do
{
for(i=0; i <255; i++)
{
ret = HAL_I2C_Master_Transmit(&hi2c1, i, data, 1, HAL_MAX_DELAY);
}
}while(ret!=HAL_OK);
while (1)
{
}
}
static void MX_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();
}
}
SLAVE Code :
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
do
{
ret = HAL_I2C_Slave_Receive(&hi2c1, data_r, 1, 10000);
}
while(ret!=HAL_OK);
while (1)
{
}
}
static void MX_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();
}
}
THE REST IS AUTOMATICALLY GENERATED FROM CUBEMX
When debugging I get thoses results :
Master.jpg & slave.jpg
Solved! Go to Solution.
2021-06-18 03:49 AM
Hello @Malek Mahar ,
Referring to what I suggested already in your other post, I prefer that you start with a ready to use example from the STM32CubeF4 firmware package.
You have following examples:
Try with these examples in order to understand how it works then move to your own project generated with STM32CubeMX.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2021-06-18 03:49 AM
Hello @Malek Mahar ,
Referring to what I suggested already in your other post, I prefer that you start with a ready to use example from the STM32CubeF4 firmware package.
You have following examples:
Try with these examples in order to understand how it works then move to your own project generated with STM32CubeMX.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2021-06-19 02:54 AM
Hello @Amel NASRI,
Thank you for your answer,
I had a wiring error concerning SCL & SDA pins on the slave board that I have corrected and it worked perfectly.
2021-06-21 02:31 AM
Hi @Malek Mahar ,
Glad to know that you found the root cause of your issue!
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.