blinking esp8266 not working on NODEMCU

Thread Starter

yef smith

Joined Aug 2, 2020
112
Hello i have installed eclipse and the espressif sdk and the example blinky 2 worked great as shown in code 1 bellow.


Then i have found a manual which gives the code shown bellow called code 2


When i Complied code 2 instead of the bilinky 2 code 1 it showed no error,but it didnt blink either.


I think its because we used the wrong GPIO.
I cant understand the meaning of the CODE2


there is flash stuff, and ATTR,flash map



PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);

gpio_output_set(0, 0, (1 << LED), 0);

What kind of code it is? it differs alot from EFR32 simplisity studio.

Is there some place i cant learn the meaning of these terms?



Code 1

Code:
   /*
The blinky demo using an os timer
TODO : work out why this resets after a while
*/

#include <ets_sys.h>
#include <osapi.h>
#include <os_type.h>
#include <gpio.h>

// see eagle_soc.h for these definitions
#define LED_GPIO 2
#define LED_GPIO_MUX PERIPHS_IO_MUX_GPIO2_U
#define LED_GPIO_FUNC FUNC_GPIO2

#define DELAY 100 /* milliseconds */

LOCAL os_timer_t blink_timer;
LOCAL uint8_t led_state=0;

LOCAL void ICACHE_FLASH_ATTR blink_cb(void *arg)
{
    GPIO_OUTPUT_SET(LED_GPIO, led_state);
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U,FUNC_GPIO12);
    led_state ^=1;
}

void user_rf_pre_init(void)
{
}

void user_init(void)
{
    // Configure pin as a GPIO
    PIN_FUNC_SELECT(LED_GPIO_MUX, LED_GPIO_FUNC);
    // Set up a timer to blink the LED
    // os_timer_disarm(ETSTimer *ptimer)
    os_timer_disarm(&blink_timer);
    // os_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg)
    os_timer_setfn(&blink_timer, (os_timer_func_t *)blink_cb, (void *)0);
    // void os_timer_arm(ETSTimer *ptimer,uint32_t milliseconds, bool repeat_flag)
    os_timer_arm(&blink_timer, DELAY, 1);
}
Click and drag to move

Code 2


#include <stdio.h>
#include "ets_sys.h"
#include "user_interface.h"
#include "gpio.h"
//------------------------------------------------------
#define LED 2
//------------------------------------------------------
void delay(uint32_t count )
{
while(--count);
}
//------------------------------------------------------
uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void)
{
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;

switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 8;
break;

case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
break;

case FLASH_SIZE_16M_MAP_512_512:
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
break;

case FLASH_SIZE_32M_MAP_512_512:
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
break;

default:
rf_cal_sec = 0;
break;
}
return rf_cal_sec;
}
//------------------------------------------------------
void ICACHE_FLASH_ATTR user_init()
{
gpio_init();
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
gpio_output_set(0, 0, (1 << LED), 0);
while(1)
{
delay(1000000);
system_soft_wdt_feed();
gpio_output_set(0, (1 << LED), 0, 0);
delay(1000000);
system_soft_wdt_feed();
gpio_output_set((1 << LED), 0, 0, 0);
}
}
//------------------------------------------------------
1607711715054.gif
 

Attachments

Last edited:
Top