Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No function to enable I2C slave (STM32F0) #1508

Open
riban-bw opened this issue Nov 3, 2023 · 0 comments
Open

No function to enable I2C slave (STM32F0) #1508

riban-bw opened this issue Nov 3, 2023 · 0 comments

Comments

@riban-bw
Copy link

riban-bw commented Nov 3, 2023

I am using libopencm3 with a STM32F072 as a I2C target (slave). This code block enables this mode:

// Configure GPIO B6 (I2C1 SCL), B7 (I2C1 SDA)
rcc_periph_clock_enable(RCC_GPIOB);
gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO6);
gpio_set_af(GPIOB, GPIO_AF1, GPIO6);
gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO7);
gpio_set_af(GPIOB, GPIO_AF1, GPIO7);

// Configure I2C1
nvic_enable_irq(NVIC_I2C1_IRQ);
i2c_reset(I2C1);
i2c_peripheral_disable(I2C1);
rcc_periph_clock_enable(RCC_I2C1);
rcc_set_i2c_clock_hsi(I2C1);
i2c_set_speed(I2C1, i2c_speed_sm_100k, 8);
i2c_set_own_7bit_slave_address(I2C1, address);
i2c_enable_interrupt(I2C1, I2C_CR1_ADDRIE);
I2C_OAR1(I2C1) |= I2C_OAR1_OA1EN_ENABLE; //!@todo This should be available in cm3 lib
i2c_peripheral_enable(I2C1);

I have to manually set the OA1EN flag in OAR1. There should be a method of enabling this mode without resorting to direct register manipulation. (That is of course the purpose of this abstraction library.) This could be done automatically when setting slave address or, maybe that could be undesirable in which case a separate function to enable slave may be desirable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant