查看: 3547|回复: 4

[求助] M41T81rtc时间不走

[复制链接]

该用户从未签到

7

主题

17

帖子

0

注册会员

Rank: 2

积分
77
最后登录
2016-8-3
发表于 2016-7-28 11:26:33 | 显示全部楼层 |阅读模式
各位大大好!

我在i2c上面接了一个M41T81芯片,然后根据数据手册,直接利用i2c来读取8个时间寄存器的数据。发现读出来的时间都是最大值

X9@JFER_[TM$}GDTGFEAA.png

0x00 0xff 0x7f 0x7f 0x3f 0x07 0x3f 0x1f 0xff

文档上面有说ST位置为0的时候晶振就可以起振。“寄存器01h的第7位D7 含义是停止位(ST)
当把这一位设置为1 时将使振荡器停止振荡假如期望该器件废除大量的计时振荡
器可以被停止振荡以减小电流的消耗当复位以后为0 振荡器在一秒之内重新启振”

于是我就把01H置为了0x00 然后把02H置为了 0x04,等了几分钟,发现读出来的值还是0x04。开始以为是晶振没有起振,但是用示波器量了,发现是可以起振的。

那我是不是有什么地方没有配置好,或者什么地方操作不当呢。

还有,在内核中看到M41T80的驱动,不知道能不能用在我这上面,如果可以,怎么去使用呢,之前没有搞过,有点懵。
我知道答案 目前已有4人回答
回复

使用道具 举报

  • TA的每日心情

    2017-1-4 08:05
  • 签到天数: 11 天

    连续签到: 1 天

    [LV.3]偶尔看看II

    85

    主题

    1629

    帖子

    1

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    2569

    优秀版主

    最后登录
    2019-3-28
    发表于 2016-7-28 11:49:36 | 显示全部楼层
    LZ方便把自己的读写流程简要的描述一下吗?
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    7

    主题

    17

    帖子

    0

    注册会员

    Rank: 2

    积分
    77
    最后登录
    2016-8-3
     楼主| 发表于 2016-7-28 13:33:46 | 显示全部楼层
    技术范儿 发表于 2016-7-28 11:49
    LZ方便把自己的读写流程简要的描述一下吗?

    #include <stdio.h>
    #include <linux/types.h>
    #include <stdlib.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/ioctl.h>
    #include <errno.h>
    #define I2C_RETRIES 0X0701
    #define I2C_TIMEOUT 0X0702
    #define I2C_RDWR 0X0707
    #define I2C_SLAVE_ADDR 0x68  

    struct i2c_msg
    {
            unsigned short addr;
            unsigned short flags;
    #define I2C_M_TEN 0X0010
    #define I2C_M_RD 0X0001
            unsigned short len;
            unsigned char *buf;
    };

    struct i2c_rdwr_ioctl_data
    {
            struct i2c_msg *msgs;
            int nmsgs;
    };

    int main(int argc ,char* argv[])
    {
            int fd,ret;
            struct i2c_rdwr_ioctl_data e2prom_data;
           
            fd = open("/dev/i2c-2",O_RDWR);
            if(fd<0)
            {
                    perror("open error\n");
            }

            e2prom_data.nmsgs = 2;
            e2prom_data.msgs = (struct i2c_msg*)malloc(e2prom_data.nmsgs*sizeof(struct i2c_msg));
            if(!e2prom_data.msgs)
            {
                    perror("malloc error\n");
            }
        ret = ioctl(fd,I2C_TIMEOUT,1);
    //        printf("%d\n",ret);
            ret = ioctl(fd,I2C_RETRIES,2);
    //        printf("%d\n",ret);


            e2prom_data.nmsgs = 1;
            (e2prom_data.msgs[0]).len = 2;
            (e2prom_data.msgs[0]).addr = I2C_SLAVE_ADDR;
            (e2prom_data.msgs[0]).flags = 0;
            (e2prom_data.msgs[0]).buf = (unsigned char*)malloc(2);
            (e2prom_data.msgs[0]).buf[0] = 0x01;
            (e2prom_data.msgs[0]).buf[1] = 0x00;
            ret = ioctl(fd,I2C_RDWR,(unsigned long)&e2prom_data);
           
            if(ret < 0)
            {
                    perror("ioctl error1\n");
            }

    //set time
            e2prom_data.nmsgs = 1;
            (e2prom_data.msgs[0]).len = 2;
            (e2prom_data.msgs[0]).addr = I2C_SLAVE_ADDR;
            (e2prom_data.msgs[0]).flags = 0;
    //        (e2prom_data.msgs[0]).buf = (unsigned char*)malloc(2);
            (e2prom_data.msgs[0]).buf[0] = 0x02;
           
            (e2prom_data.msgs[0]).buf[1] = 0x04;
    /*        (e2prom_data.msgs[0]).buf[2] = 0x59;
            (e2prom_data.msgs[0]).buf[3] = 0x59;
            (e2prom_data.msgs[0]).buf[4] = 0x16;
            (e2prom_data.msgs[0]).buf[5] = 0x04;
            (e2prom_data.msgs[0]).buf[6] = 0x25;
            (e2prom_data.msgs[0]).buf[7] = 0x07;
            (e2prom_data.msgs[0]).buf[8] = 0x16;
    */               
            ret = ioctl(fd,I2C_RDWR,(unsigned long)&e2prom_data);

            if(ret < 0)
            {
                    perror("ioctl error2");
            }

            sleep(5);

    //read time
            e2prom_data.nmsgs = 2;
            (e2prom_data.msgs[0]).len = 1;
            (e2prom_data.msgs[0]).addr = I2C_SLAVE_ADDR;       
            (e2prom_data.msgs[0]).flags = 0;
            (e2prom_data.msgs[0]).buf = (unsigned char*)malloc(1);
            (e2prom_data.msgs[0]).buf[0] = 0x08;
           
            (e2prom_data.msgs[1]).len = 1;
            (e2prom_data.msgs[1]).addr = I2C_SLAVE_ADDR;
            (e2prom_data.msgs[1]).flags = I2C_M_RD;
            (e2prom_data.msgs[1]).buf = (unsigned char*)malloc(1);
            (e2prom_data.msgs[1]).buf[0] = 0;

            ret = ioctl(fd,I2C_RDWR,(unsigned long)&e2prom_data);
            if(ret<0)
            {
                    perror("ioctl error3");
            }

           
            printf("buf[0] = %x\n",(e2prom_data.msgs[1]).buf[0]);
    /*        printf("buf[1] = %x\n",(e2prom_data.msgs[1]).buf[1]);
            printf("buf[2] = %x\n",(e2prom_data.msgs[1]).buf[2]);
            printf("buf[3] = %x\n",(e2prom_data.msgs[1]).buf[3]);
            printf("buf[4] = %x\n",(e2prom_data.msgs[1]).buf[4]);
            printf("buf[5] = %x\n",(e2prom_data.msgs[1]).buf[5]);
            printf("buf[6] = %x\n",(e2prom_data.msgs[1]).buf[6]);
            printf("buf[7] = %x\n",(e2prom_data.msgs[1]).buf[7]);
    */       
            free((e2prom_data.msgs[1]).buf);
            free(e2prom_data.msgs);
                   
            close(fd);
           
            return 0;
    }
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    7

    主题

    17

    帖子

    0

    注册会员

    Rank: 2

    积分
    77
    最后登录
    2016-8-3
     楼主| 发表于 2016-7-28 13:35:27 | 显示全部楼层
    技术范儿 发表于 2016-7-28 11:49
    LZ方便把自己的读写流程简要的描述一下吗?

    然后我又另外写了一个只有读取的程序  读0x04的数据
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    7

    主题

    17

    帖子

    0

    注册会员

    Rank: 2

    积分
    77
    最后登录
    2016-8-3
     楼主| 发表于 2016-7-28 13:37:49 | 显示全部楼层
    技术范儿 发表于 2016-7-28 11:49
    LZ方便把自己的读写流程简要的描述一下吗?

    e2prom_data.nmsgs = 2;
            (e2prom_data.msgs[0]).len = 1;
            (e2prom_data.msgs[0]).addr = I2C_SLAVE_ADDR;        
            (e2prom_data.msgs[0]).flags = 0;
            (e2prom_data.msgs[0]).buf = (unsigned char*)malloc(1);
            (e2prom_data.msgs[0]).buf[0] = 0x08;
            
            (e2prom_data.msgs[1]).len = 1;
            (e2prom_data.msgs[1]).addr = I2C_SLAVE_ADDR;
            (e2prom_data.msgs[1]).flags = I2C_M_RD;
            (e2prom_data.msgs[1]).buf = (unsigned char*)malloc(1);
            (e2prom_data.msgs[1]).buf[0] = 0;

    对了,读这一块地址0x08是我后来测试的时候改的。之前是0x04的
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-21 00:35 , Processed in 0.095319 second(s), 26 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表