It is supposed to be a really simple task, but im running into an error:
E (23) gpio: GPIO can only be used as input mode
Here is the code I have used: (I am not even using GPIO 23, wtf is going on T_T)
#include <SPI.h>
const int CS_PIN = 35; // Chip Select pin
const int MOSI_PIN = 21; // Master Out Slave In
const int SCK_PIN = 18; // Clock pin
const int MISO_PIN = 19;
const int dummypin = 23;
//00010001 in hexadecimal this is taken from datasheet
#define CMD_WRITE 0x11
void setup() {
SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);
pinMode(dummypin, INPUT);
pinMode(CS_PIN, OUTPUT);
// Set CS high
digitalWrite(CS_PIN, HIGH);
}
void loop() {
setPotentiometerValue(0); // Value range is 0-255
}
// Function to set potentiometer value
void setPotentiometerValue(uint8_t value) {
// Bring CS low to select the MCP41010
digitalWrite(CS_PIN, LOW);
SPI.transfer(CMD_WRITE); // Command byte
SPI.transfer(value); // to set pot value
// Bring CS high to send the data (ig)
digitalWrite(CS_PIN, HIGH);
}
Where am I going wrong T_T, I am not even using GPIO23
Here is the datasheet: Single/Dual Digital Potentiometer with SPI Interface (microchip.com)
aagum-bae:
It is supposed to be a really simple task, but im running into an error:
E (23) gpio: GPIO can only be used as input mode
Here is the code I have used: (I am not even using GPIO 23, wtf is going on T_T)
#include <SPI.h>
const int CS_PIN = 35; // Chip Select pin
const int MOSI_PIN = 21; // Master Out Slave In
const int SCK_PIN = 18; // Clock pin
const int MISO_PIN = 19;
const int dummypin = 23;
//00010001 in hexadecimal this is taken from datasheet
#define CMD_WRITE 0x11
void setup() {
SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);
pinMode(dummypin, INPUT);
pinMode(CS_PIN, OUTPUT);
// Set CS high
digitalWrite(CS_PIN, HIGH);
}
void loop() {
setPotentiometerValue(0); // Value range is 0-255
}
// Function to set potentiometer value
void setPotentiometerValue(uint8_t value) {
// Bring CS low to select the MCP41010
digitalWrite(CS_PIN, LOW);
SPI.transfer(CMD_WRITE); // Command byte
SPI.transfer(value); // to set pot value
// Bring CS high to send the data (ig)
digitalWrite(CS_PIN, HIGH);
}
Where am I going wrong T_T, I am not even using GPIO23
You can check the answers here about the error message you are seeing.
opened 05:42PM - 22 Jan 24 UTC
closed 02:18PM - 23 Jan 24 UTC
Status: Awaiting triage
### Board
ESP32 Wroom DevKit & Lolin32 Lite
### Device Description
Esp32 in b… readboard with 3 multiplexers connected
### Hardware Configuration
//Read Mux 1 & 2
#define ReadS0 16
#define ReadS1 4
#define ReadS2 2
#define ReadS3 15
#define ReadEnable 17
#define ReadAnalogPin 35
#define ReadDigitalPin 34
//Out Mux
#define OutS0 21
#define OutS1 19
#define OutS2 18
#define OutS3 5
#define OutEnable 22
#define OutPin 32
### Version
v2.0.11
### IDE Name
Arduino IDE
### Operating System
Windows 10
### Flash frequency
80MHz
### PSRAM enabled
no
### Upload speed
921600
### Description
Weird Behavior when setting consecutive pinMode as OUTPUT, i get random crashes and random error in pin setting and sometimes random Serial characters and freezing of sketch. For example, sometimes my code does not initialize when starting the set pin section, other times some pins give error, but the pins with the errors are not consistent, sometimes it's a set of pins, sometimes other pins. Completely randomly.
`E (4607) gpio: GPIO can only be used as input mode
[ 4613][E][esp32-hal-gpio.c:130] __pinMode(): GPIO config failed`
### Sketch
```cpp
pinMode(mux_read_enable_, OUTPUT);
pinMode(mux_out_enable_, OUTPUT);
pinMode(mux_read_analog_, INPUT);
pinMode(mux_read_digital_, INPUT);
pinMode(mux_out_pin_, OUTPUT);
Serial.println("Mux Pins Set");
for (int i = 0; i < 4; i++) {
Serial.println(mux_read_s[i]);
pinMode(mux_read_s_[i], OUTPUT);
//delay(10);
}
Serial.println("Mux Read Pins Set");
for (int i = 0; i < 4; i++) {
Serial.println(mux_out_s[i]);
pinMode(mux_out_s_[i], OUTPUT);
//delay(10);
}
Serial.println("Mux Out Pins Set");
//Set Mux Pins to LOW
digitalWrite(mux_read_enable_, LOW);
digitalWrite(mux_out_enable_, LOW);
digitalWrite(mux_out_pin_, LOW);
Serial.println("Mux Read Pins Set to LOW");
GPIO.out_w1ts = ((uint32_t)0 << mux_read_s_[0]);
Serial.print("Mux read pin set: ");
Serial.println(mux_read_s_[0]);
GPIO.out_w1ts = ((uint32_t)0 << mux_read_s_[1]); //Issue?
Serial.print("Mux read pin set: ");
Serial.println(mux_read_s_[1]);
GPIO.out_w1ts = ((uint32_t)0 << mux_read_s_[2]);//Issue?
Serial.print("Mux read pin set: ");
Serial.println(mux_read_s_[2]);
GPIO.out_w1ts = ((uint32_t)0 << mux_read_s_[3]); //Issue?
Serial.print("Mux read pin set: ");
Serial.println(mux_read_s_[3]);
Serial.println("Mux Out Pins Set to LOW");
GPIO.out_w1ts = ((uint32_t)0 << mux_out_s_[0]);
Serial.println("Mux out pin: " + String(mux_out_s_[0]) + "set to LOW");
GPIO.out_w1ts = ((uint32_t)0 << mux_out_s_[1]);
Serial.println("Mux out pin: " + String(mux_out_s_[1]) + "set to LOW"); //Issue?
GPIO.out_w1ts = ((uint32_t)0 << mux_out_s_[1]);
Serial.println("Mux out pin: " + String(mux_out_s_[2]) + "set to LOW");
GPIO.out_w1ts = ((uint32_t)0 << mux_out_s_[3]);
Serial.println("Mux out pin: " + String(mux_out_s_[3]) + "set to LOW");
```
### Debug Message
```plain
E (4607) gpio: GPIO can only be used as input mode
[ 4613][E][esp32-hal-gpio.c:130] __pinMode(): GPIO config failed
```
### Other Steps to Reproduce
_No response_
### I have checked existing issues, online documentation and the Troubleshooting Guide
- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.
xfpd
August 20, 2024, 12:59pm
3
Is this upside down? Setting a pin after using it?
aagum-bae:
SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);
pinMode(dummypin, INPUT);
pinMode(CS_PIN, OUTPUT);
I think this is "error #23 "... and has to do with other GPIO pins (reserved?)
opened 11:35AM - 23 Jan 17 UTC
closed 05:26PM - 05 Apr 17 UTC
Hi
How i can configure GPIO 32 and 33 as input or output in ESP32, I tried for … all other gpio, those are working, Can anyone give some suggestion.
Thanks
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html
ah shit thanks, i think i need to change that
thanks for the reply, will check that out
horace
August 20, 2024, 1:48pm
6
any particular reason not to use the default ESP32 VSPI pins?
MOSI: 23
MISO: 19
SCK: 18
SS: 5
I am already using those pins for something else and they are soldered inplace, i do not want to remove the soldering and rework again
system
Closed
February 17, 2025, 5:57am
8
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.