Search code examples
c++arduinoarduino-esp8266atmelstudio

Arduino yield in Atmel Studio


I'm trying to write code for Arduino in Atmel Studio 7. To keep it similar to Arduino IDE, I'm trying to adapt its libs.

But I got already blocked by delay(), which uses yield(). Yield does not seem to be implemented anywhere. So my compiler says "undefined reference to yield".

I don't understand how the Arduino IDE handles that? What can I do to use yield() in Atmel Studio?

Here's my try:

#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#include <util/delay.h>
#include <avr/io.h>

#include <Arduino.h>
#include <wiring.c>

int main(void) {
  DDRB = (1 << DDB5);
  while(1) {
    PORTB = (1 << DDB5);
    delay(1000);
    PORTB = (0 << DDB5);
    delay(1000);
  }
}

Solution

  • Although delays, as the commenters suggest, are usually to be avoided, most of us who program bare metal Atmel chips start off with the blinking LED program. It's the "Hello World" of bare-metal embedded programming. A delay is fine for this.

    If you will look in you util/delay.h though, you will see functions that are especially written for your chip. Use those instead and do not link in the Arduino versions. You will find a _delay_ms() and _delay_us() functions which are perfect for this first-steps type of program.