cancel
Showing results for 
Search instead for 
Did you mean: 

I2C - generated CubeMX

TomᨠMat?jka
Associate II
Posted on March 28, 2017 at 22:56

Hello, I still tried with I2C on nucleo F401RE. I am use STM32CubeMx for generate files, but my program is not working. I  want send three bytes on I2C in blovking mode. This is my code: 

I2C not working, still is log. 0 on SDA and SCL. Please help me.

In rar. is all files.

int main(void)

{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration----------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

/* Configure the system clock */

SystemClock_Config();

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_I2C1_Init();

/* USER CODE BEGIN 2 */

/* USER CODE END 2 */

uint8_t buffer[3]={0x33,0x87,0X76};

while (1)

{

HAL_I2C_Master_Transmit(&hi2c1,0X40,buffer,3,10);

HAL_Delay(100);

HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);

/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}

#hal #smt32-nucleo #cube-mx #i2c
4 REPLIES 4
choirul Kusumohadi
Associate
Posted on February 27, 2018 at 11:52

Hallo, have u done with this issue?

Posted on February 27, 2018 at 13:07

After very nearly a year, one would hope so!

Posted on February 28, 2018 at 02:27

I has some like a bug in CubeMX,

Condition:

I use STM32l073Rz,

When I generated a code with setup I2C1 :

Primary Slave Address : 0x02 in CubeMX,

Primary Address Length Selection : 7 bit.

But output script shown 0x04,

When I change 0x01, output script shown 0x02.

Posted on February 28, 2018 at 11:32

Sounds like one is using the 7-bit address right-aligned in a byte, and the other has it left-aligned...

http://www.avrfreaks.net/comment/1872781&sharpcomment-1872781