Questions tagged [c]

C is an imperative (procedural) systems implementation language. It was designed to be compiled using a relatively straightforward compiler, to provide low-level access to memory, to provide language constructs that map efficiently to machine instructions, and to require minimal run-time support. C was therefore useful for many applications that had formerly been coded in assembly language. from http://en.wikipedia.org/wiki/C_(programming_language)

Filter by
Sorted by
Tagged with
45
votes
9answers
8k views

Using volatile in embedded C development

I have been reading some articles and Stack Exchange answers about using the volatile keyword to prevent the compiler from applying any optimizations on objects ...
34
votes
4answers
3k views

Who receives the value returned by main()?

I know that in computers, value returned by the main() function is received by the operating system. But, what happens in the ...
33
votes
9answers
35k views

Fast and memory efficient moving average calculation

I'm looking for a time and memory efficient solution to calculate a moving average in C. I need to avoid dividing because I'm on a PIC 16 which has no dedicated division unit. At the moment, I just ...
25
votes
3answers
14k views

What resides in the different memory types of a microcontroller?

There are different memory segments to which various types of data are put into from C code after compilation. I.e: .text, .data,...
24
votes
2answers
6k views

C coding design - function pointers?

I have a PIC18F46K22 and program it with the XC8 compiler. In the end, I'll have a system like a pc with stdin and stdout. So in ...
24
votes
2answers
31k views

What is bit banging

I am new to microcontroller programming. I am using ATmega32-A controller and CodeVisionAVR compiler. I am using the waveform generator(AD9833) to generate a sinewave signal using SPI communication. I ...
22
votes
10answers
30k views

Programming languages for electronics engineers

I am an Electronics and Communications Engineering student, before I got to college, I have been interested in programming and computer applications. I had focused on designing Windows applications ...
22
votes
5answers
8k views

C standard libraries on bare metal

I am mostly doing development on devices that have ported Linux so the standard C library provides lots of it's functionality through implementing system calls which have a standardised behaviour. ...
22
votes
7answers
31k views

For embedded code, why should I use “uint_t” types instead of “unsigned int”?

I am writing an application in c for an STM32F105, using gcc. In the past (with simpler projects), I have always defined variables as char, ...
18
votes
8answers
6k views

Writing DSP algorithms directly in C or assembly? [closed]

I m working on a DSP project(IIR filtering) on an Analog Devices digital signal processor(BF706) with the compiler suite coming with it, CrossCore Studio. It has some examples for simple DSP stuff ...
18
votes
4answers
6k views

How does factory reset work?

All embedded devices includes a "Factory reset" option that allows the user to reset his device if something is wrong. I am developing a Firmware on an STM32 board. The firmware includes a boot ...
17
votes
4answers
49k views

How do I use the printf function on STM32?

I am trying to figure out how to use the printf function to print to the serial port. My current setup is STM32CubeMX generated code and SystemWorkbench32 with the STM32F407 discovery board. I see ...
16
votes
6answers
17k views

Use of global variables in Embedded Systems

I started writing firmware for my product and I'm a rookie here. I went through many articles about not using global variables or functions. Is there any limit for using global variables in an 8 bit ...
16
votes
8answers
22k views

Why is printf() bad for debugging embedded systems?

I guess it's a bad thing to try to debug a microcontroller-based project using printf(). I can understand that you have no predefined place to output to, and that ...
16
votes
5answers
2k views

Possibilities for allocating memory for modular firmware design in C

modular approaches are pretty handy in general (portable and clean), so I try to program modules as independent of any other modules as possible. Most of my approaches are based on a struct that ...
16
votes
3answers
2k views

From C to Assembly

Suppose that we have the following piece of C code for an avr-8bit: int v1=1; int v2=2; v2=v2+v1; I expected the following disassemble ...
16
votes
2answers
17k views

STM32F2: Makefile, linker script and start-up file combination without commercial IDE

I have been working with an STM32F2 (specifically, the STM32F217IGH6 on a development board) for about two months. By far my biggest problem had to do with the "setup", which includes makefile, linker ...
16
votes
1answer
1k views

Sine signal generation using PWM

We are unable to generate a sine signal properly using a MC68HC908GP32 microcontroller. PWM description begins in page 349. Clock frequency is 2.4MHz, while we have used 7 kHz PWM by using the ...
15
votes
4answers
5k views

How to implement critical sections on ARM Cortex A9

I am porting some legacy code from an ARM926 core to CortexA9. This code is baremetal and does not include an OS or standard libraries, all custom. I am having a failure that appears to be related ...
13
votes
9answers
5k views

What is the best approach when writing functions for embedded software in order to get better performance? [closed]

I have seen some of the libraries for microcontrollers and and their functions do one thing at a time. For example, something like this: ...
13
votes
3answers
3k views

C Integer Promotion on 8-bit MCUs

Using avr-gcc as an example, int types are specified to be 16-bits wide. Performing operations on 8-bit operands in C results in those operands being converted to 16-bit int types due to integer ...
11
votes
3answers
1k views

Variable declaration with @ in C

I am reading some C code and came across this declaration in the program: unsigned char serv_ctr @0x0002; Can someone point me to documentation, or explain what ...
11
votes
6answers
2k views

What is the reason my PIC16 multitasking RTOS kernel doesn't work?

I am trying to create a semi-pre-emptive (co-operative) RTOS for PIC x16 microcontrollers. In my previous question, I've learnt that accessing hardware stack pointer is not possible in these cores. I ...
11
votes
4answers
15k views

Endian problem on STM32

I'm using arm gcc (CooCox) to program an STM32F4discovery, and I've been wrestling w/ an endian problem I'm sampling with a 24 bit ADC via SPI. Since three bytes are coming in, MSB first I had the ...
11
votes
2answers
9k views

Program AVR EEPROM directly from C source

When you include the following code in an AVR C source, you can apparently directly program the fuses, without the need for an extra command or .hex file: ...
11
votes
3answers
1k views

Microcontroller Sleep Race Condition

Given a microcontroller that is running the following code: ...
11
votes
1answer
2k views

PIC18F4550 C-compiler that's open-source & cross-platform?

I'm a long time AVR user. I really like that AVR-GCC works on the two main OSes I use (Mac OS X and Linux), is open-source, and is supported by Atmel. I'd like to get back into PIC programming (used ...
10
votes
6answers
6k views

Avoiding global variables when using interrupts in embedded systems

Is there a good way of implementing communication between an ISR and the rest of the program for an embedded system which avoids global variables? It seems that the general pattern is to have a ...
10
votes
1answer
7k views

What is slew rate for I2C?

I'm configuring I2C on a PIC18 using the built-in functions of the C18 compiler as described in section 2.4 of the documentation: ...
10
votes
2answers
5k views

Standard text LCD menu system

Is there a pattern out there for a simple menu system in C for a text LCD. I find myself re-writing code a lot for handling simple text LCD menus. I find most systems have a main menu and some sub-...
9
votes
4answers
2k views

Why GCC compiler omitting some code?

I can not understand why GCC compiler cutting out part of my code while it preserve absolutely the same one in the neighborhood? The C code: ...
9
votes
5answers
17k views

Is it going to be possible to write code in C++ for PIC microcontrollers in the future?

Is it ever gonna be possible to use C++ for coding PICs? Is there any hardware limitations that prevents us to use C++? How much the size of generated .hex file and running time of the program ...
9
votes
5answers
2k views

What tools or standards can be used to improve embedded C code reliability?

I typically program PICs in C, usually for switched-mode converters. I've heard of various static analysis tools and standards like MISRA C that can be used to help improve the reliability of code. I'...
9
votes
5answers
4k views

Start off with embedded C with ATmega32 (ATmega AVR series)

I have a ATmega32 board laying around and I figure it would be perfect to start off with microcontrollers. I once did some babbling in embedded C (thats when I got this board) but the flow was stopped ...
9
votes
7answers
10k views

Arduino Serial print changes behavior of program undesireably

I'm using a loop counter, declared in a header: int loop_counter = 0; I use this counter to trigger an event every so often. I used to use a modulo for this same ...
9
votes
3answers
16k views

STM32: Timer interrupt works immediately

This is code for timer in my project on STM32F429: ...
9
votes
2answers
3k views

Fixed point trigonometry for embedded aplications

I need to do rotational (and other) transformations in an embedded application, requiring the sin() cos() and tan() functions. I know you can use look-up tables, and that's the only solution I could ...
9
votes
3answers
13k views

Call Serial.print in a separate tab/header file

I'm writing a program in Arduino 0022. Calling Serial.println works fine in my main sketch code, but when I attempt to use it in my header file "...
9
votes
2answers
756 views

Printing variable characters to UART does not work, constants work fine

I have a rather strange issue with XC8 on a PIC18F27K40 microcontroller. On a PIC16F1778 it works. I have defined: ...
8
votes
4answers
4k views

Run code once in lifetime of an embedded C program

How can I make a code snippet run only once in the lifetime of a program? It can be turned off and turned on many times. The only option to run the code snippet again must be flashing the board again. ...
8
votes
6answers
2k views

Concept of the static keyword from the perspective of embedded C

static volatile unsigned char PORTB @ 0x06; This is a line of code in a PIC microcontroller header file. The @ operator is ...
8
votes
3answers
44k views

Starting with I2C on PIC18s

For a project I'd like three PICs (two slaves PIC18F4620, one master PIC18F46K22) to communicate over the I2C bus. Later on, more slaves may be added (like EEPROM, SRAM, ...). I'm writing the code for ...
8
votes
2answers
911 views

PIC12F675 GP4 doesn't work

I'm using a PIC12F675 for a project, and everything works fine except one thing. GP4 does not work as digital IO. I've looked at the configs and the code a lot, but couldn't find anything. Config: <...
8
votes
3answers
1k views

What does #if 0 do

Today I started to use MPLAB X to program my PICs, and found a code template, with multiple files and spots to fill in code. Before I have had a single file with my code in it. In this template, where ...
8
votes
5answers
5k views

What's wrong with this casting in C code for AVR?

I defined two variables: uint8_t a[2]; uint16_t b; Next I want to use a as variable of type ...
8
votes
5answers
5k views

How to Wire a PIC Microcontroller?

I'm completely new to the world of PIC Microcontrollers and electrical engineering so please go easy :) Anyway, I managed to program my PIC 16f627 to turn on three LEDs when push button (trigger ...
8
votes
2answers
1k views

Why does AVR code use bit shifting [closed]

In AVR programming, register bits are invariably set by left-shifting a 1 to the appropriate bit position - and they're cleared by a ones' complement of the same. ...
8
votes
2answers
4k views

Implementing Control Commands for an MCU over Serial

Im looking to integrate a command interface in a project that im making that will accept commands overs serial from a PC. The idea is that the device will do its thing but it gets sent a command, it ...
8
votes
1answer
8k views

How do I create a static library for the AVR Atmega328p?

I am attempting to create a library much like the Arduino in C. I have tried in the past and although I have lost the code, I remember simply getting loads of undefined references to functions ...
8
votes
1answer
6k views

Drawing on 8x32 LED matrix with 74HC154

How do I send a pattern into an 8x32 LED matrix? I'm using the AT89S52 microcontroller with a 74HC154 4-16 line decoder, programming in C with the Keil IDE. I've done vertical scanning, but am stumped ...