The hardware functionality and I2C state machine is described in a reference manual. Take a note that I2C is not the simplest peripheral to program. If you lack the experience, I suggest first implementing a reliable full-duplex UART driver. That is also more practical as UART can provide additional printf() style debugging. When you will have done that, you will have gained enough experience to go on and implement I2C driver. :)