The Problem with Ports ESP8266

 

I was about to write about my stunning success with the ESP8266 and WS2812b chips when I’ve hit a snag.

I have a working example of high speed port bashing to control the serial LEDS on GPIO-0.. but I want to use GPIO12. Assuming all of the ports are setup properly..

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(0), 1 );

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(0), 0 );

The above toggles GPIO-0 up and down at high speed.

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(12), 1 );

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(12), 0 );

The above does not work on GPIO-12

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(12), 0x1000 );

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(12), 0 );

The above does not work on GPIO-12 either

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR,0x1000 );

WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR,0 );

The above works a TREAT on GPIO-12 – but sadly it also messes up the OTHER port bits!!!!

What is the correct code for GPIO-12 ???

Facebooktwittergoogle_pluspinterestlinkedin

7 thoughts on “The Problem with Ports ESP8266

  1. Your problem can be in your assumption, that the GPIO12 is set up correctly. Give us more details on how your GPIO12 is configured and maybe we can help you. Do you want PWM on GPIO 12 ?

    1. Hi trhere.

      I've set all the pins as output pins and tested them as such - turning them on and off

      I then grabbed the lines you see above and they work perfectly for GPIO0... I then tried them on GPIO4 and 12 - no Joy.

      I've tried variations that are supposed to work but no good as timing is utterly critical for WS2812b LEDS.

      WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR,0x1000 );

      WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR,0 );

      This works - but messes up other PORT bits - I've since realised that there are several locations - this one is obviously the "lets mess with all port bit locations... so I'm assuming what I need is a slight variation on this...

      1. Oh and no I don't want PWM - I just want to turn this on and off at the exact same speed as I could with GPIO0 using the same code.

        This is how time critical it is - from the example I've used which works a treat.

        time=4; while (time--) WRITE_PERI_RED (PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(WSGPIO),1);
        time=9; while (time--) WRITE_PERI_RED (PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(WSGPIO),0);

        I just want to do this on other pins than GPIO0 (WSGPIO=0 in this case).

    1. Dear ALL - so many thanks for all your comments - Catalin - that code has issues according to the guy who wrote an offshoot of it.

      I started a response in here - but this is such a fun and useful conversation - I've written a new blog item.

      The short answer is - SORTED !!!

Comments are closed.