23LC1024四线访问数据
为什么需要四线串行访问23LC1024?
在“单片机片外RAM,串行的
”中减少了对Microchip公司的SPI接口RAM芯片:23LC1024的读写测试。但是在STC8G1K08但潘辰的SPI接口驱动下,访问对其进行一次字节的读写操作,大概需要消耗20微妙的的时间,这使得在高速、高精度采集应用中跟不上数据的采集。
为了提高对其的访问速度,可以采用以下的方式:
- 使用其四线串行模式(SQI)的方式进行访问;
- 尽量使用序列读写方式,而不是每次完成完整的命令+地址+数据的腹泻方式
下面为了配合AD7606八通道AD采集模块测试
中数据的采集,首先测试23LC1024在STC8G1K08操作下访问速度
本文实验中的工程文件可以在下面资源中下载:
实验电路设计
AD工程文件目录:
AD\Test\2020\TestAD7606STC\TestAD7606STC8G.SchDoc
1. 原理图
电路板设计中采用了STC8G1K08 TSOP20封装的芯片。核心板上集成了23LC1024串行接口的RAM,对于AD7606的接口是通过ADI10芯接口连接。
▲ 原理图
2. PCB
设计电路PCB版图,适宜使用单面PCB板制作实验电路。
▲ 快速制版后的实验电路板
3. 硬件调试
软件开发所在的目录:
C51\STC\Test\2020\testAD76068G1K\TestAD76068G.uvproj
置STC8G1K08的硬件选项配置如下:
▲ 单片机硬件选项配置
主要性能测试
1. 测试单个字节读写的时间
测试标准写入函数在执行过程中,LC1024的CS的波形:
LC1024ByteWrite(0, 0, 0xff, 0xf)
写入时间为2us,CS的波形如下图所示:
▲ CS波形,时间为2.03us
读出的时间也是2.0us,
LC1024ByteRead(0x0, 0x0, 0xff)
下面是在读的时候,CLK, SO1的波形。
▲ CLK,SD1的波形
2. 连续字节读写
使用连续字节读写的方式读取多组字节。下面是读取连续10个字节。所需要的时间为8.57us。
LC1024ReadBegin(0x0, 0x0, 0x0);
LC1024WriteByte(0x0);
LC1024WriteByte(0x0);
LC1024WriteByte(0x0);
LC1024WriteByte(0x0);
LC1024WriteByte(0x0);
LC1024WriteByte(0x0);
LC1024WriteByte(0x0);
LC1024WriteByte(0x0);
LC1024WriteByte(0x0);
LC1024WriteByte(0x0);
LC1024ReadWriteEnd();
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
▲ 连续读取十个字节所需要的时间
如果仅仅执行读取起始和结束的语句:
LC1024ReadBegin(0x0, 0x0, 0x0);
LC1024ReadWriteEnd();
- 1
- 2
- 3
所小号的时间为2us。这说明读取单个字节的时间大约为 ( 8.57 − 2 ) / 10 = 0.65 μ s \left( {8.57 - 2} \right)/10 = 0.65\mu s (8.57−2)/10=0.65μs左右。
这个速度与博文“扩展32KRAM的STC8H8K信号采集版
”中,通过并口扩展RAM的一次读写时间0.532us的速度基本相当了。
通过这个时间可以说明,使用SQI(串行四线制)在连续读写的情况下可以达到与并口扩展RAM相当的速度。
即使是单个读写所消耗的2us的时间,也比在博文“单片机片外RAM,串行的
”中读取单个字节所消耗19.2us将近快了10倍左右。
▲ 通电进行调试
▲ 测量读写信号波形
函数程序模块
相关LC1024读取的程序模块如下。
其中致的说明的是,在LC1024的初始化函数中,调用了LC1024Reset命令,就保证了LC1024成功进入SQI模式。
- LC1024访问函数头文件:
/*
**==============================================================================
** LC1024L4.H: -- by Dr. ZhuoQing, 2020-05-04
**
** Description:
**
**==============================================================================
*/
#ifndef __LC1024L4__
#define __LC1024L4__
//------------------------------------------------------------------------------
#ifdef LC1024L4_GLOBALS
#define LC1024L4_EXT
#else
#define LC1024L4_EXT extern
#endif // LC1024L4_GLOBALS
//------------------------------------------------------------------------------
//==============================================================================
#define LC1024_CS 1, 5
#define LC1024_CLK 1, 4
#define LC1024_SO0 1, 0
#define LC1024_SO1 1, 1
#define LC1024_SO2 1, 2
#define LC1024_SO3 1, 3
#define LC1024_CLK_PULSE ON(LC1024_CLK),_nop_(),OFF(LC1024_CLK)
#define LC1024_SO_OUT (P1M1 &= 0xf0, P1M0|=0xf)
#define LC1024_SO_IN (P1M1 |= 0xf, P1M0 &= 0xf0)
//------------------------------------------------------------------------------
void LC1024L4Init(void);
//------------------------------------------------------------------------------
#define LC1024_READ 0x03 // Read data from memory areray beginning at selected address
#define LC1024_WRITE 0x02 // Write data to memory array beginning at selected address
#define LC1024_EDIO 0x3B // Enter Dual I/O access(Enter SDI bus mode)
#define LC1024_EQIO 0x38 // Enter Quad I/O access
#define LC1024_RSTIO 0xFF // Reset Dual and Quad I/O access
#define LC1024_RDMR 0x05 // Read Mode register
#define LC1024_WRMR 0x1 // Write Mode register
#define LONG_3(w) ((unsigned char)(w >> 24))
#define LONG_2(w) ((unsigned char)(w >> 16))
#define LONG_1(w) ((unsigned char)(w >> 8))
#define LONG_0(w) ((unsigned char)w)
//------------------------------------------------------------------------------
void LC1024Reset(void);
void LC1024EQIEnter(void);
void LC1024EQIExit(void);
//------------------------------------------------------------------------------
unsigned char LC1024ByteRead(unsigned char ucAdd2, unsigned char ucAdd1, unsigned char ucAdd0);
void LC1024ByteWrite(unsigned char ucAdd2, unsigned char ucAdd1,
unsigned char ucAdd0, unsigned char ucByte);
//------------------------------------------------------------------------------
void LC1024ReadBegin(unsigned char ucAdd2, unsigned char ucAdd1, unsigned char ucAdd0);
void LC1024WriteBegin(unsigned char ucAdd2, unsigned char ucAdd1, unsigned char ucAdd0);
unsigned char LC1024ReadByte(void);
void LC1024WriteByte(unsigned char ucByte);
void LC1024ReadWriteEnd(void);
//------------------------------------------------------------------------------
unsigned char LC1024ReadMode(void);
void LC1024WriteMode(unsigned char ucMode);
//==============================================================================
// END OF THE FILE : LC1024L4.H
//------------------------------------------------------------------------------
#endif // __LC1024L4__
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- LC1024的C语言程序。
/*
**==============================================================================
** LC1024L4.C: -- by Dr. ZhuoQing, 2020-05-04
**
**==============================================================================
*/
//------------------------------------------------------------------------------
#define LC1024L4_GLOBALS 1 // Define the global variables
#include "LC1024L4.H"
#include "C51BASIC.H"
#include "STC8G.H"
#include "INTRINS.H"
//------------------------------------------------------------------------------
void LC1024L4Init(void) {
PM_PP(LC1024_CS);
PM_PP(LC1024_CLK);
ON(LC1024_CS);
OFF(LC1024_CLK);
LC1024_SO_IN;
LC1024Reset();
LC1024EQIEnter();
}
//------------------------------------------------------------------------------
void LC1024EQIEnter(void) {
unsigned char i, ucMask, ucByte;
ucByte = LC1024_EQIO;
ucMask = 0x80;
LC1024_SO_IN;
PM_PP(LC1024_SO0);
OFF(LC1024_CS);
for(i = 0; i < 8; i ++) {
if(ucByte & ucMask) ON(LC1024_SO0);
else OFF(LC1024_SO0);
ucMask >>= 1;
LC1024_CLK_PULSE;
}
LC1024_SO_IN;
ON(LC1024_CS);
}
void LC1024EQIExit(void) {
LC1024_SO_OUT;
P1 |= 0xf;
OFF(LC1024_CS);
LC1024_CLK_PULSE;
LC1024_CLK_PULSE;
LC1024_SO_IN;
ON(LC1024_CS);
}
//------------------------------------------------------------------------------
unsigned char LC1024ByteRead(unsigned char ucAdd2, unsigned char ucAdd1, unsigned char ucAdd0) {
unsigned char ucRet;
LC1024_SO_OUT;
OFF(LC1024_CS);
P1 &= 0xf0;
LC1024_CLK_PULSE;
P1 |= 0x3;
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd2 >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd2 & 0xf);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd1 >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd1 & 0xf);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd0 >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd0 & 0xf);
LC1024_CLK_PULSE;
LC1024_SO_IN;
LC1024_CLK_PULSE; // Dummy byte
LC1024_CLK_PULSE;
ON(LC1024_CLK);
ucRet = (P1 << 4);
OFF(LC1024_CLK);
ON(LC1024_CLK);
ucRet |= (P1 & 0xf);
OFF(LC1024_CLK);
ON(LC1024_CS);
return ucRet;
}
//------------------------------------------------------------------------------
void LC1024ByteWrite(unsigned char ucAdd2, unsigned char ucAdd1,
unsigned char ucAdd0, unsigned char ucByte) {
LC1024_SO_OUT;
OFF(LC1024_CS);
P1 &= 0xf0;
LC1024_CLK_PULSE;
P1 |= 0x2;
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd2 >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd2 & 0xf);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd1 >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd1 & 0xf);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd0 >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd0 & 0xf);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucByte >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucByte & 0xf);
LC1024_CLK_PULSE;
LC1024_SO_IN;
ON(LC1024_CS);
}
//------------------------------------------------------------------------------
unsigned char LC1024ReadMode(void) {
unsigned char ucRet;
OFF(LC1024_CS);
LC1024_SO_OUT;
P1 &= 0xf0;
LC1024_CLK_PULSE;
P1 |= 0x5;
LC1024_CLK_PULSE;
LC1024_SO_IN;
ON(LC1024_CLK);
ucRet = (P1 << 4);
OFF(LC1024_CLK);
ON(LC1024_CLK);
ucRet |= (P1 & 0xf);
OFF(LC1024_CLK);
ON(LC1024_CS);
return ucRet;
}
//------------------------------------------------------------------------------
void LC1024ReadBegin(unsigned char ucAdd2, unsigned char ucAdd1, unsigned char ucAdd0) {
LC1024_SO_OUT;
OFF(LC1024_CS);
P1 &= 0xf0;
LC1024_CLK_PULSE;
P1 |= 0x3;
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd2 >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd2 & 0xf);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd1 >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd1 & 0xf);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd0 >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd0 & 0xf);
LC1024_CLK_PULSE;
LC1024_SO_IN;
LC1024_CLK_PULSE; // Dummy byte
LC1024_CLK_PULSE;
}
//------------------------------------------------------------------------------
void LC1024WriteBegin(unsigned char ucAdd2, unsigned char ucAdd1, unsigned char ucAdd0) {
LC1024_SO_OUT;
OFF(LC1024_CS);
P1 &= 0xf0;
LC1024_CLK_PULSE;
P1 |= 0x2;
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd2 >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd2 & 0xf);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd1 >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd1 & 0xf);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd0 >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucAdd0 & 0xf);
LC1024_CLK_PULSE;
}
unsigned char LC1024ReadByte(void) {
unsigned char ucRet;
ON(LC1024_CLK);
ucRet = (P1 << 4);
OFF(LC1024_CLK);
ON(LC1024_CLK);
ucRet |= (P1 & 0xf);
OFF(LC1024_CLK);
return ucRet;
}
void LC1024WriteByte(unsigned char ucByte) {
P1 &= 0xf0;
P1 |= (ucByte >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucByte & 0xf);
LC1024_CLK_PULSE;
}
//------------------------------------------------------------------------------
void LC1024ReadWriteEnd(void) {
LC1024_SO_IN;
ON(LC1024_CS);
}
//------------------------------------------------------------------------------
void LC1024WriteMode(unsigned char ucMode) {
LC1024_SO_OUT;
OFF(LC1024_CS);
P1 &= 0xf0;
LC1024_CLK_PULSE;
P1 |= 0x5;
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucMode >> 4);
LC1024_CLK_PULSE;
P1 &= 0xf0;
P1 |= (ucMode & 0xf);
LC1024_CLK_PULSE;
ON(LC1024_CS);
LC1024_SO_IN;
}
//------------------------------------------------------------------------------
void LC1024Reset(void) {
LC1024_SO_OUT;
P1 |= 0xf;
OFF(LC1024_CS);
LC1024_CLK_PULSE;
LC1024_CLK_PULSE;
LC1024_CLK_PULSE;
LC1024_CLK_PULSE;
LC1024_CLK_PULSE;
LC1024_CLK_PULSE;
LC1024_CLK_PULSE;
LC1024_CLK_PULSE;
ON(LC1024_CS);
LC1024_SO_IN;
}
//==============================================================================
// END OF THE FILE : LC1024L4.C
//------------------------------------------------------------------------------
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
文章来源: zhuoqing.blog.csdn.net,作者:卓晴,版权归原作者所有,如需转载,请联系作者。
原文链接:zhuoqing.blog.csdn.net/article/details/105919083
- 点赞
- 收藏
- 关注作者
评论(0)