atsh204a加密芯片i2c通讯介绍

版权声明: https://blog.csdn.net/hecong129/article/details/82219166

两年前写了套加密芯片程序,现在有新需求.
一看代码,通讯细节一脸懵逼.特记录笔记如下:

i2C通讯:
接收包结构:

byte Name meaning
0 count 包的长度
1 to N-2 Date-Packet 协议包内容,每个命令的协议包内容组成都有差异
N-1 N checksum 两个字节的校验和

发送包结构:

byte Name meaning
0 command 命令字,不计入count和CRC
1 count 包长度, 不包含命令字
2 Opcode 具体操作指令 如 read: 0x2
3 pare1 4字节(0x00)或32字节(0x80)指令 位操作 | 上对应区域 cfg 0, otp 1, data 2
4-5 pare2 寄存器地址 4低字节,5高字节
Data 数据包
N-1 N CRC 校验和

Command 命令字解析:

命令类型 解析
0 reset 清空加密芯片内部buffer,记数归0
1 sleep 进入低功耗
2 idle 进入空闲
3 正常操作 通讯读写的时候跟随该参数
4 其他 保留


    //buf[0-1] = 0xC8; // i2c addr  i2c地址
    buf[0] = 0x03;     // option command 命令字 
    buf[1] = 7;        // len  长度
    buf[2] = 0x02; // CMD read  
    buf[3] = 0; //80 32byte 4byte mode 4byte 32byte | cfg:0 otp:1 data 2
    // 表示4字节, cfg区域.
    buf[4] = 0; // 低字节,0寄存器地址
    buf[5] = 0; // 高字节,
    sha204c_calculate_crc(5,&buf[1],&buf[6]); //计算两位校验和
    hal_i2c_send(buf,8); //发送
    hal_i2c_receive(buf2,7); //接收
    for(i=0; i<7; i++)
    {
        printk("!!!! %2X: \n",buf2[i]);
    }

猜你喜欢

转载自blog.csdn.net/hecong129/article/details/82219166
I2C