C2

C2协议标准

  • Each C2 frame is initiated with a START condition
  • Each C2 frame terminates with a STOP condition
  • All C2 devices include an 8-bit Device ID register and an 8-bit Revision ID register

寄存器

ADDRESS: Address Register

  • 1.ADDRESS selects which C2 Data register is accessed during C2 Data Read/Write frames.
  • 2.During Address Read frames, ADDRESS provides PI status information.

The Address Read command returns an 8-bit status code

Bit Name Description
7 EBusy or FLBusy This bit indicates when the EPROM or Flash is busy completing an operation.
6 EError This bit is set to 1 when the EPROM encounters an error.
5:2 Unused
1 InBusy This bit is set to 1 by the C2 Interface following a write to FPDAT. It is cleared to 0 when the PI acknowledges the write to FPDAT.
0 OutReady This bit is set to 1 by the PI when output data is available in the FPDAT regis-ter.

DEVICEID: Device ID Register

The Device ID register (DEVICEID) is a read-only C2 Data register containing the 8-bit device identifier of the target C2 device. The C2 address for register DEVICEID is 0x00

REVID: Revision ID Register

The Revision ID register (REVID) is a read-only C2 Data register containing the 8-bit revision identifier of the target C2 device. The C2 address for register REVID is 0x01

Data Register 0 ~ Data Register M-1
Revision ID (REVID)
Device ID (DEVICEID)
ADDRESS

帧 C2 Instruction Frames

master访问目标device 有四种基本格式

Instruction INS Code
Data Read 00b
Address Read 1
Data Write 01b
Address Write 11b

查看Table 1.3. C2 Bit Field Descriptions
此表讲述了有关于帧 的详细内容。

Address Read Frame


This instruction is typically used to quickly access status information。

Address Write Frame


An Address Write frame loads the target Address register。


Data Write Frame


A Data Write frame writes a specified value to the target Data register, as selected by the target Address register.
DATA length in bytes = LENGTH + 1。
如果要传递的数据是一个字节。那么INS字段的值就应该是00b

Data Read Frame


A Data Read frame reads the contents of the target Data register, as selected by the target Address register.

Address Write,
Address Read,
Data Write,
Data Read
  • 两个CPU。

    • MCU_master
    • MCU_key
      MCU_master模拟C2协议给MCU_key烧写程序。

C2 Timing Specifications 时序图

Device Reset Timing

Address Write Timing

Address Read Timing

Data Write Timing

Data Read Timing

引脚分配

  • MCU_master
P0.7  - MCU_C2CK2  - C2CK
P1.0  - MCU_C2DAT2 - C2D

需要注意的事项

  • 1.If the C2CK master is an MCU, care should be taken to disable interrupts while C2CK is low in order to prevent a clock low time extending beyond 5 μs and potentially causing a target device reset.

C2相应的操作

增加了一个设备的开关操作。对于MCU_master而言需要传送数据显然需要将其引脚设置为push pull

void C2CK_DriverOn(void){ P0MDOUT |= 0x80; }// P0 ^ 7 push pull
void C2CK_DriverOff(void){ P0 |= 0x80;         // P0 ^ 7 set 1P0MDOUT &= (~0x80); // set P0^7 out  open-drain}
void C2D_DriverOn(void){P1MDOUT |= 0x01;
}
void C2D_DriverOff(void){P1 |= 0x01;P1MDOUT &= (~0x01);
}

开启引脚就是将其设置为强推。关闭就是将其设置为开漏。没有驱动能力。

Device Reset

To generate the reset timing:

  1. Turn the C2CK driver on.
  2. Force C2CK low.
  3. Wait at least 20 μs.
  4. Force C2CK high.
  5. Wait at least 2 μs.
  6. (Optional) Turn the C2CK driver off.
    SetC2CK 高电平时一个下降沿保持最少tRD的时间然后一个上升沿。
  SetC2CK(LOW);Delay_us(20);SetC2CK(HIGH);

C2CK Clock Strobes

To generate C2CK clock strobes with a microcontroller-based programmer:

  1. Turn the C2CK driver on.
  2. Wait at least 40 ns. This helps ensure C2D data setup time.
  3. Force C2CK low. Ensure interrupts are disabled at this point.
  4. Wait between 80 and 5000 ns.
  5. Force C2CK high.
  6. Wait at least 120 ns. This helps ensure C2D data valid time.
void StrobeC2CK(void)
{SetC2CK(LOW);SetC2CK(HIGH);
}

注意 这里没有实现第一个步骤
因此调用StrobeC2CK之前需要确定C2CK为高电平

Performing the Address Write Instruction

The C2CK strobes mentioned in this section refer to the steps described in 1.5.2 C2CK Clock Strobes. To write to a target device’s ADDRESS register:

  1. Disable interrupts.
  2. Turn the C2CK driver on.
  3. Strobe C2CK. This will generate the START field and forces the C2D pin on the target device to become an input.
  4. Turn on the C2D driver.
  5. Force C2D high. This sets C2D for the 2-bit INS field, and the Address Write instruction is 11b.
  6. Strobe C2CK. This transfers the first bit of the INS field.
  7. Strobe C2CK. This transfers the second bit of the INS field.
  8. Force C2D to each bit of the address value being written to ADDRESS (starting with bit 0) and strobe C2CK for each bit.
  9. Turn off the C2D driver. This prepares C2D to possibly become an output from the target device.
  10. Strobe C2CK to generate the STOP field.
  11. (Optional) Turn off the C2CK driver.
  12. Re-enable interrupts.
void C2_WriteAR(unsigned char addr)
{static bit EA_SAVE = EA;EA = 0;C2CK_DriverOn();StrobeC2CK();C2D_DriverOn();SetC2D(HIGH);StrobeC2CK();//SetC2D(HIGH);  不确定需不需要再次实现C2D拉高 先保留着看一看StrobeC2CK();for (i = 0; i < 8; i++){SetC2D(addr & 0x01);StrobeC2CK();addr >>= 1;}  //发送每个字节 注意先发送低字节。C2D_DriverOff();// STOP fieldStrobeC2CK();C2CK_DriverOff();EA = EA_SAVE;
}

解释
看了9号步骤才发现为什么在C2D_DriverOff以及C2CK_DriverOff为什么还需要将引脚从推挽设置为开漏。此时应该是需要接受来自target device输入。若是设置为推挽,那么target device就没有能力将引脚拉低,表示不了低电平。

Performing the Address Read Instruction

To read the status code from a target device’s ADDRESS register:

  1. Disable interrupts.
  2. Turn the C2CK driver on.
  3. Strobe C2CK. This will generate the START field and forces the C2D pin on the target device to become an input.
  4. Turn on the C2D driver.
  5. Force C2D low. This sets C2D for the first part of the 2-bit INS field, and the Address Read instruction is 01b.
  6. Strobe C2CK. This transfers the first bit of the INS field.
  7. Force C2D high. This sets C2D for the second part of the 2-bit INS field.
  8. Strobe C2CK. This transfers the second bit of the INS field.
  9. Turn off the C2D driver. This prepares C2D to become an output from the target device.
  10. Strobe C2CK and read C2D from the target device. The device will return the 8-bit status code returned from an Address Read instruction bit by bit starting with bit 0. C2CK must be strobed after each read of C2D.
  11. Strobe C2CK to generate the STOP field.
  12. (Optional) Turn off the C2CK driver.
  13. Re-enable interrupts.

基本和地址写指令区别不大,就是关闭中断然后引脚的设置

unsigned char C2_ReadAR(void)
{static bit EA_SAVE = EA;EA = 0;C2CK_DriverOn();// START fieldStrobeC2CK();C2D_DriverOn();//This sets C2D for the first part of the 2-bit INS field, and the Address Read instruction is 01b.SetC2D(LOW);//This transfers the first bit of the INS field.StrobeC2CK();This sets C2D for the second part of the 2-bit INS field.SetC2D(HIGH);// This transfers the second bit of the INS field.StrobeC2CK();C2D_DriverOff();for (i = 0; i < 8; i++){addr >>= 1;StrobeC2CK();if (GetC2D()) {addr |= 0x80;}  // 先接受bit0//STOP field.StrobeC2CK();C2CK_DriverOff();EA = EA_SAVE;return addr;
}

Performing the Data Write Instruction

  1. Disable interrupts.
  2. Turn on the C2CK driver.
  3. Strobe C2CK. This will generate the START field and forces the C2D pin on the target device to become an input.
  4. Turn on the C2D driver.
  5. Force C2D high. This sets C2D for the first part of the 2-bit INS field, and the Data Write instruction is 10b.
  6. Strobe C2CK. This transfers the first bit of the INS field.
  7. Force C2D low. This sets C2D for the second part of the 2-bit INS field.
  8. Strobe C2CK. This transfers the second bit of the INS field.
  9. Leave C2D low. This is the start of the LENGTH field, which will be 00b in this example.
  10. Strobe C2CK to start the LENGTH field.
  11. Strobe C2CK to finish transferring the LENGTH field.
  12. Force C2D to each bit of the data value being written to the data register (starting with bit 0) and strobe C2CK for each bit.
  13. Turn off the C2D driver. This prepares C2D to become an output from the target device.
  14. Srobe C2CK.
  15. Check C2D for a value of 1b. If C2D becomes 1, the WAIT field is over, as it can contain zero or more 0’s and exactly one 1b. If
    C2D is not 1b, strobe C2CK and check the status again.
  16. At this point, C2D is driving a 1, indicating the end of the WAIT field. Strobe C2CK to generate the STOP field.
  17. (Optional) Turn off the C2CK driver.
  18. Re-enable interrupts.
void C2_WriteDR(unsigned char dat)
{unsigned char i;static bit EA_SAVE;EA_SAVE = EA;EA = 0;// START fieldC2CK_DriverOn();StrobeC2CK();// INS field (01b, LSB first)C2D_DriverOn();SetC2D(HIGH);StrobeC2CK();SetC2D(LOW);StrobeC2CK();// LENGTH field (00b -> 1 byte)SetC2D(LOW);StrobeC2CK();SetC2D(LOW);StrobeC2CK();// DATA fieldfor (i = 0; i < 8; i++){SetC2D(dat & 0x01);StrobeC2CK();dat >>= 1;}C2D_DriverOff();// WAIT fielddo{StrobeC2CK();} while (!GetC2D());// STOP fieldStrobeC2CK();C2CK_DriverOff();EA = EA_SAVE;
}

Performing the Data Read Instruction

  1. Disable interrupts.
  2. Turn on the C2CK driver.
  3. Strobe C2CK. This will generate the START field and forces the C2D pin on the target device to become an input.
  4. Turn on the C2D driver.
  5. Force C2D low. This sets C2D for the first part of the 2-bit INS field, and the Data Read instruction is 00b.
  6. Strobe C2CK to transfer the first bit of the INS field.
  7. Strobe C2CK to transfer the second bit of the INS field.
  8. Leave C2D low. This is the start of the LENGTH field, which will be 00b in this example.
  9. Strobe C2CK to start the LENGTH field.
  10. Strobe C2CK to finish transferring the LENGTH field.
  11. Turn off the C2D driver. This prepares C2D to become an output from the target device.
  12. Strobe C2CK.
  13. Check C2D for a value of 1b. If C2D becomes 1, the WAIT field is over, as it can contain zero or more 0’s and exactly one 1b. If
    C2D is not 1b, strobe C2CK and check the status again.
  14. At this point, C2D is driving a 1, indicating the end of the WAIT field.
    15.Strobe C2CK and read C2D from the target device. The device will return the contents of the data register bit by bit starting with bit
  15. C2CK must be strobed after each read of C2D.
  16. Strobe C2CK to generate the STOP field.
  17. (Optional) Turn off the C2CK driver.
  18. Re-enable interrupts.
unsigned char C2_ReadDR(void)
{unsigned char i;unsigned char dat;static bit EA_SAVE;EA_SAVE = EA;EA = 0;// START fieldC2CK_DriverOn();StrobeC2CK();// INS field (00b, LSB first)C2D_DriverOn();SetC2D(LOW);StrobeC2CK();SetC2D(LOW);StrobeC2CK();// LENGTH field (00b -> 1 byte)SetC2D(LOW);StrobeC2CK();SetC2D(LOW);StrobeC2CK();C2D_DriverOff();// WAIT fielddo{StrobeC2CK();} while (!GetC2D());// DATA fielddat = 0;for (i = 0; i < 8; i++){dat >>= 1;StrobeC2CK();if (GetC2D())dat |= 0x80;}// STOP fieldStrobeC2CK();C2CK_DriverOff();EA = EA_SAVE;return dat;
}

Programming Registers

  • FPCTL: Flash Programming Control Register
  • FPDAT: Flash Programming Data Register
  • EPCTL: EPROM Programming Control Register
  • EPDAT: EPROM Programming Data Register
  • EPADDRH and EPADDRL: EPROM Programming Address
  • EPSTAT: EPROM Programming Status

其他

C2 isolation circuitry

参考资料

Markdown使用技巧总结——字体,颜色,字号,背景,首行缩进等
C2 协议标准手册
CSDN-markdown 扩展教程

C8051F310 模拟C2协议浅析与实现相关推荐

  1. swift int转string_Swift集合类型协议浅析(下)

    关注[搜狐技术产品]公众号,第一时间获取技术干货 导读 本篇是Swift集合类型协议浅析系列文章的下篇,在这篇文章中,我们将继续围绕集合类型协议展开讨论,侧重点更多地关注于String相关的周边协议. ...

  2. 【IoT】基于NB-IoT的CoAP协议浅析

    [IoT]基于NB-IoT的CoAP协议浅析 CoAP(Constrained Application Protocol) 协议是 IETF 提出的一种面向网络的协议,采用了与 HTTP 类似的特征, ...

  3. UniSwap V3协议浅析(下)

    文章前言 本篇文章我们继续接着之前的UniSwap V3协议浅析(上)来进行分析Uniswap v3设计 源码分析 UniswapV3Factory UniswapV3Factory的主要功能是提供创 ...

  4. 路由器密码和上网账号密码都忘记了怎么办,可以通过模拟PPPoE协议从路由器获取

    假如忘记了上网账号和密码,最简单的就登上路由器看看就知道,但如果路由器的秘密也忘记该怎么办? 还有个办法就是通过模拟PPPoE协议从路由器获取. 路由器通常是通过PPPoE协议接入网络,在路由器连通时 ...

  5. STM32模拟I2C协议获取MLX90615红外温度传感器测温数据(Open Drain管脚配置)

    STM32模拟I2C协议获取MLX90615红外温度传感器测温数据(Open Drain管脚配置) STM32的GPIO管脚可以配置为Open Drain输出模式,并且有两个功能: 可以设置内部上拉, ...

  6. STM32模拟IIC协议驱动AD7991/AD7995/AD7999芯片

    STM32模拟IIC协议驱动AD7991/AD7995/AD7999芯片 AD7991/AD7995/AD7999是12位/10位/8位 4通道模拟输入的AD转换芯片 通信方式采用的是:I2C 芯片供 ...

  7. 分享一个iec104协议的资源,一个模拟iec104协议主站端的小工具

    最近编写的iec104协议的软件也基本稳定了,现在上传到资源上去留作备份. 可实现功能: V1.005 2019.331 1.增加启动调用可执行文件目录下104.ini,调用遥信点表功能:增加显示SO ...

  8. Socket模拟HTTP协议之火车票购票软件

    前段时间我发布过一篇文章描述Socket进行HTTP/HTTPS操作,但是还是很多朋友觉得多次一举,放着简单的HttpWebRequest不用! 实际是有些人根本没看文章就乱说了,我们的目地是提高访问 ...

  9. 一致性协议浅析:从逻辑时钟到Raft

    前言 春节在家闲着没事看了几篇论文,把一致性协议的几篇论文都过了一遍.在看这些论文之前,我一直有一些疑惑,比如同样是有Leader和两阶段提交,Zookeeper的ZAB协议和Raft有什么不同,Pa ...

最新文章

  1. Android窗口管理服务WindowManagerService计算窗口Z轴位置的过程分析
  2. python中pow是什么函数_python中pow什么意思
  3. python谁的课比较好-【年度系列】2018年学习Python最好的5门课程
  4. Verilog_Day2
  5. python selenium 保存网页_python selenium+pywin32 实现网页另存为
  6. struts result type redirect 重定向和转发的区别
  7. 从0到1使用VUE-CLI3开发实战(五):模块化VUEX及使用vuetify
  8. python字典与顺序有关吗_python – 为什么在字典和集合中的顺序是任意的?
  9. python接口自动化(一)--什么是接口、接口优势、类型(详解)
  10. 马化腾亲自写腾讯网站,雷军靠写程序赚到第一个100万...那些码农出身的互联网大佬们...
  11. Java StringBuilder
  12. 【图像处理】基于matlab GUI图像全局+局部美化【含Matlab源码 1461期】
  13. 动态在网络图片上写字
  14. 第十三届第一场蓝桥杯嵌入式主观题讲解
  15. solidworks电气元件3d库_送软件 | 零基础也可以学的EPLAN电气设计实战教程
  16. 几个很实用的软件 root 改机 软改 硬改 改串号 改设备 参数生成器APK 电脑软件
  17. 慎用windows EFS文件加密
  18. 京东评价系统海量数据存储设计
  19. 如何重装oracle数据库,oracle数据库的重装
  20. Latex设置指定区域的行距

热门文章

  1. 武装服务器(一):云服务器配置aliyundriver-webdav以及使用Aria2和Rclone挂载阿里云盘实现离线下载器
  2. 测试开发工作者日记:2020.10.19
  3. 简单步骤,使用 Android studio 实现保存 QQ 账号密码,和简易 QQ 用户登录界面
  4. 数据库和计算机实验小结,计算机——数据库实验报告.doc
  5. c语言手册 html,C语言版完全指引手册beta版——初到者必读 — 编程爱好者社区...
  6. 2555555555555555555
  7. 水库防汛泄洪抢险应急广播系统解决方案
  8. 高德地图--- 会动的小汽车(行动轨迹回放)demo效果(整理)
  9. PHP Framework 数据库框架 Medoo 2.1:使用 Medoo 连接MYSQL数据库
  10. ProMax v2.0.7047 1CD流程模拟软件