Interfacing EEPROM and Interrupt
Interfacing EEPROM and Interrupt
No:
DATE : Interfacing EEPROM and Interrupt
AIM
To develop a C-Language program to write and read a data in EEPROM and also to analyze its
performance with the interrupt.
APPARATUS & SOFTWARE REQUIRED
THEORY
PROCEDURE
1. Double click IAR Embedded Workbench in the Desktop.
2. To create a new project, choose Project>Create New Project. In the Dialog box, set the tool chain to
ARM and select the project template as empty project.
3. To type the program, select new from file menu and save it with the name (anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
6. Change the mode of the program into downloading mode by using Flash loader software.
7. To view the output, after downloading your program change the board to execution mode in cortex
M4 development board and reset it.
8. In first step, some data will be written in EEPROM at the starting address 0x01.
9. Then read the data from that memory location. The read data will be displayed in the terminal
window.
PROGRAM
/*Header Files*/
#include "stm32f4xx.h"
#include "stdio.h"
/*Definitions*/
#define SLAVE_ADDRESS1 0xA6 // the EEPROM address for write
#define SLAVE_ADDRESS2 0xA7 // the EEPROM address for read
/* prototype functions */
void I2C_stop();
void I2C_write(uint8_t data);
void I2C_start(uint8_t address);
void init_I2C1();
void Delay(int t);
void USART2_config();
int EEPROM_read(uint16_t address);
void EEPROM_write(uint16_t address,uint8_t value);
void TIM2_Config(void);
void TIM2_IRQHandler();
void switch_config(void);
/*Main Routine*/
int main(void)
{
int val;
USART2_config();
printf("\n\rInterfacing EEPROM and Interrupt");
switch_config();
init_I2C1();
address=0x0000;
EEPROM_write(address,0);
TIM2_Config();
while(1)
{
val = ((GPIOE->IDR)&0x14); //Read PORTE
if(val == 0x10) //if decrement switch is pressed
{
if(count==0)
count=0;
else
count=count-1;
NVIC->ISER[0] |= (0<<28); //Interrupt Disable
EEPROM_write(address,count); //write the count value in the EEPROM
NVIC->ISER[0] |= (1<<28); //Interrupt Enable
while(((GPIOE->IDR)&0x04)==0x00); //wait till the key is released
}
else if(val == 0x04) //If increment switch is pressed
{
count=count+1;
if(count>=255)
{
count=0;
address=address+1;
}
NVIC->ISER[0] |= (0<<28); //Interrupt Disable
EEPROM_write(address,count);
NVIC->ISER[0] |= (1<<28); //Interrupt Enable
while(((GPIOE->IDR)&0x10)==0x00); //wait till the key is released
} }}
/*Delay Routine*/
void Delay(int t)
{
int y,u;
for(y=0;y<t;y++)
for(u=0;u<t;u++);
}
RESULT
Thus the C-Language program to write and read a data in EEPROM and also to analyze its performance with
the interrupt is developed and is verified.