#Include #Include #Include #Include #Include
#Include #Include #Include #Include #Include
#include
#include
#include
#include
"stm32f0xx_i2c.h"
"i2c.h"
"stm32f0xx.h"
"stm32f0xx_rcc.h"
"stm32f0xx_gpio.h"
100kHz
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
// I2C mode
//
I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
// 50%
duty cycle --> standard
I2C_InitStruct.I2C_OwnAddress1 = 0x00;
// own address, not relevant in master mode
I2C_InitStruct.I2C_Ack = I2C_Ack_Disable;
//
disable acknowledge when reading (can be changed later on)
I2C_InitStruct.I2C_AcknowledgedAddress =
I2C_AcknowledgedAddress_7bit; // set address length to 7 bit addresses
I2C_Init(I2C1, &I2C_InitStruct);
// init I2C1
// enable I2C1
I2C_Cmd(I2C1, ENABLE);
I2C_EVENT_MASTER_BYTE_TRANSMITTED));
}
int main(void){
I2C1_init(); // initialize I2C peripheral
uint8_t received_data;
I2C_start(I2C1,
// start a transmission
I2C_write(I2C1,
I2C_stop(I2C1);
SLAVE_ADDRESS<<1, I2C_Direction_Transmitter);
in Master transmitter mode
0x01); // write one byte to the slave
// stop the transmission