2024-12-31 11:15 AM - last edited on 2025-01-08 08:44 AM by Andrew Neil
STM32F407G DISC-1 STMCubeIDE
Greetings, I am trying to send data to LCD screen by using I2C Communication Protocol. I succeed in doing it by using HAL library. Also, my current work does work in debug mode.However, I could not make it work by running it normally.
I did it in HAL by using the same clock, frequency configurations. I could not find the problem.
Here is my code:
int main(void)
{
GPIO_Handle_t I2C1_SCL_PB6 = { .PORTNAME = GPIOB,
.PINCONF.PIN = GPIO_PIN_6,
.PINCONF.MODE = GPIO_MODE_ALTARNATE,
.PINCONF.OTYPE = GPIO_OTYPE_OD,
.PINCONF.OSPEED = GPIO_OSPEED_VHIGH,
.PINCONF.PUPD = GPIO_PUPD_PU,
.PINCONF.AF = AF4
};
GPIO_Handle_t I2C1_SDA_PB7 = { .PORTNAME = GPIOB,
.PINCONF.PIN = GPIO_PIN_7,
.PINCONF.MODE = GPIO_MODE_ALTARNATE,
.PINCONF.OTYPE = GPIO_OTYPE_OD,
.PINCONF.OSPEED = GPIO_OSPEED_VHIGH,
.PINCONF.PUPD = GPIO_PUPD_PU,
.PINCONF.AF = AF4
};
gpioInit(&I2C1_SCL_PB6);
gpioInit(&I2C1_SDA_PB7);
I2C1_CLOCK_ENABLE();
I2C1_FREQ_16MHZ();
I2C1_FREQ_SCL_100MHZ();
I2C1_RISE_TIME_17();
I2C1_ENABLE();
I2C1_ACK_ENABLE();
I2C1_START_GENERATION();
I2C1->I2C_DR = SLAVE_ADDRESS_LCD;
lcd_init ();
lcd_send_string ("ABCDE");
while(1)
{
}
}
2025-01-08 10:18 AM
Yes, I already checked them, in HAL structured code, no-pull up, no pull-down is configured.Also, I tried to use external pull-up resistor but in any case TxE is never set.I already shared each file as public.
2025-01-08 11:40 AM
> Yes, I already checked them
Chip should work the same way then. Registers dictate how it works. It's a mystery. Good luck.