cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Amera.11
Associate

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

2 REPLIES 2
KnarfB
Principal III

Yes, master and slave are different, see I2C_TwoBoards_ComDMA\Src\main.c

#ifdef MASTER_BOARD 
  // code for master is here
#else
  // code for slave is here
#endif /* MASTER_BOARD */

You are supposed to build the project twice, once for the master board (#define MASTER_BOARD) and once for slave (without #define MASTER_BOARD). Try to get the code running first with as little changes as possible.

Amera.11
Associate

Many thanks for your reply. yes I followed that example in this path

C:\Users\<…username…>\STM32Cube\Repository\STM32Cube_FW_F7_V1.15.0\Projects\STM32746G-Discovery\Examples\I2C\I2C_TwoBoards_ComDMA

and used the #ifdef #else.. #endif

but in that example only reading and writing is different for master and slave and the configuration is outside #ifdef and therefore is the same for both:

I2cHandle.Instance       = I2Cx;

 I2cHandle.Init.Timing      = I2C_TIMING;

 I2cHandle.Init.AddressingMode  = I2C_ADDRESSINGMODE_10BIT;

 I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;

 I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;

 I2cHandle.Init.NoStretchMode  = I2C_NOSTRETCH_DISABLE;  

 I2cHandle.Init.OwnAddress1   = I2C_ADDRESS;

 I2cHandle.Init.OwnAddress2   = 0xFF;

So how the configuration of I2cHanle should be different between slave and master?

Thanks