Mit dem ESP32C3 laufen lernen

OP #7751153
Lesenswert?

Hallo ihr Bit Manipulierer,

aktuell habe ich ein kleines ESP32C3 Super Mini Board vor mir liegen. Vorher habe ich überwiegend etwas mit den AVR 8 bitlern zu tun gehabt.

Nun möchte ich ohne das ganze Arduino Krams mal versuchen einen I/O Pin zu nutzen.. Klappt leider noch nicht..

Es könnte sein das ich das Datenblatt falsch deute oder mein Code einfach nur falsch ist?! Könnte mal jemand von euch Experten bitte drüber schauen..

1
/*
2
GPIO_FUNCn_OUT_SEL Selection control for GPIO output n. If a value Y (0<=Y<128) is written to this
3
field, the peripheral output signal Y will be connected to GPIO output n. If a value 128 is written
4
to this field, bit n of GPIO_OUT_REG and GPIO_ENABLE_REG will be selected as the output value
5
and output enable. (R/W)
6
*/
7
volatile uint32_t *GPIO_Func_Out_Cnfg = (uint32_t*) (0x0554 + 4  * 8);
8

9
/*
10
GPIO_OUT_DATA_ORIG GPIO0 ~ 21 output value in simple GPIO output mode. The values of bit0
11
~ bit21 correspond to the output value of GPIO0 ~ GPIO21 respectively, and bit22 ~ bit25 are
12
invalid. (R/W/SS)
13
*/
14
volatile uint32_t *GPIO_Out_Reg = (uint32_t*)(0x0004);
15

16
/*
17
GPIO_ENABLE_DATA GPIO output enable register for GPIO0 ~ 21. Bit0 ~ bit21 are corresponding to
18
GPIO0 ~ 21, and bit22 ~ bit25 are invalid. (R/W/SS)
19
*/
20
volatile uint32_t *GPIO_Enable_Reg = (uint32_t*)(0x0020);
21

22
void setup() {
23

24
  // special peripheral index
25
  *GPIO_Func_Out_Cnfg = 0x80;
26

27
  // set GPIO8
28
  *GPIO_Out_Reg &= ~1<<8u; 
29

30
  // enable GPIO8
31
  *GPIO_Enable_Reg = 1<<8u;
32

33
}
34

35
void loop() {
36
  // put your main code here, to run repeatedly:
37

38
}
Angehängte Dateien:
OP #7751175
Lesenswert?

Harald K. schrieb:

Und dann sieh Dir Setie 94 an.

Okay. Also die Basis Adresse vom GPIO ist 0x60004000. Das heißt für die Register die ich beschreiben möchte z.B.

1
volatile uint32_t *GPIO_Func_Out_Cnfg = (uint32_t*) (0x0554 + 4  * 8);

müssen auf die Basis Adresse addiert werden oder?

1
//Mapping Address
2
//GPIO 0x6000_4000 to 0x6000_4FFF 
3

4
#define GPIO_BASE 0x60004000u
5

6
/*
7
GPIO_FUNCn_OUT_SEL Selection control for GPIO output n. If a value Y (0<=Y<128) is written to this
8
field, the peripheral output signal Y will be connected to GPIO output n. If a value 128 is written
9
to this field, bit n of GPIO_OUT_REG and GPIO_ENABLE_REG will be selected as the output value
10
and output enable. (R/W)
11
*/
12
volatile uint32_t *GPIO_Func_Out_Cnfg = (uint32_t*) GPIO_BASE + (0x0554 + 4  * 8);
#7751334
Lesenswert?

Jan H. schrieb:

Nun möchte ich ohne das ganze Arduino Krams mal versuchen einen I/O Pin zu nutzen..

Micropython https://micropython.org/download/ESP32_GENERIC_C3/ https://docs.micropython.org/en/latest/esp32/quickref.html

1
# hello world für ESP8266 oder ESP32
2
# ESP32-C3 Pin 8   0 = LED on  1 = LED off
3

4
from machine import Pin
5
import time
6
p=Pin(2,Pin.OUT)
7

8
while True:
9
    p.on()
10
    time.sleep(1)
11
    p.off()
12
    time.sleep(1)
#7751696
Lesenswert?

Jan H. schrieb:

Fehler gefunden! Anscheind macht die Arduino IDE warum auch immer andere Rechenschritte..

1
> volatile uint32_t *GPIO_Out_Reg = (uint32_t*)(GPIO_BASE + 0x0004);
2
>

ergibt ein anderes Ergebniss als

1
> volatile uint32_t *GPIO_Out_Reg = (uint32_t*)GPIO_BASE + 0x0004;
2
>

Keine Arduino Eigenwilligkeit, sondern C Standard.

Im ersten Fall addierst Du die Zahlen GPIO_BASE und 4. Anschließend machst Du einen Pointer auf 32 Bit Daten daraus.

Im zweiten Fall machst Du aus der GPIO_BASE einen 32 Bit Pointer und addierst dann 4 (32 Bit) Elemente darauf.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren