小编Jac*_*ert的帖子

使用Linux通过I2C读写EEPROM

我尝试通过I2C 读取和写入带有Raspberry Pi B + 的Atmel 24C256 EEPROM,但是我无法正常工作.

这是我到目前为止的代码:

#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <linux/i2c.h>

#define DEVICE_PATH "/dev/i2c-1"

#define PAGE_SIZE 64

#define DEVICE_ADDR 0x50 // 0b1010xxxx


int file_desc;
char buffer[PAGE_SIZE + 2]; // 64 bytes + 2 for the address

void teardownI2C()
{
    int result = close(file_desc);
}

void setupI2C()
{
    file_desc = open(DEVICE_PATH, O_RDWR);
    if(file_desc < 0)
    {
    printf("%s\n", strerror(errno));
    exit(1); …
Run Code Online (Sandbox Code Playgroud)

c linux i2c eeprom raspberry-pi

3
推荐指数
2
解决办法
2万
查看次数

为什么这条汇编线是“寄存器的无效使用”?

我正在阅读一些操作系统开发教程,并且经常看到以下代码段:

.intel_syntax noprefix

do_e820:
    xor ebx, ebx        # ebx must be 0 to start
    xor bp, bp      # keep an entry count in bp
    mov edx, 0x0534D4150    # Place "SMAP" into edx
    mov eax, 0xe820
    mov [es:di + 20], dword 1   # <<<this is the line I don't get
    mov ecx, 24     # ask for 24 bytes
    int 0x15
    jc short .failed    # carry set on first call means "unsupported function"
    mov edx, 0x0534D4150    # Some BIOSes apparently trash this …
Run Code Online (Sandbox Code Playgroud)

x86 assembly memory-mapping

1
推荐指数
1
解决办法
1641
查看次数

标签 统计

assembly ×1

c ×1

eeprom ×1

i2c ×1

linux ×1

memory-mapping ×1

raspberry-pi ×1

x86 ×1