Custom wire/i2c frequency stm32f103 ?

Post Reply
ziumus
Posts: 2
Joined: Mon Jan 29, 2018 11:52 am

Custom wire/i2c frequency stm32f103 ?

Post by ziumus » Mon Jan 29, 2018 11:58 am

Hello,
I need to set 300khz frequency on my i2c, i have tried 100k and 400k, 100k works fine, but 400k doesnt work at all.
On arduino Uno i can set 300k and lcd works fine.
Is there a way to set custom frequency on stm32f103?
Thanks

User avatar
mrburnette
Posts: 2220
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Custom wire/i2c frequency stm32f103 ?

Post by mrburnette » Mon Jan 29, 2018 1:22 pm

Try this syntax: viewtopic.php?f=51&t=2024&start=20#p40640

I2C now defaults to hardware I2C rather than software I2C as of August 2017.

Little thin on your forum introduction, ugh? :lol:
You may find something of interest here: http://stm32duino.com/viewtopic.php?f=2&t=3111


Ray

User avatar
RogerClark
Posts: 7690
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Custom wire/i2c frequency stm32f103 ?

Post by RogerClark » Mon Jan 29, 2018 8:28 pm

Please introduce yourself as it’s not fair in other forum members to expect help from the community without at least saying hello and what project you are working on.

Remember the Arduino_STM32 and STM32GENERIC cores are non commercial and developed by community members, so without the community, neither Core would exist.

P.S

Ray is a global moderator and I am super admin.

ziumus
Posts: 2
Joined: Mon Jan 29, 2018 11:52 am

Re: Custom wire/i2c frequency stm32f103 ?

Post by ziumus » Wed Feb 07, 2018 9:29 am

Sorry for poor introduction.
We are working on High Performance electric bike.
For first few prototypes we used atmega.We use them for LCD, SD ,Bluetooth, BMS.
we came to the problem where Arduino Mega is slow for LCD and SD card logging.
Then we found this amazing project .
Over a couple of weeks almost 90% of the code has been converted to work on stm32f103ZET6.

This problem with the frequency I have solved in i2c.c file, just changed 400 000 to 170 000 and it works fine.

Code: Select all

        if (flags & I2C_DUTY_16_9) {
            /* Tlow/Thigh = 16/9 */
            ccr |= I2C_CCR_DUTY_16_9;
            ccr |= clk_hz / (400000 * 25);
        } else {
            /* Tlow/Thigh = 2 */
            ccr |= clk_hz / (400000 * 3);
        }
I'm the beginner in the world of micro controllers, but I'll try to help the community as much as I can

Thanks you for your effort .

User avatar
mrburnette
Posts: 2220
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Custom wire/i2c frequency stm32f103 ?

Post by mrburnette » Wed Feb 07, 2018 2:30 pm

ziumus wrote:
Wed Feb 07, 2018 9:29 am
<...>
For first few prototypes we used atmega.We use them for LCD, SD ,Bluetooth, BMS.
we came to the problem where Arduino Mega is slow for LCD and SD card logging.
<...>
The ZET6 @72MHz will provide lots of processor bandwidth and SRAM resources; however, you will still need to be careful about your choice of implementation for peripherals. non-DMA and a poor choice of 3rd party libraries can still cause a significant hiccup in performance.

One way around such problems is to ensure that no code ever blocks; sometimes harder to do when you are selecting libraries as "black-box" software products. Architect your code to ensure that every peripheral software object is non-blocking. This query will give some insight into posts in this forum on the subject.

There is however, another option: Throw hardware at it! SD logging has only one input stream: characters. For all practical purposes, a 16MHz AVR uC can completely handle an SD card as a self-contained system. I did a crude prototype as a demonstration many years ago... here.

As you are currently in the "port phase" of your project, I would encourage you to get-to-know your code by profiling every section ... that is, determine the worst-cast time in mS that any section of code will take to run. Overall performance of the software is a loop() function, but understanding what is happening in the loop will give you insight on where to spend time in optimizing (or off-loading) performance concerns.

Ray

Post Reply