I need to make connection between two STM32 Nucleo 64 via I2C. I followed an example in STM32Cube\Repository\....\I2C_TwoBoards_ComDMA I configurbased on this example and connected SDA, SCL but nothing is transferred. I am cant solve the problem.
I configure the I2C as follows:
hi2c1.Instance = I2C1;
hi2c1.Init.ClockSpeed = 100000;
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
hi2c1.Init.OwnAddress1 = I2C_ADDRESS;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0xFF;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
where
#define I2C_ADDRESS 0x30F
In master, I used this code snippet from
while(HAL_I2C_Master_Transmit_DMA(&hi2c1, (uint16_t)I2C_ADDRESS, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK)
{
if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
{ Error_Handler(); }
}
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY)
{
}
This is in the main while loop.
In the slave which is the receiver, I use this to receive via I2C and send it to PC via USART:
while(HAL_I2C_Master_Receive_DMA(&hi2c1, (uint16_t)I2C_ADDRESS, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
{
if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
{Error_Handler();}
}
HAL_UART_Transmit(&huart2, aRxBuffer, RXBUFFERSIZE, 10);
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY)
{
}
Using CubeMx I enabled I2c1 where pins PB6 and PB7 were enabled as SDA and SCL and I connected them between two boards as well as GND. after programming and reset, I get nothing in tera tem suggesting nothing is transferred. I am not able to diagnose the problem.
Is configuration for master and slave different?
Thanks