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
< > 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.
Previous article:I2C Serial Bus Protocol
Next article:I2C Communication EEPROM
Recommended ReadingLatest update time:2024-11-16 11:26
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Wireless connectivity and lighting solutions for equipment in smart buildings
- MSP430F5438 Research Experience
- Automatic focusing system based on DSP chip TMS320F206 for numerical calculation and implementation control
- BT8896A Specification (Zhongke Bluexun)
- What is the amplification factor of this op amp?
- Multisim simulation of infinite gain multi-channel negative feedback (MFB) second-order Butterworth low-pass filter
- Help with "How to select capacitor voltage for VBAT pin of SIM900A?"
- Request a Free VICOR UHV BCM Evaluation Sample
- IBM develops 2-nanometer chip
- Crazy Shell AI open source drone ADC (joystick control)