How I program GPIOs in C | Embedded System Project Series #12

  Рет қаралды 8,944

Artful Bytes

Artful Bytes

Күн бұрын

I program the I/O-pins on my robot (and development board) according to the pin assignment in my schematic. Writing to registers is cumbersome, so to make things easier, I implement a code abstraction in C that lets me configure and initialize all pins in a single place.
The git repository:
github.com/artfulbytes/nsumo_...
0:00 Recap
0:44 Introduction
1:57 Why start here?
3:18 Setup
4:00 Pin Mapping
5:40 How are IO pins configured?
7:25 Memory-mapped registers
8:56 Blinky example
9:42 Defining the interface (io.h)
10:15 Select register
11:32 Direction register
11:59 Resistor register (pullup/pulldown)
13:22 Input register
13:57 First commit
14:39 How to implement?
15:39 Bitwise operation (code trick!)
17:29 Array indexing (code trick!)
18:52 Implementation (io.c)
19:53 Testing the code
22:38 Second commit
22:55 Initialize all pins
28:27 Third commit
28:44 Last words
#embeddedsystems #gpio #cprogramming
⌨️ My development environment
www.artfulbytes.com/devenv
🌍 Links
GitHub - github.com/artfulbytes
Website - www.artfulbytes.com
👨‍💻 About me
Hi and welcome. I'm Niklas, an embedded systems engineer from Sweden. On this channel, I make practical videos about embedded systems or, in general terms, about building and programming hardware.

Пікірлер: 17
@palaaaurinkoon
@palaaaurinkoon Жыл бұрын
Thank you for this wonderful series. Can't wait to see what's next.
@needywallaby2030
@needywallaby2030 2 ай бұрын
i was searching for copper but found a gold this channel is best imo
@renanpils
@renanpils 4 ай бұрын
This series is awesome man! Very good content!
@redwoodenjoyer
@redwoodenjoyer 11 ай бұрын
You are so, so smart and good at explaining this. Coming from Arduino and slowly leveling up my knowledge and realizing that even something as simple as direct bit banging was the TIP OF THE ICEBERG for all of firmware
@artfulbytes
@artfulbytes 11 ай бұрын
Thanks! haha yep, lots of details hiding underneath :)
@olivialinden8699
@olivialinden8699 Жыл бұрын
👍
@user-sj9kh4pf7n
@user-sj9kh4pf7n Жыл бұрын
Only now I've realized: TI - Texas Instruments😁🤣
@artfulbytes
@artfulbytes Жыл бұрын
😁
@zDoubleE23
@zDoubleE23 4 ай бұрын
Any good sources where the preprocessors like #ifndef, #end, etc are explained and exemplified with use cases?
@artfulbytes
@artfulbytes 4 ай бұрын
No resource to cover them all, I've just picked it up here and there. But as I mention somewhere in the series, avoid them when you can because they can lead to hard-to-debug issues down to road.
@3deesuk
@3deesuk Жыл бұрын
in 16:55 min , what is pin_bit? i understand pin number and port number. what is different between io_pin_bit and io_pin_idx? (io & IO_PORT_MASK) >> IO_PORT_OFFSET this gives port 0 instead of port one for IO_10?
@artfulbytes
@artfulbytes Жыл бұрын
pin_bit is the bit value and pin idx is the position idx of that bit value. For example, for pin number 7, the bit value (pin_bit) is 0b10000000 (dec: 128), the 7th bit is set. Pin idx is 7, because it's the 7th bit position. For pin number 3, the bit value is 0b00001000 (dec: 8), and pin idx 3. Yes (io & IO_PORT_MASK) >> IO_PORT_OFFSET gives value 0 for IO_10. But in io_port_e enum, value 0 corresponds IO_PORT1 (there is no IO_PORT0). I did it like this because in TI calls the first port 1 (not 0) in the datasheet.
@pablocabellojordan2943
@pablocabellojordan2943 7 ай бұрын
Hi there, just found this channel, and this is exactly what I would love to do. I'm learning self-taught, but gets to hard for me. Can you please tell me something like a routemap so I can use to study?. (Something like: first you have to learn C, then electronics, then ...).
@artfulbytes
@artfulbytes 6 ай бұрын
Firstly, I would just focus on writing programs in C without any microcontroller, just programs running on your host machine, to get familiar with it. Once you feel somewhat comfortable you can pick up a simpler microcontroller, like an 8-bit one. Start small. Try to blink an LED with a GPIO, detect a button press with interrupt, hook up a sensor and write a driver to talk to it learning about uart/i2c/spi... You will have to do some simple circuits to connect things so you will learn some electronics as you go along. You don't need to be an expert in electronics if you purely want to focus on embedded software. Also I don't like the word "study", you don't learn embedded systems by reading a book, you learn by doing. Note, I'm not saying you shouldn't read, but that you should read what you need to know to do what you want to do. So not "How to learn C", instead more "How do I blink an LED with GPIO on the microcontroller I have in front of me"... Something like that :)
@ReganeKegane-wq9by
@ReganeKegane-wq9by 9 ай бұрын
Ok
@bhojasd
@bhojasd 19 күн бұрын
CAN YOU PLEASE MAKE VIDEOS IN SLOW MANNER ....YOU MOVED FAST FARWARD YOUR CODE WHICH IS VERY UNCOMFORTABLE TO UNDERSTAND FOR ME
@bhojasd
@bhojasd 19 күн бұрын
NEXT TIME PLEASE DON DO FARWARDING OF CODE PORTION .......PLEASE MAKE IT SLOW AND ALSO TALK SLOWLY ....LOVE FROM INDIA
100❤️
00:19
MY💝No War🤝
Рет қаралды 23 МЛН
Llegó al techo 😱
00:37
Juan De Dios Pantoja
Рет қаралды 49 МЛН
HAPPY BIRTHDAY @mozabrick 🎉 #cat #funny
00:36
SOFIADELMONSTRO
Рет қаралды 18 МЛН
Microcontroller Interrupts | Embedded System Project Series #17
54:40
Bare-Metal MCU #1 - Intro to registers
13:10
Mitch Davis
Рет қаралды 69 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 775 М.
Rust's Alien Data Types 👽 Box, Rc, Arc
11:54
Code to the Moon
Рет қаралды 139 М.
Extracting Firmware from Embedded Devices (SPI NOR Flash) ⚡
18:41
Flashback Team
Рет қаралды 558 М.
What was Coding like 40 years ago?
29:05
The Coding Train
Рет қаралды 1,7 МЛН
Samsung laughing on iPhone #techbyakram
0:12
Tech by Akram
Рет қаралды 2,6 МЛН
Я купил первый в своей жизни VR! 🤯
1:00
Todos os modelos de smartphone
0:20
Spider Slack
Рет қаралды 60 МЛН
Самые крутые школьные гаджеты
0:49
Xiaomi SU-7 Max 2024 - Самый быстрый мобильник
32:11
Клубный сервис
Рет қаралды 410 М.