cancel
Showing results for 
Search instead for 
Did you mean: 

I2C comunication doesn't work

DannyB
Associate II

Hello

I am trying to drive a MEMS mirror via I2C communication using the nucleo-h723zg board.

This is the clock configuration:

DannyB_2-1767105523319.png

DannyB_3-1767105553038.png

 

Then I activated the I2C1 as follow: 

DannyB_0-1767105458104.pngDannyB_1-1767105475047.png

 

I used the pins PB8 and PB9 for SCL and SDA:

DannyB_4-1767105652277.png

I'm using the DAC called MCP47x6A0T, so the address should be:

static const uint8_t DAC_Address= 0x60;

 

Then I give an input data:

static const uint8_t MEMS_Digital_Input2= 0x1C;

and then I use the function Master Transmit in the while loop:

HAL_I2C_Master_Transmit(&hi2c1, DAC_Address, MEMS_Digital_Input2, 1, HAL_MAX_DELAY);

I've this circuit connected to the microcontroller:

DannyB_5-1767106007834.png

 

Using an oscilloscope and a multimeter I'm always measuring 0V and I can't see the SCL and SDA signals.

Do you know where am I doing wrong?

Kind regards

14 REPLIES 14
DannyB
Associate II

@TDK I fixed the slave address but nothing is changed. I've to check the HAL_I2C_IsDeviceReady function. 

Because @Andrew Neil  when I measure with the oscilloscope both signals are at 0V. So it seems I have no output signal from the microcontroller.


@DannyB wrote:

I measure with the oscilloscope both signals are at 0V


You still haven't said where, exactly, you did this measurement!

 


@DannyB wrote:
AndrewNeil_0-1767173790168.png

There needs to be a GND connection between the Nucleo and the mirror PCB.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

I'm measuring on the PB8 and PB9 pins as shown below:

measureI2C.jpeg

Now I can see the SCL signal but on the SDA signal I see only the slave address, the data is always 0.

I'm trying to send the MEMS_Input2.

DannyB_0-1767349759235.png

When I send the function HAL_I2C_Master_Transmit(&hi2c1, DAC_Address, MEMS_Digital_Input2, 1, HAL_MAX_DELAY);

I've a warning telling this:

DannyB_1-1767349938731.png

Is that the problem for the data always at 0?

 


@DannyB wrote:

Now I can see the SCL signal


Previously you said you were seeing nothing - So what changed? 

Please show a trace of what you see - using your scope's screen capture facility rather than a photo.

Please see How to insert source code - not as screenshots.

 


@DannyB wrote:

When I send the function 
HAL_I2C_Master_Transmit( &hi2c1, DAC_Address, MEMS_Digital_Input2, 1, HAL_MAX_DELAY );

I've a warning telling this:

DannyB_1-1767349938731.png


See the documentation of the HAL_I2C_Master_Transmit function:

AndrewNeil_0-1767357924777.png

https://www.st.com/resource/en/user_manual/um2217-description-of-stm32h7-hal-and-lowlayer-drivers-stmicroelectronics.pdf#page=868

There you can see that argument 3 is pData - which is a pointer to a uint8_t.

But your code supplies  MEMS_Digital_Input - which is an actual uint8_t:

 

AndrewNeil_1-1767358120543.png

You need to pass a pointer to that variable.

 

PS:

Note that the documentation of the HAL functions is provided in the source:

/**
  * @brief  Transmits in master mode an amount of data in blocking mode.
  * @PAram  hi2c Pointer to a I2C_HandleTypeDef structure that contains
  *                the configuration information for the specified I2C.
  * @PAram  DevAddress Target device address: The device 7 bits address value
  *         in datasheet must be shifted to the left before calling the interface
  * @PAram  pData Pointer to data buffer
  * @PAram  Size Amount of data to be sent
  * @PAram  Timeout Timeout duration
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_I2C_Master_Transmit( I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout )

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@Andrew Neil as you said I added a GND connection between the Nucleo and the mirror PCB usign the GND of one of the probes.

This is what I see:

scope_6.png