How to get a value of IO_MUX_04_REG

whoyoume
Posts: 23
Joined: Fri Sep 07, 2018 2:42 am

How to get a value of IO_MUX_04_REG

Postby whoyoume » Fri Sep 07, 2018 12:15 pm

Hello All,

The code below that is for arduino IDE shows a correct value, but continues reboot when get the comment out lines work.

Could anybody tell me why?

Thank you.

---------------------------------------
volatile uint32_t* p_IO_MUX_04_REG; // cf. p70 esp32_technical_reference_manual_en.pdf
volatile uint32_t* p_IO_MUX_15_REG;
uint32_t IO_MUX_04_REG = 0;
uint32_t IO_MUX_15_REG = 0;

void printf(char *fmt, ...) {
char buf[256];
va_list args;
va_start(args, fmt);
vsnprintf(buf, 256, fmt, args);
va_end(args);
Serial.print(buf);
}

void setup() {
pinMode(4, INPUT);
pinMode(15, OUTPUT);
p_IO_MUX_04_REG = (volatile uint32_t*)(0x10 + 4*4);
p_IO_MUX_15_REG = (volatile uint32_t*)(0x10 + 4*15);
//IO_MUX_04_REG = *p_IO_MUX_04_REG;
//IO_MUX_15_REG = *p_IO_MUX_15_REG;
Serial.begin(2000000);
printf("IO_MUX_04_REG = %08x\n", IO_MUX_04_REG);
printf("IO_MUX_15_REG = %08x\n", IO_MUX_15_REG);
delay(10000);
}

void loop() {
}
---------------------------------------

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: How to get a value of IO_MUX_04_REG

Postby WiFive » Fri Sep 07, 2018 11:08 pm

Address is wrong, look at page 59. Also suggest you use utility functions like REG_GET_FIELD, REG_SET_FIELD

whoyoume
Posts: 23
Joined: Fri Sep 07, 2018 2:42 am

Re: How to get a value of IO_MUX_04_REG

Postby whoyoume » Sat Sep 08, 2018 9:00 am

WiFive, Thank you. I've get a fine result as below,

00000000000000000010101000000000 (1)
00000000000000000010101000000000 (2)
00000000000000000010101100000000 (5)

with the source code shown below.

// cf. p59 esp32_technical_reference_manual_en.pdf
//
volatile uint32_t* p_IO_MUX_GPIO4_REG = (volatile uint32_t*)IO_MUX_GPIO4_REG;
uint32_t val_IO_MUX_GPIO4_REG = 0;

void printf(char *fmt, ...) {
char buf[256];
va_list args;
va_start(args, fmt);
vsnprintf(buf, 256, fmt, args);
va_end(args);
Serial.print(buf);
}

void bit32(char* p, unsigned int val) {
for(int k = 0; k < 32; k++) {
if((val >> (31 - k)) & 1) p[k] = '1';
else p[k] = '0';
}
p[32] = '\0';
}

void setup() {
Serial.begin(2000000);
}

int flg = INPUT;
char buff[48];

void loop() {
if(flg == INPUT) flg = OUTPUT;
else if(flg == OUTPUT) flg = INPUT_PULLUP;
else flg = INPUT;
pinMode(4, flg);
delay(100);
val_IO_MUX_GPIO4_REG = *p_IO_MUX_GPIO4_REG;
bit32(buff, val_IO_MUX_GPIO4_REG);
printf("%s (%d)\n", buff, flg);
delay(1000);
}

Who is online

Users browsing this forum: No registered users and 83 guests