Skip to main content
mehmet.karakaya
Associate III
September 20, 2010
Question

GPIO routines for IIC eeprom - tested on STM32F103RET6

  • September 20, 2010
  • 5 replies
  • 719 views
Posted on September 20, 2010 at 16:18

GPIO routines for IIC eeprom - tested on STM32F103RET6

    This topic has been closed for replies.

    5 replies

    trevor23
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:08

    And have a single software delay function instead of all the repeated loop delays e.g.

    #define LOOPS_PER_MICRO_SECOND ??? // change as appropriate

    void delay_uS(unsigned int uS)

    {

        unsigned int volatile i;

        for (i = uS * LOOPS_PER_MICRO_SECOND; i; i--);

    }

    This way you have only one ''magic number'' to change when porting / changing speed i.e. LOOPS_PER_MICRO_SECOND.

    Andrew Neil
    Super User
    May 17, 2011
    Posted on May 17, 2011 at 14:08

    Note that software delay loops are liable to be optimised-out by a decent compiler.

    And you haven't said what clock frequency/ies is/are appropriate to the particulare ''magic numbers'' that you've used...

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    mehmet.karakaya
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:08

    I think I adjusted the system clock to 72 Mhz

    so the magic numbers dont need to be changed for slower processors

    I think if it runs for 72 Mhz it runs for slower too

    Andrew Neil
    Super User
    May 17, 2011
    Posted on May 17, 2011 at 14:08

    You're still missing the fundamental flaw with relying upon the execution timing of anything written in a High-Level Language (HLL) - see: 

    http://www.8052.com/forum/read/162556

     (not 8052-specific)

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    mehmet.karakaya
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:08

    ok - you are right but maybe some inline assemler delay macro can be written

    instead of my HLL routines - inline assembler cannot be optimized by compiler , am I wrong ?

    -----------------------------

    I have another question - please look at it

    I want the system tick function be called every 100 milisecond 

    and that it makes one variable true - thats all I want 

    but when I add the below line in main() fucntion 

    my program freezes - what is worng or mising in my program ?

    main(){

    ..............

     SysTick_Config(SystemCoreClock / 10);

    ..............

    }

    in stm32f10x_it.c

    -----------------------------

    void SysTick_Handler(void)

    {

        TIMERJOB=1;

    }