Learning to code a random MCU....

Thread Starter

Nathan Hale

Joined Oct 28, 2011
143
Hello Everyone, hope you all are doing great!

So, I got this arduino kit from amazon a while ago, and I have been building small projects with the help of a book that came with the kit.
So basically, I am able to take the help of the book and the arduino website with its reference page etc to build stuff. Apparently arduino is based on the ATMEL ATMEGA IC.

Now, lets say I buy an NXP FS32K144UAT0VLLT 32-bit Automotive General Purpose Microcontroller and try to blink an LED with it, like I did with the arduino. Where would some one get all the necessary information from? The NXP website doesn't provide all the necessary info, on a nice platter, to teach people how to blink an LED with their microcontroller. I know you would probably say , the reference manual.
But, how do you "pick out" the info that you want from that 2000 page manual?

Let me make myself more clear.
Lets say, I would like to have a small delay before my LED turns off. I would use, delayMicroseconds() in the arduino code.
delayMicroseconds() is custom made for the arduino and arduino just gets what I mean when i put delayMicroseconds() in the code .

Now, lets say, I want to do the same task with the fancy NXP FS32K144UAT0VLLT 32-bit Automotive General Purpose Microcontroller, I dont know how to and where to begin, because the 2000 page reference manual does not have delayMicroseconds listed in it. Obviously, the NXP FS32K144UAT0VLLT 32-bit Automotive General Purpose Microcontroller, most likely has its own way of introducing a small delay before the LED turns off.
Now, how would YOU personally go and dig up such info so that you would be able to introduce a small delay before your LED turns off? How would you know what sentence/structure/code word to use?
If I uploaded the following arduino code, to blink an LED, into the code of the NXP FS32K144UAT0VLLT 32-bit Automotive General Purpose Microcontroller it would most likely come up with a million errors.

voidsetup(){
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN,OUTPUT);
}

// the loop function runs over and over again forever
voidloop(){
digitalWrite(LED_BUILTIN,HIGH);// turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN,LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}



Well, I guess my question is more about how to make sense of the reference manual. Just how do you gentlemen dig out the info from a ref manual? Do they all look completely different but are in essence the same? Is there a book you would recommend me reading to more easily follow reference manuals?
Thank you in advance for your replies.

p.s. I must tell you that I did "code" one of there random microcontrollers in college, but always got stuck extracting info from the manual in order to write the code. When I asked my prof how he extracted coding information from the manual, I didnt get a clear answer, and thought you guys might be able to answer/ help better. I used "Code Warrior" to program the microcontroller and it was some Freescale MCU.
 
Last edited:

danadak

Joined Mar 10, 2018
3,573
"Normally" the IDE will have example projects, in C and / or C++.

Arduino is a set of functions you can call and use in code, like delay. IDEs for
other processors may or may not have predefined library functions. You will
find those typically in the compiler manual.


Regards, Dana.
 

MrChips

Joined Oct 2, 2009
19,270
There are code standards for any given language.
ANSI C is a standard that all ANSI C compilers ought to adhere to in order to be compatible. If you write code using the ANSI C standard then you should be able to port the code from one MCU to another.

For example, sprintf( ) is a standard C function. Its usage ought to be universal across all ANSI C compatible compilers.

delayMicroseconds( ) is not an ANSI C function. It is a function supplied by the platform library.
There are many ways to implement such a function, in software and in hardware. Such implementation will depend on the processor's clock. Hence the user has to have some mechanism for specifying the clock frequency.

The User Manual of XYZ MCU will show you how to use the internal hardware modules of the MCU and how to program the MCU at the machine level or assembler code level. If you want to program the MCU in C, look at the IDE (Integrated Development Environment) recommended by the MCU manufacturer.

If you examine the IDE you will usually find examples on how to use the hardware, including how to access a delay function in the supplied libraries.

In general, be expected to do some editing when porting C code from one MCU to another. The internal hardware and all pin assignments will be different. It takes considerable foresight, planning and code organization if you foresee porting code from one MCU to another.

(This is one reason why you should not get too attached to Arduino.)
 

Papabravo

Joined Feb 24, 2006
12,389
Hello Everyone, hope you all are doing great!

So, I got this arduino kit from amazon a while ago, and I have been building small projects with the help of a book that came with the kit.
So basically, I am able to take the help of the book and the arduino website with its reference page etc to build stuff. Apparently arduino is based on the ATMEL ATMEGA IC.

Now, lets say I buy an NXP FS32K144UAT0VLLT 32-bit Automotive General Purpose Microcontroller and try to blink an LED with it, like I did with the arduino. Where would some one get all the necessary information from? The NXP website doesn't provide all the necessary info, on a nice platter, to teach people how to blink an LED with their microcontroller. I know you would probably say , the reference manual.
But, how do you "pick out" the info that you want from that 2000 page manual?

Let me make myself more clear.
Lets say, I would like to have a small delay before my LED turns off. I would use, delayMicroseconds() in the arduino code.
delayMicroseconds() is custom made for the arduino and arduino just gets what I mean when i put delayMicroseconds() in the code .

Now, lets say, I want to do the same task with the fancy NXP FS32K144UAT0VLLT 32-bit Automotive General Purpose Microcontroller, I dont know how to and where to begin, because the 2000 page reference manual does not have delayMicroseconds listed in it. Obviously, the NXP FS32K144UAT0VLLT 32-bit Automotive General Purpose Microcontroller, most likely has its own way of introducing a small delay before the LED turns off.
Now, how would YOU personally go and dig up such info so that you would be able to introduce a small delay before your LED turns off? How would you know what sentence/structure/code word to use?
If I uploaded the following arduino code, to blink an LED, into the code of the NXP FS32K144UAT0VLLT 32-bit Automotive General Purpose Microcontroller it would most likely come up with a million errors.

voidsetup(){
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN,OUTPUT);
}

// the loop function runs over and over again forever
voidloop(){
digitalWrite(LED_BUILTIN,HIGH);// turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN,LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}



Well, I guess my question is more about how to make sense of the reference manual. Just how do you gentlemen dig out the info from a ref manual? Do they all look completely different but are in essence the same? Is there a book you would recommend me reading to more easily follow reference manuals?
Thank you in advance for your replies.

p.s. I must tell you that I did "code" one of there random microcontrollers in college, but always got stuck extracting info from the manual in order to write the code. When I asked my prof how he extracted coding information from the manual, I didnt get a clear answer, and thought you guys might be able to answer/ help better. I used "Code Warrior" to program the microcontroller and it was some Freescale MCU.
You stick with CPUs that have a manual that you find "tractable". If you want to use the device with a 2000 page manual for economic reasons then you dig in ASAP, because you're not digesting the 2000 pages if you don't start on page 1. I'm sure there is something out there just for you.
 
Top