Showing posts with label Embedded C Programming. Show all posts
Showing posts with label Embedded C Programming. Show all posts

May 27, 2016

ARM Bare Metal Programming with GNU

ARM bare metal programming was considered a dark art and known only to very few. Here are the links that opens it to you on how to write a startup code, linker script and all that is hidden behind your popular IDEs. With this knowledge, you can start to write your code without the help of any IDEs. You can completely take in control where to place each of your bits on the RAM. Enjoy exploring the core of embedded programming.

Embedded programming with the GNU toolchain - bravegnu.org
Building Bare-Metal ARM Systems with GNU - embedded.com
Building Bare-Metal ARM Systems with GNU - mikrocontroller.net

May 17, 2016

Articles on 'const' and 'volatile' qualifiers

More recently I went through some of the articles and lectures on C and C++ by Dan Saks, a consultant in US. I especially liked his lecture on 'const' qualifier which was more thought provoking and felt, a must share article. http://www.dansaks.com/articles.htm. Also, he is a columnist at embedded.com

February 25, 2016

Functions with variable number of arguments

    1. Functions can be written to handle variable number of arguments. For example, printf().

    2. The function prototype should have atleast one known argument followed by ellipsis (set of 3 dots)     which represent any unknown number of arguments passed. The ellispsis should only appear as the last aruments.

 void function(char var1, int var2, ...);

    3. This feature is implemented using a set of macros va_list, va_start, va_arg, va_end, va_copy defined in stdarg.h. All the above macros were defined since C89 except va_copy which is defined since C99.

    4. va_list is a type used to declare a pointer to be used by other macros.

 va_list ap;

    5. va_start is a macro which initializes ap to point to the first anonymous argument (unknown argument) which is stored in stack memory. The known argument just before the ellipsis is used by va_start as a reference in the memory to locate the unknown arguments. va_start should be invoked before va_arg.

 va_start(ap, var2);

    6. va_arg is a macro which retuns an unknown argument on every call and steps ap to the next argument. var_arg uses type name as its second parameter to determine the return type and step size.

 temp = va_arg(ap, );

        The used can be one of the fully promoted types (int, unsigned int, double), its pointer types and void *. The behaviour of va_arg is undefined if the is not compatible with the actual type if there is no next argument.

    7. va_copy is a macro that creates a copy of ap such that the current state of ap is copied.

 va_copy(ap, ap_copy);

    8. va_end clears the ap so that is no more usable. It must be called before returning from the function.

 va_end(ap);

Example:

#include <stdio.h>
#include <stdarg.h>

int add(int c, ...);

int main()
{
    int res1, res2, res3, res4;

    res1 = add(3, 1, 2, 3);

    res2 = add(5, 1, 2, 3, 4, 5);

    res3 = add(7, 1, 2, 3, 4, 5, 6, 7);

    res4 = add(9, 1, 2, 3, 4, 5, 6, 7, 8, 9);

    printf("res1 = %d\nres2 = %d\nres3 = %d\nres4 = %d\n",
    res1, res2, res3, res4);
}


int add(int count, ...)
{
    int sum = 0, sum2 = 0;
    va_list valist, valist2;
    
    va_start(valist, count);

    while (count) {
 if (count == 2)
     va_copy(valist2, valist);

 sum += va_arg(valist, int *);

 if (count &lt;=2)
     sum2 += va_arg(valist2, int);
 --count;
    }

    return sum;
}

 Reference:

    1. K&amp;R - Sec 7.3, Appendix B7
    2. c99 - Sec 4.8

December 26, 2015

CC3200 Launchpad UART Interrupt handling

For enabling and using UART in CC3200 using SDK without interrupt, visit CC3200 Launchpad - Enabling UART.

If you are having problem with simple UART transaction, please go through the above mentioned post and come back to learn interrupt handling.

There are only a very few more steps to enable and using Interrupt handler for UART. This should be considered as continuation of the above mentioned post.

All the APIs below are prefixe 'MAP_'. But, it can also be used without the prefix. But, prefix is recommended to reduce the size of the binary by mapping the APIs pre-written on the internal ROM chip.

//To enable the Global Interrupt
MAP_IntEnable(FAULT_SYSTICK);

Enabling the global interrupt will make all the unmasked peripheral interrupt to be visible to the interrupt controller.

//Registers a handler for UART1 interrupt                                  
MAP_UARTIntRegister(UARTA1_BASE, UART1_IntHandler);

Registers the interrupt handler with the name given by the second parameter for the UART1. The interrupt handler shall contain the ISR to be run on occurrence of the interrupt.
//Enables interrupt for UART1
MAP_UARTIntEnable(UARTA1_BASE, UART_INT_RX | UART_INT_RT);

The above API unmasks the individual UART interrupts as given by the second parameter. The second parameter can be OR'd value of any or all possible interrupt sources. Here, the macro UART_INT_RX refers to the interrupt on reception of a data at the RX register. UART_INT_RT refers to the Receive timeout interrupt which occurs after pre-defined timeout after the reception of data. Transmit interrupt can also be enabled by OR'ing UART_INT_TX macro. The TIs CC3200 comes with 8 byte Transmit and Receive FIFO to help buffering of serially sent or received data. It also can help reduce the frequency of interrupt.

The Interrupt handler should use the same name as registered with UARTIntRegister as follows.

//Interrupt handler
void UART1_IntHandler() {
  unsigned char ch;

  while((ch = MAP_UARTCharGetNonBlocking(UARTA1_BASE) != -1) {
    chararray[i++] = ch;
  }

}

CC3200 Launchpad SimpleLink enabling UART

The below tutorial to enable and use UART is by using the CC3200 SDK library version 1.1.0 but it will be compatible with other versions as well.

First let me list the library header files that are required for this program.
Considering UART1
  1. rom_map.h
  2. hw_memmap.h
  3. prcm.h/prcm.c
  4. pin.h/pin.c
  5. uart.h/uart.c
  6. uart_hal.h/uart_hal.c

//Enable the UART peripheral clock
MAP_PRCMPeripheralClkEnable(PRCM_UARTA1, PRCM_RUN_MODE_CLK);

//Pin Configuration
// Configure PIN_01 (GPIO_10) for UART1_TX                   
MAP_PinTypeUART(PIN_01, PIN_MODE_7);
// Configure PIN_02 (GPIO_11) for UART1_RX
MAP_PinTypeUART(PIN_02, PIN_MODE_7);

//Set the UART1 Configurations (Clock, Baudrate, Data, Stop and Parity bits)
MAP_UARTConfigSetExpClk(CONSOLE,MAP_PRCMPeripheralClockGet(CONSOLE_PERIPH), UART_BAUD_RATE, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

Now, the UART1 is configured to work with GPIO pins 10 (TX) and 11 (RX) with baud rate as defined by the macro UART_BAUD_RATE and data length of 8 bits, 1 stop bit and no parity check. You can also choose different pin sets such as GPIO_16 as TX and GPIO_17 as RX or any other pin sets as defined in the technical reference manual.

Lets look at APIs to send and receive data. There are API defined to send and receive data both in non-blocking and blocking (polling) methods.

Blocking Codes - Waits for data reception or transmission completion by entering a conditional loop and blocking the cpu.

Non-Blocking Codes - Looks for data, data is retrieved if available or else, it continues executing the next instruction.

//Blocking codes

//Receive data
Data = UARTCharGet(UARTA1_BASE);

//Send data
UARTCharPut(UARTA1_BASE, Data);

//Non-Blocking codes

//Receive data
Data = UARTCharGetNonBlocking(UART1_BASE);

//Send data
UARTCharPutNonBlocking(UARTA1_BASE, Data);

Here, UART1_BASE is a macro defining the base memory location of UART1 as given in memory map in the Datasheet and is defined in hw_memmap.h. The variable 'Data' is the data received or sent. By using the UARTCharGet or UARTCharPut API inside a loop a string of data can be sent over serial port.

In the SDK, there are functions prefixed with 'MAP_' which are macros defined in rom_map.h which actually maps to the memory location of internal ROM where these APIs are pre-written as part of the servicepack. This reduces the size of binary file and serial flash utilization.

UART can also be used with interrupt enabled. For UART interrupt handling, visit CC3200 Launchpad - UART Interrupt handling.

October 10, 2015

ARM Programs for basic understanding

Below is some basic ARM program for the STM32L152 Discovery Board (Cortex M3) without using any programming library. Here, we directly configure the registers using self defined macros. This will help understand the hardware architecture as well. This is the method how libraries are built. But for fast programming, programming libraries such as CMSIS is recommended. Refer STM32L152 Datasheet for register memory-map (~Chapter 5).

1. Blink LED
2. Timer2 programming
3. USART1 programming
4. Automated Power Tiller - A project with ISR and modular code

September 09, 2015

C Programming guidelines and standards

We do C programming and we may be good in writing the logic. But in industry standards, some writing guidelines are followed to increase the clarity of the code to give better readability to others who see your code. In times we feel debugging our own code is hectic. Following the coding guidelines will help you in this case. Here are links to few coding guidelines and standards to write a clean readable code.
GNU Coding Standards

To know the standard defined in C as per ANSI C, refer c89-draft

August 13, 2015

A complete course materials on embedded System design

This is a series of presentation from an Embedded System Course that covers the course content in total of 8 modules. Below is the link to all the modules. These presentations will suffice the basics to start with embedded system design.

  1. Embedded C and 8-bit Microcontroller
  2. System Design Using ARM
  3. Embedded Linux
  4. Embedded RTOS (VxWorks, RTLinux)
  5. System Design using DSP
  6. System Design using FPGAs

January 28, 2015

Training Programme Calendar (MSME-PPDC)

What is MSME?
Micro, Small and Medium Enterprises (MSME), they are the nurseries for entrepreneurship and innovation. They are widely dispersed across the country and produce a diverse range of products and services to meet the needs of the local markets, the global market and the national and international value chains. The Ministry has a number of programmes to help and assist entrepreneurs and small businesses.

It is a body of Government of India and organizes various short, medium and long term training programme that covers various technical training for Diploma, Engineering and Management fields. These training programme would help entrepreneurs, students and employees. The training programmes are constantly advertised on leading newspapers and also can be found in the website http://www.ppdcagra.in/training.html.


Employment Registration for Job seekers in industries: http://ee4ind.com/CandRegister.aspx 

Related Links: 
  1. Indian Institute of Entrepreneurship 
  2. National Institute for Micro, Small and Medium Enterprises  
  3. National Institute for Entrepreneurship & Small Business Development  

November 24, 2014

Centre for Development and Advanced Computing (C-DAC) - Education and Training programmes

C-DAC's Education and Training programmes are aimed at creating skilled manpower in the country by providing quality training programmes in the field of Electronics and ICT. This activity started almost two decades ago with a humble beginning of training about 20 students per year, but has today grown to an extent of training more than 5000 students per year. It also grew from just one training centre to about 50 training centres across India and has even made its presence in several countries abroad. In addition to conducting wide range of training programmes in the areas of Information, Communication and Electronics technologies, C-DAC also develops ICT tools and technologies for modern methods of imparting education and training to masses. The Education and Training activities of C-DAC are governed and steered by Academic Council (AC) and Academic Management Committee (AMC).
Presently, C-DAC offers its various training programmes through its own training centres in Bengaluru, Chennai, Hyderabad, Kolkata, Mohali, Mumbai, Noida, Pune and Thiruvananthapuram, and its network of Authorised Training Centres (ATC) spread across the country.
The various activities under the umbrella of C-DAC's Education and Training Programmes are described below:
Post Graduate Diploma Programmes
C-DAC conducts two batches of following PGD...
Go

Formal Training Programmes
C-DAC also conducts formal training programmes...

Go

Faculty Development Programmes
C-DAC conducts advanced faculty training programmes...


Go

Corporate Training Programmes
C-DAC offers various specialized training...
Go

Education Technologies
C-DAC has taken major initiatives in developing...
Go

Other Initiatives
Capacity Building Initiatives...

Go

International Training Program
International Training Program...
Go


November 13, 2014

NIELIT | Course Calendar 2015

http://calicut.nielit.in/course/calendarcedti.asp

Course Code Course Name Duration Starting Date Course Fee * Course Brochure
Information Technology Group
 SW100 PG Diploma in Software Technology  6 Month(s)   Mar-9-2015  67000 
    SW101 Diploma in .NET Technologies  3 Month(s)   Dec-8-2014  35100 
    SW102A Diploma in JEE  3 Month(s)   Mar-9-2015  35100 
    SW102B Diploma in Android Application Development  3 Month(s)   Mar-9-2015  35100 
 SW250 Diploma in PHP and jQuery  3 Month(s)   Feb-25-2015  30000 
 SW302 Diploma in .Net Technologies (Online Course)  3 Month(s)   Feb-25-2015  10000 
 SW304 Diploma in PHP Programming (Online Course)  3 Month(s)   Feb-25-2015  10000 
 SW500 PG Diploma in Information Security and Cloud Computing  24 Week(s)   Feb-25-2015  73000 


Embedded Systems Group
 ED500 PG Diploma in Embedded System Design  24 Week(s)   Feb-25-2015  80000 
 AED600 PG Diploma in Embedded Real Time Systems  24 Week(s)   Feb-25-2015  80000  -


Process Control and Instrumentation Group
 PC100 PG Diploma in Industrial Automation System Design  24 Week(s)   Mar-23-2015  80000 
 PC500 Advanced Diploma-PLC/SCADA/DCS Engineer  16 Week(s)   May-4-2015  40000 


VLSI Design Group
 US100 Diploma in Medical Ultrasound  200 Hour(s)   Mar-30-2015  25000 
 AVL500 PG Diploma in VLSI & Embedded Hardware Design  24 Week(s)   Feb-25-2015  80000  -
 AVL600 PG Diploma in ASIC Design and Verification  24 Week(s)   Mar-30-2015  80000  -



General Details:

Click on individual course codes for more details of the courses. Some courses are modular programs. The full course name is displayed in bold face. One can apply for total/individual modules. For PG Diploma courses, Diploma Students will be given only 'Advanced Diploma' certificate instead of PG Diploma.
Eligibility:
Engineers/Diploma/Graduates with appropriate experience. Please click on individual courses to see the eligibility details of that particular course. Final year students may also apply.
Hostel:
Hostel Facility is available for boys and girls on daily or monthly chargeable basis. However, students are required to pay the hostel fees for the duration of the course for which they are seeking admission at the time of joining the course. The hostel rent varies from Rs.850 to Rs.1400 per month depending on the location of the accommodation and facilities available. Caution deposit varies from Rs.300 to 1500 depending upon the duration of the stay, and the same is required to be paid in addition to the hostel rent.
Fees:
The students are normally required to pay the entire course fee at the time of admission. However, in the case of certain specified courses, the students can also make payment of fees in installments (applicable only for courses mentioned in the training calendar and are of duration 4 months or more). Service tax on the course fee will be charged extra at actuals. SC/ST/Physically Handicapped candidates are eligible for seat reservation for all the courses as per Govt. of India norms.
Tution Fees/Examination fees are waived for SC/ST students subject to terms and conditions. The students are requested to contact the Training Officer to know the fees payable by them for the Course Materials and other charges.

Intimation of Selection:
The students selected for the course/s shall be intimated of his selection by email/post/courier. The students are therefore required to provide their correct email address and are advised to check their email/visit our website to know about their selection. List of selected students shall also be available in our website (for select courses only).
How to Apply:
Students can apply for the course/s by either filling up the online application form or by downloading the application form and forwarding the same to the Training Officer, along with DD for Rs.1000/- as Advance Deposit.  For the admitted students, this advance deposit will be converted to caution deposit which will be refunded at the end of the course. This advance deposit will not be refunded for a selected candidate who does not join the course.

1. Procedure for Online application : Students can apply online by filling up the online application form. Click here to apply online. The students are first required to obtain the DD for Rs.1000/- towards Advance Deposit. The students are required to fill the details with regards to the DD Number, Date and amount. The students are requested to note down their registration number allotted after pressing the "Submit" button and forward the demand draft mentioning their name and their online registration number. Online registrations not containing the details with regards to the Advance Deposit details will not be considered for registration. If the payment is done through online banking or directly through bank, the original receipt/counterfoil of the same should reach here before the last date to apply.

2. Procedure for applying using the Application form : The students can download the application form from our web site (Download Application Form ) and fill the particulars and forward the same to the Training Officer along with the requisite fee as mentioned above.
3. Mode of  Payments : The course fee can be paid by one of the following methods

August 08, 2014

Microchip PIC Timer Tutorial

Concept of timer is clearly explained in the download below. Also, a clear differentiation between timer and counter is provided. Download (.pdf)

August 07, 2014

Embedded programming for LCD interfacing with microcontroller (ATMEL / PIC)


Embedded programming for LCD display Interfacing
(Book: The 8051 Microcontroller an Embedded Systems – using Assembly and C, Muhammad Ali Mazidi, Janice Gillispie Mazidi, Rolin D. McKinlay)
LCD Interfacing
Pin
Symbol
I/O
Description
1.   
Vss
-
Ground
2.   
Vcc
-
+5V power supply
3.   
VEE
-
Power supply to control contrast
4.   
RS
I
RS=0 – select command register
RS =1 – select data register
5.   
R/W
I
R/W=0 – Write
R/W=1 – Read
6.   
E
I/O
Enable
7.   
DB0-DB7
I/O
8-bit data bus

LCD Command Codes
Code
(Hex)
Command to LCD instruction register
1
Clear display screen
2
Return home
4
Decrement cursor (shift cursor to left)
6
Increment cursor (shift cursor to right)
5
Shift display right
7
Shift display left
8
Display off, cursor off
A
Display off, cursor on
C
Display on, cursor off
E
Display on, cursor blinking
F
Display on, cursor blinking
10
Shift cursor position to left
14
Shift cursor position to right
18
Shift the entire display to the left
1C
Shift the entire display to the right
80
Force cursor to beginning of 1st line
C0
Force cursor to beginning of 2nd line
38
2 lines and 5×7 matrix

Example Program:
To write/read on the LCD, first a set of commands (from above table) should be sent to the LCD module to set mode and clear display. Below is a set of functions in an order to make you understand easily.
(Don’t consider the item displayed, instead “HELLO!” will be displayed)


Receive all updates via Facebook. Just Click the Like Button Below

▼

You can also receive Free Email Updates:

dgpride - Study Zone - Free Books - Tamil Lyrics

Copyright © 2008 -2012 dgpride. All rights reserved.

Subject/Topics

2 Marks (26) 8051 (1) AC Machines (7) Animations (1) Anna University Chennai (31) Arduino (4) ARM (3) Audio (1) Basic C Concepts (8) Basic Electronics (13) Basic principles (9) Book list (1) CAD (1) Chemical (2) Circuit theory (6) Civil (2) Cloud Computing (1) Communication (4) Competitive exams (2) Computer Architecture (4) Control system and components (9) CSE (40) Curriculum (4) DC Machines (9) Did you know (14) Digital (13) DLC (4) Documentation (1) DSP (1) EC 2201 (3) ECE (45) EDC (1) EEE (34) EIE (63) Electrical (35) Electronics (43) Electroplating (2) Emacs (1) Embedded basics (19) Embedded C Programming (19) Embedded Linux (5) Embedded System (22) Engineering basics (15) Environmental Science (1) Fibre Optics (1) Filters (2) FPGA (1) GATE (3) General (7) GNU (4) Handwritten (1) Hobbyist (15) How to (8) HTML (3) Humanities (2) IC Engines (7) ICE (5) Industrial Electronics (10) Industrial Instrumentatin (2) industrial process (2) Instrumentation (21) IoT (2) IT (2) Laboratory Manuals (17) LabVIEW (2) Lesson notes (2) LIC (2) Links (9) Linux (8) Magnetics (1) Management (1) Mechanical (5) Mechatronics (9) Microcontrollers (14) Microprocessors (9) Microsoft (1) Motivation (1) Must Know (11) Networks (1) NuttX (1) Objective type (1) Open Source (1) Opportunities (7) Oscillators (2) Part Time (1) Physics (1) Post Graduation (1) Power Electronics (12) Power Plant Engineering (2) Power Supplies (2) Previous GATE Papers (1) Process Control (2) Project (4) Protocol (1) R2008 (11) R2009 (1) R2013 (1) Recruitment (2) Research (2) Robotics (9) RTOS (3) Signal Processing (8) Signals and Systems (4) SMPS (1) Software tutorial (4) Stepper Motor (2) Syllabus (5) Texas Instruments (2) Thermodynamics (2) Training and Placement (6) Transducer Engineering (2) Transformer (2) Transmission (1) Tutorials (48) Two Marks (26) U-Boot (1) University Question Papers (16) Verilog (1) Video (4) Virtual Instrumentation (3) Visual Basic (21) VLSI (11) Web designing (4) Wi-Fi (3) Wireless (6)