Read Rotary BCD Coded Switch

dikkehenk
Posts: 2
Joined: Fri Mar 29, 2019 1:02 pm

Read Rotary BCD Coded Switch

Postby dikkehenk » Mon Apr 01, 2019 12:19 pm

Hi,
This is my first time I am asking a question on this forum. Thanks to everyone who is contributing. Learned a lot here.

At the start of my code I want to read a 10 Position Rotary BCD Coded Switch (I only need 8 positions -3 bits-)
I am using GPIO 12-13-14 of the ESP. On my DOIT board the pinout is 6 =GPIO 13, 7 = GPIO 12, 8 = GPIO 14. I will correct that with the wiring. A simple way is to read the input register of the ESP32. Then shift right (12 times -from pin 12-) to get the dec. value of the rotary switch.

Before I can use (read) the input register I have to write/clear the GPIO_ENABLE_W1T(Clear) with 3 bits (0x07) shifted for the right pin positions.

Examples of ESP32 direct port manipulation are hard to find. With the knowledge I've collected so far I've written this code.
Am I on the right track?

Thanks Henk
  1. void setup() {
  2. pinMode(12, INPUT_PULLDOWN);
  3. pinMode(13, INPUT_PULLDOWN);
  4. pinMode(14, INPUT_PULLDOWN);
  5.  
  6. REG_WRITE(GPIO_ENABLE_W1TC_REG, 0x07 << 12); //Enable pin 12-13-14 (0x07 = bin 00000111 only need 3 bits)
  7.  
  8. uint32_t input = REG_READ(GPIO_IN_REG); //Read the Input 32bit register
  9. input = input >> 12; // Shift the found value 12 times to the right to calc the value
  10.  
  11. Serial.print (input); //Check the found decimal nr.
  12. }
  13.  
  14. void loop() { }

username
Posts: 479
Joined: Thu May 03, 2018 1:18 pm

Re: Read Rotary BCD Coded Switch

Postby username » Mon Apr 01, 2019 9:35 pm

I've collected so far I've written this code. Am I on the right track?
Well, does it work, if so then your on the right track. :D

dikkehenk
Posts: 2
Joined: Fri Mar 29, 2019 1:02 pm

Re: Read Rotary BCD Coded Switch

Postby dikkehenk » Tue Apr 02, 2019 11:52 am

Just trying to get an expert view on this code

ESP_Sprite
Posts: 9025
Joined: Thu Nov 26, 2015 4:08 am

Re: Read Rotary BCD Coded Switch

Postby ESP_Sprite » Wed Apr 03, 2019 3:42 am

Looks good, but can I ask what the reason you don't want to use the GPIO read functions given by ESP-IDF/Arduino is?

Who is online

Users browsing this forum: No registered users and 146 guests