Re: How to write a own I2C(slave) driver? #i2s #slave #driver

Stefan Jaritz


I took the tlv320dac310x audio codec driver as template. Done a very specific driver for the tlv320aic3204 from TI. It is not streamlined with the zephyr audio api. I can send it to you or put it on my github repro.

Maybe it is worth thinking about adding a "code dump" place, were people can share there code. This codes is may not fulfilling the zephyr quality standards but can be a good starting point for everyone who tries to create drivers etc.

Best regards,


On 12/12/2018 11:38, Rodrigo Peixoto wrote:

Stefan, Is that IC a sensor? 
Do you need to use interrupt on it?

I would suggest you to start taking a look at the code from the sensor This is a simple one and it implements the Sensor Driver API. This API is described here If you need interrupts on it, you need to write the proper code for that. You can take a look at the sensor driver

Good luck and let us know if you face any issue. 

Best regards,
Rodrigo Peixoto
Co-founder and Technical advisor

+55 (82) 98144-8585 | Skype: rodrigopex

Em seg, 10 de dez de 2018 às 15:00, Stefan Jaritz <stefan@...> escreveu:

I am currently checking the documentation for a "How to do an I2C slave
driver" and I did not find some tutorial.

Hopefully some guys can quickly tell me how to do it.

My hardware setup: custom stm32f412 board + IC connected via I2C_1 (Pin
B9 & B8)

I created an out of tree board and added at the dts file:

&i2c1 {
     status = "ok";
     clock-frequency = <I2C_BITRATE_FAST>;

I setup the pins in the pinmux.c with these two lines:

#ifdef CONFIG_I2C_1

Think form this side the I2C should be rightfully configured.

Now I like to access the IC connected via I2C_1. How to do that?

How I link my code to the I2C_1 device, write the protocoll functions
and build an API around that?

Any ideas examples are welcome!


Join to automatically receive all group messages.