Tag Archives: serial communication

USART Library for PIC – Setup on MPLAB X IDE

This article describes the setup and use of the C library for serial communication. We focus on its usage with PIC16F series of MCUs from Microchip. Here we describe how to setup a MPLAB X project with support for serial communication related functions. The library is designed for compilation and use with Microchip’s XC8 C Compiler. Fig. Serial Communication Demo   Creating a New Project in MPLAB X You can create a new project using the MPLAB’s Start page as shown below. Fig. MPLAB X Start Page Alternatively you can use menu File->New Project Fig. Select New Project from File Menu And for those who love the Keyboard over mouse can hit <Ctrl>+<Shift>+<N> Any of the three method will launch the New Project Wizard as shown below. The first step is the selection of project type. From the Categories list select Microchip Embedded and from Projects select Standalone Project. Fig. Project Type Selection Second step is the selection of device for which the project is targeted. Select Mid Range 8-bit MCUs (PIC12/16/MCP) in Family and PIC16F877A in Device. Fig. Device Selection Third step is the selection of debug tool. For that select Simulator. Fig. Tool Selection Microchip MPLAB lets you install more that one compiler. It also lets you install more that one version of the same compiler. So their […]

Software I2C Library for AVR MCUs

Inter IC Communication or I2C is a two wire serial communication bus used to connect a variety of external peripheral with a microcontroller. Most common are EEPROMs, RTC, Port Expanders etc. Most leading MCUs comes with at least one dedicated I2C host adaptor built in. But some times we need more than one I2C interface or we need I2C lines on some other i/o pins than those allotted to the hardware I2C, in that case we need to go with a solution called SoftI2C. In SoftI2C the I2C signals are handled in software, the advantage is that any two i/o line of the MCU can be used for communication. The drawback is that it need more CPU cycles are wasted in generating the signal thus less time slice is available to the application. In this article we will present our open source, flexible and easy to use SoftI2C library. This library can be used to connect any I2C slave device with an AVR (and latter PIC MCU) MCU. Some limitations of the library are :- No Multimaster support. No clock stretching support. But you can connect multiple number of I2C Slaves on the same bus. I2C Master/Slave Connection The Soft I2C Library for AVR The soft I2C library for AVR comes in two files. i2csoft.c i2csoft.h The configuration section lets […]

Synchronous Serial Communication Tutorial – The Basics of I2C and SPI.

This tutorial give you the details of synchronous serial communication, which is the basis of data transfer in communication standards like SPI and I2C. The tutorial is aimed for a beginner who has no experience or any idea of serial communication. So intermediate user who already has some idea about serial data transfer can skip this tutorial and jump directly to SPI or I2C tutorials. Data Transfer. Knowledge of data transfer is very important for any embedded system developer. In any embed ed system data is moved between several units like between RAM and CPU. There are many methods and technique for data transfer each having its own pros and cons. So different data transfer technique is used in different situations. Some example of data transfer are Simple parallel transfer. (Used to transfer 8,16,32 … bits of data in the same time) Asynchronous Serial Transfer (USART) – Old but still in use mode of serial communication using only 2 lines (+1 additional line for GND). SPI – Serial Peripheral Interface – Standard Mode of communication between different ICs. Many ICs designed for a Variety of Jobs like Flash Memory, LCD controller, Ethernet Controllers etc uses this standard for communication. So if you want to use any of these functionality you need to have a knowledge of SPI. IIC(or I2C) – […]