Poll

How to write embedded c program from datasheet?

a
2 (50%)
b
2 (50%)

Total Members Voted: 4

Author Topic: How to start embedded progrmming  (Read 1961 times)

0 Members and 1 Guest are viewing this topic.

Offline mathanTopic starter

  • Newbie
  • Posts: 7
  • Country: in
How to start embedded progrmming
« on: September 21, 2018, 11:34:52 am »
hello all,
          I have just begin embedded c programming, I am on the learning process can anyone help me for how to write the program from  datasheet? if any website or forum available for that please provide the details :)

THANKS IN ADVANCE ;)
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: How to start embedded progrmming
« Reply #1 on: September 21, 2018, 11:39:27 am »
Your missing just a few details...

E.g. maybe a link to the datasheet??

What your intending to use it for??

Do you have any prior knowledge of programming languages?
 

Offline rjp

  • Regular Contributor
  • *
  • Posts: 124
  • Country: au
Re: How to start embedded progrmming
« Reply #2 on: September 21, 2018, 11:39:59 am »
you may have more success if you tell people where you are embedding the c.
 

Offline mathanTopic starter

  • Newbie
  • Posts: 7
  • Country: in
Re: How to start embedded progrmming
« Reply #3 on: September 21, 2018, 12:07:40 pm »
Hi Rerouter,
               Thanks for your reply. I know basic C language and i able to understand programs ( i have read several pic24f programs). now i m trying to write basic program like toggle the LED. I have saml21j18b development board so I want to make simple program by whatever the details that provided in the datasheet itself  :)
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: How to start embedded progrmming
« Reply #4 on: September 21, 2018, 12:28:31 pm »
Ok to begin with, It appears this development board is intended to be used with "Atmel Studio", This is an "IDE" for writing the software to run on the device.

To write microcontroller software, generally the IDE's will have a "Library" of common code to make things more plug and play, similar to what the arduino enviroment does, keeping the harder stuff hidden,

But if you just want to dive right in, the device has various "Peripherals" there are specific purpose bits of hardware that generally let you do cool things, without having to be actively looked after by the CPU,
simple Examples would be an ADC, (Analog to digital converter, he measures voltages and spits out a number for the reading), Timers (Can be used to count pulses or the time between pulses, or as an alarm), USART/UART's (Serial In and out), SPI (Mostly the same just generally faster), TWI (Small cheap external sensors)

Then when you get to higher performace there are more peripherals that can pull off some real magic like the DMA Controller (Direct Media Access), you pretty much tell him to copy from X to Y and how many bytes and he will handle the transfer with the CPU free to do what it wants, getting a flag when the transfer is done,

These peripherals are set up with "Registers", where certain bits switch certain functions of those peripherals to behave how you want it, the datasheet should go into high detail on what each register controls,

But to honestly just toggle an LED, your likely looking at I/O, setting a pin as an output, then changing its state after X amount of time, If it has that library of macros like i mentioned at the start its likely something like: pinMode A11 Output;  digitalWrite A11 True; delay(1000); digitalWrite A11 False; delay(1000);
 
The following users thanked this post: mathan

Offline mathanTopic starter

  • Newbie
  • Posts: 7
  • Country: in
Re: How to start embedded progrmming
« Reply #5 on: September 21, 2018, 12:41:32 pm »
Thank you for your detailed reply. I never expect this kind of explanation which is more helpful for me and broke some hesitation inside of me to ask questions in the forum :) :)
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 6201
  • Country: ro
Re: How to start embedded progrmming
« Reply #6 on: September 21, 2018, 01:20:19 pm »
The best I've seen so far:



From how to install the IDE and blink a LED, up to RTOS and multithread debugging. Some key hardware about the ARM architecture are explained, some C particularities important for embedded programming also shown.

Take each lesson, one by one, and do yourself the steps and exercises from the video.
 
The following users thanked this post: mathan

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: How to start embedded progrmming
« Reply #7 on: September 21, 2018, 02:19:27 pm »
Writing a program directly from a datasheet is an advanced topic in that you are blowing off all of the supplied libraries (if there are any) and starting from bare iron.  That was pretty common about 10 years ago because there weren't any libraries.  I'm think back to my work with the ATmega128, LPC2106 and LPC2148.  For the LPC chips there was an assembly language startup file that was pretty common but once the code branched to main(), you were on your own.  For the ATmega, there was AVR-libc, a very nice library that doesn't overwhelm you if you don't need some of the features.

Today we have HALs (Hardware Abstraction Layers) and some factory tools like STM32CubeMX (for STM32F devices) that generate skeleton code based on how you graphically set up the pins.  These are good and bad.  They generate an enormous amount of very general purpose code and they hide the bare iron.  Good and bad...  You didn't write the code and you will spend a very long time figuring out how it works.  In the end, you will probably chuck it and write to the bare metal.  But it's helpful as a starting point and for proof of concept.

Then there is the Arduino approach which I recommend as a starting point.  Why?  Because everything that can be done with an Arduino has been done and the code is on the Internet.  You learn about IO, ADC, SPI, I2C and a host of other concepts using libraries provided by others.  But mostly, you get to copy and paste from projects on the Internet.

What you propose, starting from bare iron, in a modern device is going to be a big climb.  The startup code alone, just getting peripherals powered up and clocks ticking away, is going to be a learning experience.  It isn't enough to go to the section of the datasheet related to some widget and follow along, you need to start way back and figure out how to turn the peripheral on and get it a clock.  The reason for this is that peripherals don't consume power when they are turned off and not clocked.  Low power is the theme.

There's a book "Mastering the STM32" that will be a great help in getting started with STM32 devices.  It begins with installing the toolchain and works up.  But it is for STM boards.  I haven't looked for books related to Atmel devices.

I'm going to highly recommend you start with the Arduino and get some experience.  A lot of folks will say that Arduino isn't serious enough but you need to start somewhere.  Given all the example code on the Internet, the Arduino is a nice starting point.

Have fun!

 
The following users thanked this post: mathan

Offline Mattjd

  • Regular Contributor
  • *
  • Posts: 230
  • Country: us
Re: How to start embedded progrmming
« Reply #8 on: September 21, 2018, 02:41:33 pm »
get an msp430, and program from datasheet. Use CCS. TI has a shit ton of example code that doesnt utilize its driver library, and you can actually learn how to use peripherals. For any given development board there are three datasheets you will want. The development board datasheet, the processor datasheet, and then the processor family datasheet. Each gives different levels of information for what you want. For example, the processor datasheet will you exactly what is on each pin of the processor, and how many CC Registers Timer A has. It will also give you electrical characteristics. The processor family datasheet gives you information about exact register settings ie setting what pin in what register does what. The development board datasheet will help you connect stuff to the board, it will give you diagrams of what peripherals are connected to what GPIO and how to multiplex their various functions.
 
The following users thanked this post: mathan

Offline rjp

  • Regular Contributor
  • *
  • Posts: 124
  • Country: au
Re: How to start embedded progrmming
« Reply #9 on: September 22, 2018, 01:31:56 am »
Id second arduino if you are starting at the start-start.

you need to learn c ,  you need to learn the basics of the gpio and peripherals and you need to learn electronics.

all this before you can even build the simplest of circuits.

after that start removing the helper layers and seeing how the actual chips work - one thing to remember is that all the simplified frameworks and HAL's have the baremetal layer exposed within them , so its perfectly sensible to get the chip up and running using them and then move away from that one section of code at a time.
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 6201
  • Country: ro
Re: How to start embedded progrmming
« Reply #10 on: September 22, 2018, 02:58:42 am »
The problem with Arduino is that, in the long run, it can be a major drawback.
It's good to start, especially if you want just to play with it without any professional ambitions, because there are a lot of examples and demos, but otherwise Arduino is a mess.
 
The following users thanked this post: rs20

Offline rjp

  • Regular Contributor
  • *
  • Posts: 124
  • Country: au
Re: How to start embedded progrmming
« Reply #11 on: September 22, 2018, 04:04:44 am »
The problem with Arduino is that, in the long run, it can be a major drawback.
It's good to start, especially if you want just to play with it without any professional ambitions, because there are a lot of examples and demos, but otherwise Arduino is a mess.

this is only the case if you assume someone is incapable of learning once the initial hump is overcome, which in my experience is not true.

if you dont have experts around you, learning how to code whilst learning electronics circuits whilst setting up your first circuit on barely documented ARM breakout and getting all the toolchain and headers right..  is also a mess :)


« Last Edit: September 22, 2018, 04:08:34 am by rjp »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: How to start embedded progrmming
« Reply #12 on: September 22, 2018, 02:45:38 pm »
With the Arduino you have a 100% chance of having a blinking LED in less than an hour from the time you start downloading the IDE.  It's probably closer to 10 minutes.

1) Install IDE and launch
2) Click File->Examples->Basics->Blink to open an example file
3) Click Tools->Board and select board type (UNO is a good board for beginners)
4) Click Sketch->Upload (Ctrl-U)  to compile and upload the program
5) Watch the blinking light.

It's a start...

Nearly every new embedded system starts with a blinking LED.  An enormous amount of stuff must be correct for this to actually work.

And then it's off to the races!
 

Offline Mattjd

  • Regular Contributor
  • *
  • Posts: 230
  • Country: us
Re: How to start embedded progrmming
« Reply #13 on: September 22, 2018, 03:54:17 pm »
With the Arduino you have a 100% chance of having a blinking LED in less than an hour from the time you start downloading the IDE.  It's probably closer to 10 minutes.

1) Install IDE and launch
2) Click File->Examples->Basics->Blink to open an example file
3) Click Tools->Board and select board type (UNO is a good board for beginners)
4) Click Sketch->Upload (Ctrl-U)  to compile and upload the program
5) Watch the blinking light.

It's a start...

Nearly every new embedded system starts with a blinking LED.  An enormous amount of stuff must be correct for this to actually work.

And then it's off to the races!

you can literally do the same thing on an MPS430. You download code composer studio, which will probably take longer than 10 minutes, but once you get it up and running, you create a project you the option of it being empty, LED Blink, or Hello World , or something else which i forget.


« Last Edit: September 22, 2018, 03:57:40 pm by Mattjd »
 

Offline Mattjd

  • Regular Contributor
  • *
  • Posts: 230
  • Country: us
Re: How to start embedded progrmming
« Reply #14 on: September 22, 2018, 04:00:08 pm »
The TI resource explorer where you can find examples for any and all peripherals on a board


http://dev.ti.com/tirex/#/


« Last Edit: September 22, 2018, 04:02:16 pm by Mattjd »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: How to start embedded progrmming
« Reply #15 on: September 23, 2018, 09:10:57 am »
I remember a TI Lauchpad/CCS tutorial where “now plug in the board” was about step number 25.
Hopefully it’s improved since then!  (I guess you can just run Energia, now)

(Ahh.  It was the stellaris launchpad.  “Step 25: open the box”, in this tutorial:  http://software-dl.ti.com/trainingTTO/trainingTTO_public_sw/GSW-Stellaris-LaunchPad/StellarisLaunchPadWorkbook.pdf
)

« Last Edit: September 23, 2018, 09:39:06 am by westfw »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf