How to Blink an LED in C (avr, msp430)

  Рет қаралды 34,799

Jacob Sorber

Jacob Sorber

Күн бұрын

Пікірлер: 78
@kenwallace6493
@kenwallace6493 4 жыл бұрын
You are correct! The biggest snag to embedded programming in bare metal is poor documentation. The first thing I look for is the pointer constants to the configuration registers. Next is the labels they pick and the structure so one knows the syntax to manipulate these registers. This information is often scattered or poorly formatted or obscured by levels of abstraction that confuses the "bare metal" level with higher levels. I personally don't think bit definitions are worth it, too many and you still need the spec sheet definition of the register bits for many peripherals. Finally, the Makefile approach where one is setting compiler options/flags is downright scary - I never feel confident that I can get these all right. Keep up the detail on this. Think about a session on ARM microcontrollers in the future (such as the Bluepill). Great stuff.
@KangJangkrik
@KangJangkrik 2 жыл бұрын
Even today most 3D printers (for hobbyist) are coded with Arduino libraries, because bare metal straight down to dangerous level which makes undefined behavior seldomly happen
@laca103
@laca103 2 жыл бұрын
I've learned more embedded stuff during 60 minutes of your videos, than during a whole semester of my "MCU programming class" as part of my EE Bsc...
@grassrootfilms
@grassrootfilms 2 жыл бұрын
If you go the AVR path, make sure you go get the Atmel datasheets on the MCU you're working with and read through it some. Things like DDRB seem scary and cryptic until you see in the datasheet that means "Data Direction Register - Port B". Then everything else Jacob explains is like, "Oh, I see!!!" There is a ton of info in those involving the timers and comparators and some of that is just magical with how well it works.
@ChristianDeutinger
@ChristianDeutinger 3 жыл бұрын
exactly the information for msp430 i have been locking for the last 10 years :-)
@lucianopavarotti4715
@lucianopavarotti4715 4 жыл бұрын
Dude, thank you so mcuh! Hope to see more content on MSP430 capabilities.
@JustinCromer
@JustinCromer 3 жыл бұрын
Great video! This is easily a few weeks worth of material just playing with different options!
@bastawa
@bastawa 4 жыл бұрын
I think the bigger snag to embedded programming is using RTOS. You get an extra unknown (RTOS version can work with one specific version of the compiler) etc. If you add an extra library to the equation your build process complexity grows exponentially. I had one project for which I didn't document my toolchain (I wasn't aware of those headaches at that time). One year later it took me around 8 hours to build and upload it again! This was TI Tiva TM4xxxxx. You get an error, nobody had it before, you look the header files they don't have symbols they should have or renamed them etc. I have 3 TI development kits and I haven't been using them for a long time due to build process / flashing firmware problems.
@g.1100
@g.1100 4 жыл бұрын
thanks for the video. Great work getting under the hood. I take so many things for granted with my IDE :)
@JacobSorber
@JacobSorber 4 жыл бұрын
Yeah, most people do.Glad you enjoyed it.
@jwd.t
@jwd.t 4 жыл бұрын
I've been working for quite a few time on TI's CC2650 launchpad MCU and man, the documentation and function / register abstraction is like an endless maze, total nightmare !! I've never felt so helpless working with embedded systems before in my life.
@JacobSorber
@JacobSorber 4 жыл бұрын
Agreed. I actually stopped using the CC2650 in my research for that reason. It was just too difficult to get clear answers.
@ckafrouni
@ckafrouni 4 жыл бұрын
Hey! Thanks a lot for the video, got me started on an arduino I got as a gift about a year ago!! I just wanted to specify the command to install avr-gcc on macs has changed. It is now: "brew tap osx-cross/avr && brew install avr-gcc" Thanks again, looking forward to watch more of your videos.
@arturfil
@arturfil 4 жыл бұрын
I was about to post a comment about that, might as well just post the link to the github link
@kirillyatsenko5365
@kirillyatsenko5365 4 жыл бұрын
Hello, great video! Can you please recommend some resources(courses/books) to learn this in-depth embedded programming?
@sylvestrestalin
@sylvestrestalin Жыл бұрын
I wish there was one or two more videos between the previous video and this one. I'm having a hard time understanding changing the register's values and what's happening and more about how the compiler and uploader work and their options and what not.
@redflags30
@redflags30 9 ай бұрын
same here, a bridging video would help, but still, a great video of how embedded systems engineers work
@arturfil
@arturfil 4 жыл бұрын
To install arv-gcc on OSX the new commands are: brew tap osx-cross/avr brew install avr-gcc
@LANstorm.
@LANstorm. 4 жыл бұрын
ok
@khomo12
@khomo12 8 ай бұрын
Very nice, from an undergrad!👍👍👍
@kameswarchembrolu9211
@kameswarchembrolu9211 4 жыл бұрын
Hi Jacob. I am Kamesh and an active follower of your channel. I am an embedded systems engineer and I really found your videos related to C programming and Data structures very helpful. Can you make more videos of data structures implementations and development in C. Because there aren't many good resources as yours about C.
@JacobSorber
@JacobSorber 4 жыл бұрын
Thanks, Kamesh! Yes, I have more data structure videos planned. Let me know if you have specific requests.
@MichaelDiedricks
@MichaelDiedricks 3 жыл бұрын
Thanks for this great video series. I really appreciate the informative content you're putting out here for us all. I see you're using VS Code - I was wondering if you use any extensions that assist you in embedded programming? Also, do you have a good way of managing header files - by this I mean in the way you might manage dependencies in web development. Is there a good way of doing this, or are you simply downloading the header files from TI and making sure to keep them up to date? Cheers
@oliveira_mh
@oliveira_mh 3 жыл бұрын
Very interesting video, and high quality content. I have a doubt. How do you configure vscode to work with avr-gcc? Where did you define the microcontroller you are using for vscode to recognize DDRB?
@sc5shout
@sc5shout Жыл бұрын
On the university we've got atmega 1284p and to turn on the LED we use this: #define LED_PIN (1
@manofmesopotamia7602
@manofmesopotamia7602 3 жыл бұрын
Thanks for your efforts 🙂, I used to work on Arduino, but I need to move to next level, I see Tons of ARM MCUs chips on AliExpress, I wish that I could use Keil Uvision to program any chip, but I dont know how to start, I wish if you could have some tutorial in future on how to read the programming manual and explain them, coding on Uvision and make cool stuff. I wish you got my point. Thanks
@mihirluthra7762
@mihirluthra7762 4 жыл бұрын
The link provided in the description uses a very old version on avr-*. On running those on macOS Catalina, it would say Bad CPU type in executable. To make the things a little simpler I would suggest to use a package manager like macports.
@JacobSorber
@JacobSorber 4 жыл бұрын
Ah, good to know. I haven't upgraded to Catalina yet. I always patch quickly, but hesitate with major OS versions, because each of Apple's upgrades tend to break one of the cross compilers or other tools that I'm using. Yes, macports or homebrew should probably work fine, as an alternative. Thanks.
@bastawa
@bastawa 4 жыл бұрын
Great video as usual!!!!
@JacobSorber
@JacobSorber 4 жыл бұрын
Thanks.
@MegaHatef
@MegaHatef 4 жыл бұрын
Thanks for the great video! CCS provides a neat debugging interface where you can see all registers states, etc. Im so curious if we can have such a thing when we are using non-IDE ENV. I was wondering if you have any video/plan to create video about that. Thanks.
@nenojay6832
@nenojay6832 4 жыл бұрын
awesome video!!! Thank you! I wish you included the source code or a github repo
@JacobSorber
@JacobSorber 4 жыл бұрын
It's available here. jsorber-youtube-source.herokuapp.com/
@chakreshjoshi4302
@chakreshjoshi4302 2 жыл бұрын
Thanks
@19thGreenY
@19thGreenY 4 жыл бұрын
Thanks for the video, its awesome! I'm very new to embedded systems but I got to know that C is the common language as of now. But there C++ is gaining popularity. Can I choose to learn embedded programming in C++ instead of C?
@JacobSorber
@JacobSorber 4 жыл бұрын
Absolutely, just be careful. Make sure you understand what those C++ features are doing for you. Things like classes should be fine. Things like dynamic memory allocation (new) could get you into trouble, especially if you have very little memory. Virtual methods can add some delays, which may or may not be a problem. C++ is just more complicated, and so there are more things that beginning programmers often don't understand that can cause problems that seem like magic.
@anfield6321
@anfield6321 3 жыл бұрын
The easiest way to install the compiler and debugger for msp430(on debain systems): apt-get install gcc-msp430 apt-get install mspdebug
@JacobSorber
@JacobSorber 3 жыл бұрын
Cool. Thanks. Sadly, it's not quite as easy on macOS.
@aabdev
@aabdev 3 жыл бұрын
There was mentioned JTAG at 1:54. Is that possible to describe how JTAG works under the hood (e.g. setting breakpoints)?
@shekharmaela2308
@shekharmaela2308 4 жыл бұрын
I disagree about IDEs getting in the way. I'm right now using Xcode as a GUI to lldb in order to find where I need to modify code to add a new feature.
@JacobSorber
@JacobSorber 4 жыл бұрын
Yeah, sorry if I gave you the wrong IDEa. I'm ok with using IDEs as long as they behave themselves. I think they're problematic when new programmers are learning, because they hide stuff, but I sometimes use them myself, and in certain situations they can definitely simplify things.
@mikelemon5109
@mikelemon5109 4 жыл бұрын
Awesome vid but you make it seem like a childs play learning how to program those MCUs but what if someone starts deving with another MCU type (say Nordic NRF52) How'd you approach it what and where should you look for syntax and setting(weird unexpected port lock and watchdog timer register editing) you have to put to make the code go better? after all debug won't help at all and that's all knowledge based.
@mikelemon5109
@mikelemon5109 4 жыл бұрын
OK wrote it after pausing at 10:00 lol
@JacobSorber
@JacobSorber 4 жыл бұрын
I know. Maybe I should have mentioned that at the beginning of the video. :)
@sakshisingh8167
@sakshisingh8167 3 жыл бұрын
PLEASE DO STM32F407VG DISCOVERY BOARD
@terzerk2165
@terzerk2165 2 жыл бұрын
Could you do a makefile for windows, i have tried but i can't get it to work. Thanks
@shivam4428
@shivam4428 4 жыл бұрын
du u know kernel programming ?
@JacobSorber
@JacobSorber 4 жыл бұрын
I have done some kernel programming, though I haven't done much lately. What did you have in mind?
@shivam4428
@shivam4428 4 жыл бұрын
@@JacobSorber please share with us. i am basically going towards device drivers . just started character device driver and has completed ipc and sockets programming. i was looking for valgrid ,found on your channel. now in parellel to kernel development also focusing on memory management tools.
@JacobSorber
@JacobSorber 4 жыл бұрын
@@shivam4428 I'll see what I can do. A kernel dev video would be pretty involved. So, I wouldn't expect it in the next month or two. I'm still not clear on what sort of memory mgmt tools you're interested in. Are these kernel-level tools or application-level?
@shivam4428
@shivam4428 4 жыл бұрын
@@JacobSorber ok i will be waiting for videos. tools for booth application +kernel .
@ShreyanNag
@ShreyanNag 4 жыл бұрын
Please make videos on Pointers.
@JacobSorber
@JacobSorber 4 жыл бұрын
I have some older videos on pointers. kzbin.info/www/bejne/q4WQin97fdyJiZY kzbin.info/www/bejne/oWeohJ5vr8aZfq8 kzbin.info/www/bejne/l6nRmKp6f5xsfbs I'm sure I haven't covered everything. Let me know what you think I'm missing.
@konstantinrebrov675
@konstantinrebrov675 4 жыл бұрын
A LED, not an. "An" is only for consonants. Great video by the way.
@JacobSorber
@JacobSorber 4 жыл бұрын
Thanks. I'm not sure I want to get into grammar debates on the channel, but I disagree. I've heard various opinions on this, and there seems to be some debate online. I prefer using "an" with acronyms that sound like they start with a vowel, like LED or RPG when read. The benefit is that it sounds correct when read it aloud, and it seems to be the most common opinion. More reading... www.grammar.com/a-vs-an-when-to-use/ www.shearsoneditorial.com/2013/07/a-or-an-with-abbreviations-it-depends/ web.archive.org/web/20160916082929/alt-usage-english.org:80/excerpts/fxaanbef.html blog.apastyle.org/apastyle/2012/04/using-a-or-an-with-acronyms-and-abbreviations.html
@zakiabdinasiromar5434
@zakiabdinasiromar5434 6 ай бұрын
It's 'an' LED. Reason being the pronunciation. It's pronounced as 'El' then 'ee' then 'D'. First letter is a vowel therefore an used. Spelling wise, 'LED'. Why it's that way? I have no idea. It is something we'll have to ask the English.
@aghorn
@aghorn 4 жыл бұрын
The two make links under Related videos don't work.
@JacobSorber
@JacobSorber 4 жыл бұрын
Thanks for the heads up. That's strange. They used to work. They should work now.
@aghorn
@aghorn 4 жыл бұрын
@@JacobSorber Yes, thanks. They work for me now.
@aumpatel2225
@aumpatel2225 Жыл бұрын
hey can anyone help me implement this on windows
@yvaneke580
@yvaneke580 2 жыл бұрын
i don't know how but the video is not i sync with the audio..
@mihirluthra7762
@mihirluthra7762 4 жыл бұрын
avrdude: stk500_recv(): programmer is not responding Have searched many forums but didn't get any working solution. Any ideas?
@JacobSorber
@JacobSorber 4 жыл бұрын
Hard to say from here. Have you tried another Arduino? Maybe a driver issue? Depending on what OS you're using, you can sometimes figure out what's happening by looking at the system logs (syslog or dmesg). If there are any issues recognizing a USB device it often shows up there.
@mihirluthra7762
@mihirluthra7762 4 жыл бұрын
​@@JacobSorber​Maybe yes, I should try with another arduino. It doesn't work with arduino IDE either. Although syslog or dmesg have no mentions about such things, Anyways, still a great video as always! Love your channel
@mihirluthra7762
@mihirluthra7762 4 жыл бұрын
@@JacobSorber Right, I tested it with another arduino and it works.
@JacobSorber
@JacobSorber 4 жыл бұрын
@@mihirluthra7762 Embedded systems are fun, aren't they? Glad you got it sorted.
@mihirluthra7762
@mihirluthra7762 4 жыл бұрын
Yep surely are. More when we know what's going under the hood.
@kenwallace6493
@kenwallace6493 4 жыл бұрын
One more rant and I'll shut up. Embedded microcontrollers are complex devices so managing that complexity is key to more universal use of them and more jobs programming them. Folks (like me) who design the product (e.g. solar inverters) simply cannot divert the time and effort into becoming professional computer programmers just to get that job done. We know the detail functions required and we know microcontrollers have great advantages, we just need a simpler "cookbook" to access them at a low level. Asking a professional programmer to "fix" this complexity usually results in further levels of abstraction with greater risk of not knowing what's really going on. In Power Conversion, one is always a microsecond from disaster so that is not an option.
@JacobSorber
@JacobSorber 4 жыл бұрын
I know. Especially if you get a professional developer who trained outside of embedded systems. The tension between abstraction (and all the benefits that come with it) and keeping things tight and simple is really common.
@hendrykhoza4782
@hendrykhoza4782 4 жыл бұрын
On your last video, you mention youre in africa... Which country are you on?
@JacobSorber
@JacobSorber 4 жыл бұрын
I was in Botswana. I'm now back in the US.
@hendrykhoza4782
@hendrykhoza4782 4 жыл бұрын
@@JacobSorber oOh, Great. I'm From South Africal., I just discovered your chanel and I really love it.
@hendrykhoza4782
@hendrykhoza4782 4 жыл бұрын
@@JacobSorber Any Article that you know off where I can read more about compiling C code for Arduino UNO
@henryzhang7243
@henryzhang7243 4 жыл бұрын
Jacob, add delay() waits CPU time. This way cannot pass job interview. Not a good example for Blink even all vendors just use this way for demon purpose.
@JacobSorber
@JacobSorber 4 жыл бұрын
I'm not sure I follow. Are you saying that I shouldn't show examples that aren't job-interview grade solutions? I'm going for simplicity here. If it's your first experience with microcontroller programming under the hood, I'm going with the simplest thing that works. I'll show you how to do it with timers and sleep modes in a future video.
@ropersonline
@ropersonline 3 жыл бұрын
8:02: "avrduded -F -V"
How to Blink LEDs with Timers and Interrupts in C (MSP430, Arduino)
14:32
The Multiple Paths through Embedded Systems
29:04
Jacob Sorber
Рет қаралды 10 М.
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 6 МЛН
How does fork work with open files?
13:12
Jacob Sorber
Рет қаралды 10 М.
Creating your own custom hardware (printed circuit boards)
12:36
Jacob Sorber
Рет қаралды 39 М.
How to use an ADC (embedded example in C)
14:56
Jacob Sorber
Рет қаралды 30 М.
How to make memory read-only in your C programs.
12:57
Jacob Sorber
Рет қаралды 20 М.
Using GPIO with the MSP430 Microcontroller
20:42
MSP430 Training
Рет қаралды 22 М.
Your first microcontroller project!
19:44
FriendlyWire
Рет қаралды 69 М.
A Beginner's Guide to Microcontrollers
15:18
Electronic Wizard
Рет қаралды 45 М.
Using tabs to organize code with the Arduino IDE
12:18
Programming Electronics Academy
Рет қаралды 60 М.