Hi,
It is far from being complete but any software I2C implementation could be easily adapted using PAL for I/O and GPT/RTCounters for delays. If you are in a hurry it would be a good idea to search some open source implementation and just adapt it.
Giovanni
I2C implementation for STM32
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: I2C implementation for STM32
Trunk has been updated with additional checks of clock divider for I2C bus.
If your PCLK1 frequency is 36MHz and I2C clock is 400kHz and duty cycle is 16/9 than you will get assertion error if compiled with CH_DBG_ENABLE_ASSERTS TRUE. Fast solving of problem:
set I2C clock to 360kHz
or
set duty cycle to 2/1
More information you can found in this topic https://my.st.com/public/STe2ecommuniti ... tviews=105
If your PCLK1 frequency is 36MHz and I2C clock is 400kHz and duty cycle is 16/9 than you will get assertion error if compiled with CH_DBG_ENABLE_ASSERTS TRUE. Fast solving of problem:
set I2C clock to 360kHz
or
set duty cycle to 2/1
More information you can found in this topic https://my.st.com/public/STe2ecommuniti ... tviews=105
-
- Posts: 65
- Joined: Thu Oct 03, 2013 1:06 am
- Location: Santa Cruz, California
- Has thanked: 1 time
- Been thanked: 1 time
Re: I2C implementation for STM32
Just finished reading this whole 35 page thread. It brought back not-so-fond memories...
I developed an I2C driver for the TI MSP430169 when it was first released.
It was the first MSP430 with I2C support. The silicon was very buggy.
Five months of debug before it worked well in master and slave modes. Endless corner cases.
Fortunately, we could put our own logic around the MSP430 to work around problems without resorting to busy waiting.
TI did, to their credit, completely redesign the I2C block in the MSP4302xxx parts, but we stuck with the '169.
Now, we need I2C slave support in a project involving many peer-to-peer networked STM32L1xx chips.
Questions:
It appears we could avoid the busy waits for STOP before beginning each new transaction by wiring SDA and SCL to two GPIOs configured as inputs. Interrupt on raising SDA while SCL is high signals STOP. Is this viable?
Has anyone already tried this?
I'd need to work on adding slave mode capability. The user "Z80" submitted a patch that might be a starting point.
Is there a high-level driver API for Slave Mode yet defined? Should I propose one?
I developed an I2C driver for the TI MSP430169 when it was first released.
It was the first MSP430 with I2C support. The silicon was very buggy.
Five months of debug before it worked well in master and slave modes. Endless corner cases.
Fortunately, we could put our own logic around the MSP430 to work around problems without resorting to busy waiting.
TI did, to their credit, completely redesign the I2C block in the MSP4302xxx parts, but we stuck with the '169.
Now, we need I2C slave support in a project involving many peer-to-peer networked STM32L1xx chips.
Questions:
It appears we could avoid the busy waits for STOP before beginning each new transaction by wiring SDA and SCL to two GPIOs configured as inputs. Interrupt on raising SDA while SCL is high signals STOP. Is this viable?
Has anyone already tried this?
I'd need to work on adding slave mode capability. The user "Z80" submitted a patch that might be a starting point.
Is there a high-level driver API for Slave Mode yet defined? Should I propose one?
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: I2C implementation for STM32
Hi,
I answered in the other thread, there are no plans currently and it would have to be a separate driver, not an extension of the current one.
Giovanni
I answered in the other thread, there are no plans currently and it would have to be a separate driver, not an extension of the current one.
Giovanni
Re: I2C implementation for STM32
Hi,
I am getting an error for I2C stating acknowledgement failure. Any ideas to solve it. I have checked the voltage on my SDA and SCL pin also, which is fine. Also according to my sensor it can be operated at 100k and 400k , and I am operating it at 400k.
Please help me in case i am doing any mistake.
Thanks
Kalpesh
I am getting an error for I2C stating acknowledgement failure. Any ideas to solve it. I have checked the voltage on my SDA and SCL pin also, which is fine. Also according to my sensor it can be operated at 100k and 400k , and I am operating it at 400k.
Please help me in case i am doing any mistake.
Thanks
Kalpesh
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: I2C implementation for STM32
Make sure that you are passing the correct address, which is the value of the upper 7 bits without the RW bit.
Giovanni
Giovanni
Re: I2C implementation for STM32
Giovanni wrote:Make sure that you are passing the correct address, which is the value of the upper 7 bits without the RW bit.
Giovanni
So It means , I should pass the slave address directly(i.e. only 7 bits to be transmitted) without the read/ write bit (Read -1, Write -0).
Return to “Development and Feedback”
Who is online
Users browsing this forum: No registered users and 17 guests