i was wondering how i could write a delay function in the STM8 - IAR Embedded Workbench? I used the search-function inside the IDE, so i found the "__delay()" function but if i try to use it i get:

"no definition for '__delay'"

  • 1
    \$\begingroup\$ Are you including the header that declares that function? \$\endgroup\$ – Nick Williams Aug 19 '15 at 19:01
  • \$\begingroup\$ Hi and thanks for your reply, i don't think so, according to the help it is a "pre-defined system macro" \$\endgroup\$ – binaryBigInt Aug 19 '15 at 19:23
  • \$\begingroup\$ I'm not familiar with IAR Embedded Workbench, so I'm just guessing. Can you see what file the "delay" is declared and try to include that in your source file. You might have to google: "include file for IAR Embedded Workbench". \$\endgroup\$ – Nick Williams Aug 19 '15 at 19:27
  • \$\begingroup\$ According to the Help-function i have to define my system macros in an extra file which will be loaded while the code is executing. Is there seriously no build-in delay-function? \$\endgroup\$ – binaryBigInt Aug 19 '15 at 19:46

IAR has __delay_cycles you can use it. Here a basic code

#include <intrinsics.h>
#if !defined(F_CPU)
#warning no F_CPU

#define delay_us(us) __delay_cycles((F_CPU  *(us)/4000000uL)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.