Tag Archives: i2c

DS1307 Based RTC Module

An RTC Module or a Real Time Clock Module helps a system keep track of current time (hour, minutes and seconds). It automatically increments the time without any help from the host (microcontroller). Other benefit is that it has a backup power supply from a small coin cell that help it maintain the time in absence of power. It needs very small power in backup mode so that the coin cell last for years! One such RTC IC is DS1307. It communicates with the host using I2C serial interface. We have put all the required components in one PCB to make a neat module that we can hook up to our MCUs like PIC or AVR. After the experiment you can put the module safely in your drawer, bring it out after an year and still it will give you the correct time! DS1307 Module Schematic DS1307 Based RTC Module Schematic DS1307 Module Fabricated ! DS1307 Based RTC Module   Professional DS1307 RTC module     Connection with MCU The SCL line of RTC Module will be connected to SCL line of MCU similarly the SDA line will be connected to the MCU’s SDA line. The RTC Module should be powered from the microcontroller development board. Most of our boards have extra 5v output points. Please see their documentation for […]

DS1307 I2C RTCC Interface using SoftI2C lib

In the last tutorial, I explained you how to use our SoftI2C library to read and write a 24CXX series I2C EEPROM. Now I will continue our exploration and write a register access layer for the DS1307 chip. The DS1307 chip is a real time clock and calendar IC. The register access layer that we will develop provides the application programmer with function that reads and write the registers of DS1307. Remember that any piece of hardware appears to the CPU as a set of registers only. DS1307 has :- Seven Registers (from 0x00 to 0x06) that are used for timekeeping functions. One CONTROL register(0x07) for square wave generation setting (we don’t use this for simplicity). 56 bytes of battery backup RAM (from 0x08 to 0x3F) Fig. : A Simple DS1307 RTC Module.   Once the application programmer has access to functions that reads and writes to any register (specified by its address) inside DS1307 ic, he/she can easily get and set the time infos like sec,min,hour, am/pm, date,month,year etc. The register access layer is built over the core Soft I2C layer. The register access layer consists of the following three functions. void DS1307Init(void) { SoftI2CInit(); } /*************************************************** Function To Read Internal Registers of DS1307 ——————————————— address : Address of the register data: value of register is copied to this. […]

24C1024 I2C EEPROM 128KB

24CXX I2C EEPROM Interface using SoftI2C lib

In this tutorial I will show you how to use our easy to use open source Soft I2C library to access a 24C64 EEPROM chip. We discussed the library in our previous tutorial. The functions developed in this tutorial will use services of the I2C library to read and write the EEPROM. The EEPROM access mainly contains only two routines. BOOL EEWriteByte(uint16_t address,uint8_t data); BOOL EEReadByte(uint16_t address ,uint8_t* data); The first one write a 8 bit data to a memory location specified by the variable address, since a EEPROM can have more that 256 bytes of storage that is why the address variable is 16 bit. The second function reads the memory location specified by the variable address and stores the read data in variable data. Both the function return EE_SUCCESS on success and EE_IO_ERROR on failure. How to develop the EEPROM Write function? We open the datasheet of 24C64A (64kbit) EEPROM and try to understand the random read and random write function. The figure 8 on page number 11 clearly describes the write steps. You just need to translate the figure into proper call to our Soft I2C lib API’s. BOOL EEWriteByte(uint16_t address,uint8_t data) { SoftI2CStart(); //SLA+W if(!SoftI2CWriteByte(EEPROM_WRITE_ADDRESS)) { SoftI2CStop(); //I2C i/o error return EE_IO_ERROR; } //Address HIGH if(!SoftI2CWriteByte(address>>8)) { SoftI2CStop(); //I2C i/o error return EE_IO_ERROR; } //Address LOW […]

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 […]

Easy 24C I2C Serial EEPROM Interfacing with AVR Microcontrollers

In this turorial we will see how we can easily interface a 24C series serial EEPROM with AVR microcontrollers. What is an EEPROM? An EEPROM is kinds of novalatile memory, that means it is used for storing digital data permanently without any power suply. EEPROM stands for Electrically Erasable Programmable Read Only Memory. The advantage of these kind of ROMs is that they can be erased Electrically to make them ready for storing new data. Compare this with a CD R disks they can be recorded only once. A small amount of EEPROM is also available internally on the AVR chips. So if the volume of data you want to store is small (say few user names and password) then you can use it. The internal eeprom makes design small and simple. But if the amount of data you want to store is large, say in order of few tens of kilobytes then you have to interface a External EEPROM chip with your AVR MCU. You can store pictures, sound and long texts in these eeproms. Their are many kinds of EEPROM chip available from many manufactures. One very common family is 24C series serial EEPROMs. They are available upto 128KB in size. They uses I2C interface with host controller (MCU) which is a very popular serial communication standard. I […]

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) – […]