I2C bus EEPROM implementation

Publisher:CrystalBreezeLatest update time:2018-07-15 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The development board is fl2440 board. . Running Linux 3.0 kernel

The EEPROM here is just a preliminary implementation. There is no specific analysis function. It will be analyzed in detail later.

1. Modify the kernel

Change make menuconfig

    Device Drivers --->

<*> I2C support ---> 

--- I2C support                                                                                                    
                                            [*] Enable compatibility bits for old user-space                                                                
                                            <*> I2C device interface                                                                                        
                                            < > I2C bus multiplexing support                                                                                
                                             [ ] Autoselect pertinent helper modules                                                                 
                                            <*> SMBus-specific protocols                                                                                  
                                                  I2C Algorithms --->                                                                                     
                                                  I2C Hardware Bus support --->                                                                           
                                            [ ] I2C Core debugging messages                                                                              
                                            [ ] I2C Algorithm debugging messages                                                                        

                                            [ ] I2C Bus debugging messages

[*] Misc devices --->

       EEPROM support --->


                                            <*> I2C EEPROMs from most vendors                                                                           
                                            <*> SPI EEPROMs from most vendors                                                                          
                                            Old I2C EEPROM reader                                                                                     
                                            < > Maxim MAX6874/5 power supply supervisor                                                                      
                                           <*> EEPROM 93CX6 support   


2. Change arch/arm/mach-s3c2440/mach-smdk2440.c  

Add to

 /*add 24c02 device*/
 static struct at24_platform_data at24c02 = {
     .byte_len = SZ_2K / 8,
      .page_size = 8,
     .flags = 0,
  };
 
 static struct i2c_board_info __initdata smdk_i2c_devices[] = {
      {
          I2C_BOARD_INFO("24c02", 0x50) ,
        .platform_data = &at24c02,
      },
  };

  /* add 24c02 end */

And add in smdk2440_machine_init

i2c_register_board_info(0, smdk_i2c_devices, ARRAY_SIZE(smdk_i2c_devices));

In this way, you can implement eeprom by recompiling the kernel. The file is in /sys/devices/platform/s3c2440-i2c/i2c-0/0-0050/eeprom

An application is given below.

#include
#include
#include
#include
#include
#include
#include

int main (int argc, char **argv[])
{
    int fd;
    int i;
int ret;
    char read_data[256];

    fd = open("/sys/devices/platform/s3c2440-i2c/i2c- 0/0-0050/eeprom", O_RDWR);
    if(fd < 0)
    {
        printf ("open 24c02 fail\n");
        return -1;
    }
    
    lseek(fd, 0, SEEK_SET); //point the head of eeprom

    ret = read(fd, read_data, 256);
    if(ret < 0)
    { printf
        ("read error\n"); return -1
        ;
    }
    else if(ret < 256)
    {
        perror("incomplete read\n");
        printf("%d\n", ret);
        return -1;
    }

    for(i = 0; i < 256; i++)
    {
        if(i % 16 == 0)
        {
            printf("\n");
        }
        printf("%03d ", read_data[i]);
    }

    printf("\ n");

    return 0;
}

This way it can be run on our development board.


Reference address:I2C bus EEPROM implementation

Previous article:I2C Serial Bus Protocol
Next article:I2C Communication EEPROM

Recommended ReadingLatest update time:2024-11-16 11:26

PIC XC8 EEPROM Operation
We need to make something with alarm function, and we need to be able to change the remote control content by remote control. Since the stability of the system is very high, we use a watchdog. However, the reset of the watchdog will cause all registers to reset and return to the default state. The contents to be cha
[Microcontroller]
STM8S Learning 05——EEPROM read and write operation C language program
/* During the project development in the past two days, the EEPROM function of STM8 was used. Several data needed to be saved after power failure. I also checked the EEPROM operation on the Internet and found that there were two main problems on the Internet: 1. EEPROM reading and writing were unsuccessful; 2. The EEP
[Microcontroller]
AT24C01-512eeprom read and write program based on AVR microcontroller
For AT24Cxx series eeprom memory, there is a page-skipping function when writing, no need to consider page boundaries, I2C is implemented by software simulation, and is being improved...   #define SDA1() PORTC|=1 PC1 //Data output 1, #define SDA0() PORTC&=~(1 PC1) //Data output 0 #define SDAout() DDRC|=1 PC1 //Dat
[Microcontroller]
The similarities and differences between Flash and EEPROM on microcontrollers
    The full name of FLASH is FLASHEEPROM, but the operation method is different from that of conventional EEPROM.     The biggest difference between FLASH and EEPROM is that FLASH operates by sector, while EEPROM operates by byte. The two have different addressing methods and different storage unit structures. The c
[Microcontroller]
(6) s3c2440 uses I2C interface to access EEPROM
After reading and understanding the official protocol document of I2C, let's use s3c2440 and EEPROM to verify it.         Originally I wanted to use the SDA and SCL pins of s3c2440 to be reused as GPIO for simulation, but after a week of doing it without an oscilloscope, I couldn't figure it out, and finally gave up.
[Microcontroller]
ATmega128(EEPROM)
//atmega128 read and write EEPROM sample program, record the number of CPU startup times in EEPROM //Display the read data on the LED digital tube, and you can use the reset button to refresh the display //Compilation environment AVR Studio 4.17/AVR GCC //System clock 7.3728MHZ, set the fuse bit to external high-fre
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号