C2协议标准
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. |
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
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
Instruction | INS Code |
---|---|
Data Read | 00b |
Address Read | 1 |
Data Write | 01b |
Address Write | 11b |
查看Table 1.3. C2 Bit Field Descriptions
此表讲述了有关于帧 的详细内容。
This instruction is typically used to quickly access status information。
An Address Write frame loads the target Address register。
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
。
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
P0.7 - MCU_C2CK2 - C2CK
P1.0 - MCU_C2DAT2 - C2D
增加了一个设备的开关操作。对于MCU_master而言需要传送数据显然需要将其引脚设置为push pull
void C2CK_DriverOn(void){ P0MDOUT |= 0x80; }// P0 ^ 7 push pull
void C2CK_DriverOff(void){
P0 |= 0x80; // P0 ^ 7 set 1
P0MDOUT &= (~0x80); // set P0^7 out open-drain
}
void C2D_DriverOn(void){
P1MDOUT |= 0x01;
}
void C2D_DriverOff(void){
P1 |= 0x01;
P1MDOUT &= (~0x01);
}
开启引脚就是将其设置为强推。关闭就是将其设置为开漏。没有驱动能力。
To generate the reset timing:
SetC2CK(LOW);
Delay_us(20);
SetC2CK(HIGH);
To generate C2CK clock strobes with a microcontroller-based programmer:
void StrobeC2CK(void)
{
SetC2CK(LOW);
SetC2CK(HIGH);
}
注意 这里没有实现第一个步骤
因此调用StrobeC2CK之前需要确定C2CK为高电平
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:
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 field
StrobeC2CK();
C2CK_DriverOff();
EA = EA_SAVE;
}
解释
看了9号
步骤才发现为什么在C2D_DriverOff
以及C2CK_DriverOff
为什么还需要将引脚从推挽
设置为开漏
。此时应该是需要接受来自target device
输入。若是设置为推挽
,那么target device
就没有能力将引脚拉低,表示不了低电平。
To read the status code from a target device’s ADDRESS register:
基本和地址写指令区别不大,就是关闭中断然后引脚的设置
unsigned char C2_ReadAR(void)
{
static bit EA_SAVE = EA;
EA = 0;
C2CK_DriverOn();
// START field
StrobeC2CK();
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;
}
void C2_WriteDR(unsigned char dat)
{
unsigned char i;
static bit EA_SAVE;
EA_SAVE = EA;
EA = 0;
// START field
C2CK_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 field
for (i = 0; i < 8; i++)
{
SetC2D(dat & 0x01);
StrobeC2CK();
dat >>= 1;
}
C2D_DriverOff();
// WAIT field
do
{
StrobeC2CK();
} while (!GetC2D());
// STOP field
StrobeC2CK();
C2CK_DriverOff();
EA = EA_SAVE;
}
unsigned char C2_ReadDR(void)
{
unsigned char i;
unsigned char dat;
static bit EA_SAVE;
EA_SAVE = EA;
EA = 0;
// START field
C2CK_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 field
do
{
StrobeC2CK();
} while (!GetC2D());
// DATA field
dat = 0;
for (i = 0; i < 8; i++)
{
dat >>= 1;
StrobeC2CK();
if (GetC2D())
dat |= 0x80;
}
// STOP field
StrobeC2CK();
C2CK_DriverOff();
EA = EA_SAVE;
return dat;
}
C2 isolation circuitry
Markdown使用技巧总结——字体,颜色,字号,背景,首行缩进等
C2 协议标准手册
CSDN-markdown 扩展教程