

Use fixed integer types to enhance portability

If you have programmed anything with C, you should be familiar with common data types like char, unsigned char, int, unsigned int, long int, long long int, etc. It is tough to tell by the looks of type how many bytes this variable takes on memory and how it looks in a different system. For instance in 8-bit AVR-GCC compiler int is a 16-bit type, while in ARM-GCC int is 32-bit. So int size is dependent on platform, compiler and runtime libraries. And switching between systems may trick you if you are not careful enough. You can always check the size of the variable by using sizeof() function. What to do if you need your code to be portable between different systems. Some great libraries could work on any system including 8-bit, 16-bit, 32-bit or 64-bit. To avoid this annoying problem, the ISO C99 standard introduced portable data types that are defined in stdint.h header file. If you open this header file of your default compiler tool-set you will find how things are organized. First of all, it checks the… Continue reading

AVR at a glance

Any AVR microcontroller is an 8-bit computer in a chip designed and manufactured by ATMEL Corporation. It has some RAM and ROM (Flash) as well. There is also an EEPROM memory. Including AVR core CPU all these are more than enough to say that it is a small computer where you can execute programs stored in Flash memory, run them while operating data in SRAM and storing some constant values in EEPROM. Comparing to the real computer that sits on your table you can say that AVR core is a CPU like AMD or Pentium. Flash memory would be your hard drive where programs are stored, RAM is RAM nothing to add there. EEPROM probably can be compared to some media device like CDRW. Anyway, this is only similitude in a different scale. AVR microcontrollers aren’t limited with core CPU and memory. The main thing what makes them valuable (and any other type of microcontroller) – they are rich in peripherals inside the chip. In most cases, you will find USART, I2C, SPI, ADC, Timers/Counters, and a bunch of I/O… Continue reading