STM32F103学习笔记——AS608指纹识别模块的使用

本文最后更新于:2022年5月29日 上午

在STM32F103C8T6上成功测试运行,移植修改战舰源码,不用LCD屏幕来测试,只用串口助手来进行指纹模块的测试,具体有录入指纹、删除指纹、刷指纹等操作。

一、ATK-AS608指纹模块介绍

ATK-AS608指纹模块为集成了光路和指纹处理部分的一体化指纹处理模块,具有体积小、功耗低、接口简单的特点,可靠性高、识别速度快、干湿手指适应性好,指纹搜索速度快。ATK-AS608模块通讯接口为USB和UART两种通信接口。详细资料在百度网盘,自行下载即可。

Q73oRg.png

二、开始移植代码

1,串口通讯

ATK-AS608指纹模块与STM32使用串口2进行通讯,串口3连接电脑进行调式信息输出。

将C库printf、scanf函数重定向到USART3端口,方便进行调式信息输出输入。

(1)usart.h
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
#ifndef __USART_H
#define __USART_H

#include "stm32f10x.h"
#include "stdio.h"
#include "time.h"

#define AS608_MAX_RECV_LEN 400 //最大接收缓存字节数
#define AS608_MAX_SEND_LEN 400 //最大发送缓存字节数
#define AS608_RX_EN 1 //0,不接收;1,接收.

extern uint8_t AS608_RX_BUF[AS608_MAX_RECV_LEN]; //接收缓冲,最大USART2_MAX_RECV_LEN字节
extern uint8_t AS608_TX_BUF[AS608_MAX_SEND_LEN]; //发送缓冲,最大USART2_MAX_SEND_LEN字节
extern vu16 AS608_RX_STA; //接收数据状态

//Pin definition
/*************************************************************************/
#define DEBUG_USART USART3
#define DEBUG_USART_CLK RCC_APB1Periph_USART3
#define DEBUG_USART_AF RCC_APB2Periph_AFIO
#define DEBUG_USART_GPIO_CLK RCC_APB2Periph_GPIOB
#define DEBUG_USART_BAUDRATE 115200

#define DEBUG_USART_RX_GPIO_PORT GPIOB
#define DEBUG_USART_RX_PIN GPIO_Pin_11

#define DEBUG_USART_TX_GPIO_PORT GPIOB
#define DEBUG_USART_TX_PIN GPIO_Pin_10

#define DEBUG_USART_IRQ USART3_IRQn
#define DEBUG_USART_IRQHandler USART3_IRQHandler


#define AS608_USART USART2
#define AS608_USART_CLK RCC_APB1Periph_USART2
#define AS608_USART_AF RCC_APB2Periph_AFIO
#define AS608_USART_GPIO_CLK RCC_APB2Periph_GPIOA
#define AS608_USART_BAUDRATE 115200

#define AS608_USART_RX_GPIO_PORT GPIOA
#define AS608_USART_RX_PIN GPIO_Pin_3

#define AS608_USART_TX_GPIO_PORT GPIOA
#define AS608_USART_TX_PIN GPIO_Pin_2

#define AS608_USART_IRQ USART2_IRQn
#define AS608_USART_IRQHandler USART2_IRQHandler
/******************************************************************************/

void USART_Config(void);
void Usart_SendByte( USART_TypeDef * pUSARTx, uint8_t ch);
void Usart_SendString( USART_TypeDef * pUSARTx, char *str);
void Usart_SendHalfWord( USART_TypeDef * pUSARTx, uint16_t ch);
int fputc(int ch, FILE *f);
int fgetc(FILE *f);

#endif /* __USART_H */

(2)usart.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
/**
******************************************************************************
* @file uasrt.c
* @author Soso
* @date 2019-12-17
* @brief USART1(AS608_USART) and USART3(DEBUG_USART) driver configuration code.
Redirect c library printf function to USART3 port.
******************************************************************************
*/

#include "usart.h"

//串口接收缓存区
uint8_t AS608_RX_BUF[AS608_MAX_RECV_LEN]; //接收缓冲,最大AS608_MAX_RECV_LEN个字节.
uint8_t AS608_TX_BUF[AS608_MAX_SEND_LEN]; //发送缓冲,最大AS608_MAX_SEND_LEN字节

//通过判断接收连续2个字符之间的时间差不大于10ms来决定是不是一次连续的数据.
//如果2个字符接收间隔超过10ms,则认为不是1次连续数据.也就是超过10ms没有接收到
//任何数据,则表示此次接收完毕.
//接收到的数据状态
//[15]:0,没有接收到数据;1,接收到了一批数据.
//[14:0]:接收到的数据长度
vu16 AS608_RX_STA = 0;

void AS608_USART_IRQHandler(void)
{
uint8_t res;
if(USART_GetITStatus(AS608_USART, USART_IT_RXNE) != RESET)//接收到数据
{
res = USART_ReceiveData(AS608_USART);
if((AS608_RX_STA&(1<<15))==0) //接收完的一批数据,还没有被处理,则不再接收其他数据
{
if(AS608_RX_STA<AS608_MAX_RECV_LEN) //还可以接收数据
{
TIM_SetCounter(COUNTER_TIM,0); //计数器清空 //计数器清空
if(AS608_RX_STA == 0) //使能定时器2的中断
{
TIM_Cmd(COUNTER_TIM,ENABLE);//使能定时器2
}
AS608_RX_BUF[AS608_RX_STA++]=res; //记录接收到的值
}else
{
AS608_RX_STA |= 1<<15; //强制标记接收完成
}
}
}
}


/* Configuring nested vectored interrupt controller NVIC */
static void USART_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;

/* Nested vector interrupt controller group selection */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

/* Preemptio Priority is 1 */
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
/* Sub Priority is 1 */
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
/* Enable interrupt */
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

/* Configure USART as the interrupt source */
NVIC_InitStructure.NVIC_IRQChannel = DEBUG_USART_IRQ;
/* Initialize configuration NVIC */
NVIC_Init(&NVIC_InitStructure);
/* Configure USART as the interrupt source */
NVIC_InitStructure.NVIC_IRQChannel = AS608_USART_IRQ;
/* Initialize configuration NVIC */
NVIC_Init(&NVIC_InitStructure);
}

void USART_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;

/* Enable port alternate function and enable USART GPIO clock */
RCC_APB2PeriphClockCmd(DEBUG_USART_AF|DEBUG_USART_GPIO_CLK,ENABLE);
RCC_APB2PeriphClockCmd(AS608_USART_AF|AS608_USART_GPIO_CLK,ENABLE);
/* Enable USART Clock */
RCC_APB1PeriphClockCmd(DEBUG_USART_CLK,ENABLE);
RCC_APB1PeriphClockCmd(AS608_USART_CLK,ENABLE);

/* Configure the Tx pin for alternate function */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Pin = DEBUG_USART_TX_PIN;
GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = AS608_USART_TX_PIN;
GPIO_Init(AS608_USART_RX_GPIO_PORT, &GPIO_InitStructure);

/* Configure the Rx pin for the alternate function */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_InitStructure.GPIO_Pin = DEBUG_USART_RX_PIN;
GPIO_Init(DEBUG_USART_RX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = AS608_USART_RX_PIN;
GPIO_Init(AS608_USART_RX_GPIO_PORT, &GPIO_InitStructure);

/* Configuration USART mode */
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
/* USART mode control: simultaneous enable send and receive */
USART_InitStructure.USART_Mode = USART_Mode_Tx|USART_Mode_Rx;

USART_InitStructure.USART_BaudRate = DEBUG_USART_BAUDRATE;
USART_Init(DEBUG_USART, &USART_InitStructure);
USART_InitStructure.USART_BaudRate = AS608_USART_BAUDRATE;
USART_Init(AS608_USART, &USART_InitStructure);

/* Enable serial port receive interrupt */
USART_ITConfig(AS608_USART, USART_IT_RXNE, ENABLE);

/* Enable serial */
USART_Cmd(DEBUG_USART, ENABLE);
USART_Cmd(AS608_USART, ENABLE);

USART_NVIC_Config();
}


/***************** Send a character **********************/
void Usart_SendByte( USART_TypeDef * pUSARTx, uint8_t ch)
{
/* Send a byte of data to the USART */
USART_SendData(pUSARTx,ch);

/* Waiting for the transmit data register to be empty */
while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);
}

/***************** Send string **********************/
void Usart_SendString( USART_TypeDef * pUSARTx, char *str)
{
unsigned int k=0;
do
{
Usart_SendByte( pUSARTx, *(str + k) );
k++;
}while(*(str + k)!='\0');

/* Waiting for transmission to complete */
while(USART_GetFlagStatus(pUSARTx,USART_FLAG_TC)==RESET);
}

/***************** Send a 16-digit number **********************/
void Usart_SendHalfWord( USART_TypeDef * pUSARTx, uint16_t ch)
{
uint8_t temp_h, temp_l;

/* Take out the high eight */
temp_h = (ch&0XFF00)>>8;
/* Take the lower eight */
temp_l = ch&0XFF;

/* Send high eight */
USART_SendData(pUSARTx,temp_h);
while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);

/* Send the lower eight digits */
USART_SendData(pUSARTx,temp_l);
while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);
}

/* Redirect the c library function printf to the serial port,
use the printf function after redirection. */
int fputc(int ch, FILE *f)
{
/* Send a byte of data to the serial port */
USART_SendData(DEBUG_USART, (uint8_t) ch);

/* Waiting to send */
while (USART_GetFlagStatus(DEBUG_USART, USART_FLAG_TXE) == RESET);

return (ch);
}

/* Redirect the c library function scanf to the serial port,
rewrite backwards can use scanf, getchar and other functions. */
int fgetc(FILE *f)
{
uint8_t ch;
/* Waiting for serial input data */
while (USART_GetFlagStatus(DEBUG_USART, USART_FLAG_RXNE) == RESET);

ch = USART_ReceiveData(DEBUG_USART);
USART_SendData(DEBUG_USART, (uint8_t)ch); // 串口回显

return (int)ch;
}
/*********************************************END OF FILE*********************************************/

2,定时器

STM32C8T6没有定时器4,改用定时器2,10ms定时。

(1)time.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef __TIME_H
#define __TIME_H

#include "stm32f10x.h"
#include "usart.h"

#define COUNTER_TIM TIM2
#define COUNTER_TIM_CLK RCC_APB1Periph_TIM2

#define COUNTER_TIM_IRQn TIM2_IRQn
#define COUNTER_TIM_IRQHandler TIM2_IRQHandler

void COUNTER_TIM_Init(uint16_t arr,uint16_t psc);

#endif /* __TIME_H */

(2)time.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
/**
******************************************************************************
* @file time.c
* @author Soso
* @date 2019-12-17
* @brief General timer driver code.
*
******************************************************************************
*/

#include "time.h"

extern vu16 AS608_RX_STA;

//定时器4中断服务程序
void COUNTER_TIM_IRQHandler(void)
{
if (TIM_GetITStatus(COUNTER_TIM, TIM_IT_Update) != RESET)//是更新中断
{
AS608_RX_STA|=1<<15; //标记接收完成
TIM_ClearITPendingBit(COUNTER_TIM, TIM_IT_Update); //清除TIM2更新中断标志
TIM_Cmd(COUNTER_TIM, DISABLE); //关闭TIM2
}
}

// Configuring nested vectored interrupt controller(NVIC)
static void TIMx_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure NVIC as a priority group 1 */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

/* Configure interrupt source*/
NVIC_InitStructure.NVIC_IRQChannel = COUNTER_TIM_IRQn;
/* Configuration preemption priority: 1 */
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
/* Configure sub-priority: 1 */
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
/* Enable interrupt channel */
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}


void COUNTER_TIM_Init(uint16_t arr,uint16_t psc)
{
SystemInit();
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// Enable TIM2_CLK
RCC_APB1PeriphClockCmd(COUNTER_TIM_CLK,ENABLE);

/* eg:arr=1000,psc=720
1, PSC(prescaler) = 720-1
timer frequency = 72M/(PSC + 1) = 100KHZ
calculate the time of one pulse = 1/100,000 s
2, ARR (automatic reload register) = 1000-1, counted from 0 to 999, then counted 1000 times.
3, Time = 1000/100,000 = 0.01s = 10ms */
TIM_TimeBaseStructure.TIM_Period = arr-1;
TIM_TimeBaseStructure.TIM_Prescaler = psc-1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(COUNTER_TIM,&TIM_TimeBaseStructure);

// Clear timer update interrupt flag
TIM_ClearITPendingBit(COUNTER_TIM,TIM_IT_Update);
// Enable timer update interrupt
TIM_ITConfig(COUNTER_TIM,TIM_IT_Update,ENABLE);
// Initialization disable timer
TIM_Cmd(COUNTER_TIM,DISABLE);

TIMx_NVIC_Config();
}


/*********************************************END OF FILE*********************************************/

3,AS608模块驱动代码

这里主要修改STM32F103C8T6所对应的引脚、串口发送函数的定义,下面是完整代码。

(1)as608.h
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
#ifndef __AS608_H
#define __AS608_H

#include "stm32f10x.h"
#include "usart.h"
#include "string.h"
#include "systick.h"

//Pin definition
/*************************************************************************/
#define AS608_GPIO_PORT GPIOA
#define AS608_GPIO_CLK RCC_APB2Periph_GPIOA
#define AS608_TOUCH_PIN GPIO_Pin_1

/*************************************************************************/

#define PS_Sta GPIO_ReadInputDataBit(AS608_GPIO_PORT,AS608_TOUCH_PIN) //读指纹模块状态引脚
#define CharBuffer1 0x01
#define CharBuffer2 0x02

extern u32 AS608Addr; //模块地址

typedef struct
{
u16 pageID; //指纹ID
u16 mathscore; //匹配得分
}SearchResult;

typedef struct
{
u16 PS_max; //指纹最大容量
u8 PS_level; //安全等级
u32 PS_addr;
u8 PS_size; //通讯数据包大小
u8 PS_N; //波特率基数N
}SysPara;

void PS_StaGPIO_Init(void); //初始化PA6读状态引脚

u8 PS_GetImage(void); //录入图像
u8 PS_GenChar(u8 BufferID); //生成特征
u8 PS_Match(void); //精确比对两枚指纹特征
u8 PS_Search(u8 BufferID,u16 StartPage,u16 PageNum,SearchResult *p);//搜索指纹
u8 PS_RegModel(void); //合并特征(生成模板)
u8 PS_StoreChar(u8 BufferID,u16 PageID); //储存模板
u8 PS_DeletChar(u16 PageID,u16 N); //删除模板
u8 PS_Empty(void); //清空指纹库
u8 PS_WriteReg(u8 RegNum,u8 DATA); //写系统寄存器
u8 PS_ReadSysPara(SysPara *p); //读系统基本参数
u8 PS_SetAddr(u32 addr); //设置模块地址
u8 PS_WriteNotepad(u8 NotePageNum,u8 *content); //写记事本
u8 PS_ReadNotepad(u8 NotePageNum,u8 *note); //读记事
u8 PS_HighSpeedSearch(u8 BufferID,u16 StartPage,u16 PageNum,SearchResult *p);//高速搜索
u8 PS_ValidTempleteNum(u16 *ValidN); //读有效模板个数
u8 PS_HandShake(u32 *PS_Addr); //与AS608模块握手
const char *EnsureMessage(u8 ensure); //确认码错误信息解析
#endif /* __AS608_H */

(2)as608.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
/**
******************************************************************************
* @file as608.c
* @author Soso
* @date 2019-12-17
* @brief AS608 fingerprint recognition module driver code.
******************************************************************************
*/
#include "as608.h"

u32 AS608Addr = 0XFFFFFFFF; //默认

//初始化PA8为下拉输入
//读摸出感应状态(触摸感应时输出高电平信号)
void PS_StaGPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(AS608_GPIO_CLK, ENABLE);//使能GPIOA时钟
//初始化读状态引脚GPIOA
GPIO_InitStructure.GPIO_Pin = AS608_TOUCH_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//输入下拉模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//50MHz
GPIO_Init(AS608_GPIO_PORT, &GPIO_InitStructure);//初始化GPIO
}

//发送包头
static void SendHead(void)
{
Usart_SendByte(AS608_USART,0xEF);
Usart_SendByte(AS608_USART,0x01);
}
//发送地址
static void SendAddr(void)
{
Usart_SendByte(AS608_USART,AS608Addr>>24);
Usart_SendByte(AS608_USART,AS608Addr>>16);
Usart_SendByte(AS608_USART,AS608Addr>>8);
Usart_SendByte(AS608_USART,AS608Addr);
}
//发送包标识,
static void SendFlag(u8 flag)
{
Usart_SendByte(AS608_USART,flag);
}
//发送包长度
static void SendLength(int length)
{
Usart_SendByte(AS608_USART,length>>8);
Usart_SendByte(AS608_USART,length);
}
//发送指令码
static void Sendcmd(u8 cmd)
{
Usart_SendByte(AS608_USART,cmd);
}
//发送校验和
static void SendCheck(u16 check)
{
Usart_SendByte(AS608_USART,check>>8);
Usart_SendByte(AS608_USART,check);
}
//判断中断接收的数组有没有应答包
//waittime为等待中断接收数据的时间(单位1ms)
//返回值:数据包首地址
static u8 *JudgeStr(u16 waittime)
{
char *data;
u8 str[8];
str[0]=0xef;
str[1]=0x01;
str[2]=AS608Addr>>24;
str[3]=AS608Addr>>16;
str[4]=AS608Addr>>8;
str[5]=AS608Addr;
str[6]=0x07;
str[7]='\0';
AS608_RX_STA=0;
while(--waittime)
{
delay_ms(1);
if(AS608_RX_STA&0X8000)//接收到一次数据
{
AS608_RX_STA=0;
data=strstr((const char*)AS608_RX_BUF,(const char*)str);
if(data)
return (u8*)data;
}
}
return 0;
}

//录入图像 PS_GetImage
//功能:探测手指,探测到后录入指纹图像存于ImageBuffer。
//模块返回确认字
u8 PS_GetImage(void)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x03);
Sendcmd(0x01);
temp = 0x01+0x03+0x01;
SendCheck(temp);
data = JudgeStr(2000);
if(data)
ensure = data[9];
else
ensure = 0xff;
return ensure;
}

//生成特征 PS_GenChar
//功能:将ImageBuffer中的原始图像生成指纹特征文件存于CharBuffer1或CharBuffer2
//参数:BufferID --> charBuffer1:0x01 charBuffer1:0x02
//模块返回确认字
u8 PS_GenChar(u8 BufferID)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x04);
Sendcmd(0x02);
Usart_SendByte(AS608_USART,BufferID);
temp = 0x01+0x04+0x02+BufferID;
SendCheck(temp);
data = JudgeStr(2000);
if(data)
ensure = data[9];
else
ensure = 0xff;
return ensure;
}

//精确比对两枚指纹特征 PS_Match
//功能:精确比对CharBuffer1 与CharBuffer2 中的特征文件
//模块返回确认字
u8 PS_Match(void)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x03);
Sendcmd(0x03);
temp = 0x01+0x03+0x03;
SendCheck(temp);
data = JudgeStr(2000);
if(data)
ensure = data[9];
else
ensure = 0xff;
return ensure;
}

//搜索指纹 PS_Search
//功能:以CharBuffer1或CharBuffer2中的特征文件搜索整个或部分指纹库.若搜索到,则返回页码。
//参数: BufferID @ref CharBuffer1 CharBuffer2
//说明: 模块返回确认字,页码(相配指纹模板)
u8 PS_Search(u8 BufferID,u16 StartPage,u16 PageNum,SearchResult *p)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x08);
Sendcmd(0x04);
Usart_SendByte(AS608_USART,BufferID);
Usart_SendByte(AS608_USART,StartPage>>8);
Usart_SendByte(AS608_USART,StartPage);
Usart_SendByte(AS608_USART,PageNum>>8);
Usart_SendByte(AS608_USART,PageNum);
temp = 0x01+0x08+0x04+BufferID+(StartPage>>8)+(u8)StartPage+(PageNum>>8)+(u8)PageNum;
SendCheck(temp);
data = JudgeStr(2000);
if(data)
{
ensure = data[9];
p->pageID = (data[10]<<8)+data[11];
p->mathscore = (data[12]<<8)+data[13];
}
else
ensure = 0xff;
return ensure;
}

//合并特征(生成模板)PS_RegModel
//功能:将CharBuffer1与CharBuffer2中的特征文件合并生成 模板,结果存于CharBuffer1与CharBuffer2
//说明: 模块返回确认字
u8 PS_RegModel(void)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x03);
Sendcmd(0x05);
temp = 0x01+0x03+0x05;
SendCheck(temp);
data = JudgeStr(2000);
if(data)
ensure = data[9];
else
ensure = 0xff;
return ensure;
}

//储存模板 PS_StoreChar
//功能:将 CharBuffer1 或 CharBuffer2 中的模板文件存到 PageID 号flash数据库位置。
//参数: BufferID @ref charBuffer1:0x01 charBuffer1:0x02
// PageID(指纹库位置号)
//说明: 模块返回确认字
u8 PS_StoreChar(u8 BufferID,u16 PageID)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x06);
Sendcmd(0x06);
Usart_SendByte(AS608_USART,BufferID);
Usart_SendByte(AS608_USART,PageID>>8);
Usart_SendByte(AS608_USART,PageID);
temp = 0x01+0x06+0x06+BufferID+(PageID>>8)+(u8)PageID;
SendCheck(temp);
data = JudgeStr(2000);
if(data)
ensure = data[9];
else
ensure = 0xff;
return ensure;
}

//删除模板 PS_DeletChar
//功能: 删除flash数据库中指定ID号开始的N个指纹模板
//参数: PageID(指纹库模板号),N删除的模板个数。
//说明: 模块返回确认字
u8 PS_DeletChar(u16 PageID,u16 N)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x07);
Sendcmd(0x0C);
Usart_SendByte(AS608_USART,PageID>>8);
Usart_SendByte(AS608_USART,PageID);
Usart_SendByte(AS608_USART,N>>8);
Usart_SendByte(AS608_USART,N);
temp = 0x01+0x07+0x0C+(PageID>>8)+(u8)PageID+(N>>8)+(u8)N;
SendCheck(temp);
data = JudgeStr(2000);
if(data)
ensure = data[9];
else
ensure = 0xff;
return ensure;
}

//清空指纹库 PS_Empty
//功能: 删除flash数据库中所有指纹模板
//参数: 无
//说明: 模块返回确认字
u8 PS_Empty(void)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x03);
Sendcmd(0x0D);
temp = 0x01+0x03+0x0D;
SendCheck(temp);
data = JudgeStr(2000);
if(data)
ensure = data[9];
else
ensure = 0xff;
return ensure;
}
//写系统寄存器 PS_WriteReg
//功能: 写模块寄存器
//参数: 寄存器序号RegNum:4\5\6
//说明: 模块返回确认字
u8 PS_WriteReg(u8 RegNum,u8 DATA)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x05);
Sendcmd(0x0E);
Usart_SendByte(AS608_USART,RegNum);
Usart_SendByte(AS608_USART,DATA);
temp = RegNum+DATA+0x01+0x05+0x0E;
SendCheck(temp);
data = JudgeStr(2000);
if(data)
ensure = data[9];
else
ensure = 0xff;
// if(ensure==0)
// printf("\r\n设置参数成功!");
// else
// printf("\r\n%s",EnsureMessage(ensure));
return ensure;
}

//读系统基本参数 PS_ReadSysPara
//功能: 读取模块的基本参数(波特率,包大小等)
//参数: 无
//说明: 模块返回确认字 + 基本参数(16bytes)
u8 PS_ReadSysPara(SysPara *p)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x03);
Sendcmd(0x0F);
temp = 0x01+0x03+0x0F;
SendCheck(temp);
data = JudgeStr(1000);
if(data)
{
ensure = data[9];
p->PS_max = (data[14]<<8)+data[15];
p->PS_level = data[17];
p->PS_addr = (data[18]<<24)+(data[19]<<16)+(data[20]<<8)+data[21];
p->PS_size = data[23];
p->PS_N = data[25];
}
else
ensure=0xff;
// if(ensure==0x00)
// {
// printf("\r\n模块最大指纹容量=%d",p->PS_max);
// printf("\r\n对比等级=%d",p->PS_level);
// printf("\r\n地址=%x",p->PS_addr);
// printf("\r\n波特率=%d",p->PS_N*9600);
// }
// else
// printf("\r\n%s",EnsureMessage(ensure));
return ensure;
}

//设置模块地址 PS_SetAddr
//功能: 设置模块地址
//参数: PS_addr
//说明: 模块返回确认字
u8 PS_SetAddr(u32 PS_addr)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x07);
Sendcmd(0x15);
Usart_SendByte(AS608_USART,PS_addr>>24);
Usart_SendByte(AS608_USART,PS_addr>>16);
Usart_SendByte(AS608_USART,PS_addr>>8);
Usart_SendByte(AS608_USART,PS_addr);
temp = 0x01+0x07+0x15+(u8)(PS_addr>>24)+(u8)(PS_addr>>16)+(u8)(PS_addr>>8) +(u8)PS_addr;
SendCheck(temp);
AS608Addr = PS_addr;//发送完指令,更换地址
data = JudgeStr(2000);
if(data)
ensure = data[9];
else
ensure = 0xff;
// if(ensure==0x00)
// printf("\r\n设置地址成功!");
// else
// printf("\r\n%s",EnsureMessage(ensure));
return ensure;
}

//功能: 模块内部为用户开辟了256bytes的FLASH空间用于存用户记事本,
// 该记事本逻辑上被分成 16 个页。
//参数: NotePageNum(0~15),Byte32(要写入内容,32个字节)
//说明: 模块返回确认字
u8 PS_WriteNotepad(u8 NotePageNum,u8 *Byte32)
{
u16 temp;
u8 ensure,i;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(36);
Sendcmd(0x18);
Usart_SendByte(AS608_USART,NotePageNum);
for(i=0;i<32;i++)
{
Usart_SendByte(AS608_USART,Byte32[i]);
temp += Byte32[i];
}
temp = 0x01+36+0x18+NotePageNum+temp;
SendCheck(temp);
data = JudgeStr(2000);
if(data)
ensure = data[9];
else
ensure = 0xff;
return ensure;
}

//读记事PS_ReadNotepad
//功能: 读取FLASH用户区的128bytes数据
//参数: NotePageNum(0~15)
//说明: 模块返回确认字+用户信息
u8 PS_ReadNotepad(u8 NotePageNum,u8 *Byte32)
{
u16 temp;
u8 ensure,i;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x04);
Sendcmd(0x19);
Usart_SendByte(AS608_USART,NotePageNum);
temp = 0x01+0x04+0x19+NotePageNum;
SendCheck(temp);
data = JudgeStr(2000);
if(data)
{
ensure = data[9];
for(i=0;i<32;i++)
{
Byte32[i] = data[10+i];
}
}
else
ensure = 0xff;
return ensure;
}

//高速搜索PS_HighSpeedSearch
//功能:以 CharBuffer1或CharBuffer2中的特征文件高速搜索整个或部分指纹库。
// 若搜索到,则返回页码,该指令对于的确存在于指纹库中 ,且登录时质量
// 很好的指纹,会很快给出搜索结果。
//参数: BufferID, StartPage(起始页),PageNum(页数)
//说明: 模块返回确认字+页码(相配指纹模板)
u8 PS_HighSpeedSearch(u8 BufferID,u16 StartPage,u16 PageNum,SearchResult *p)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01);//命令包标识
SendLength(0x08);
Sendcmd(0x1b);
Usart_SendByte(AS608_USART,BufferID);
Usart_SendByte(AS608_USART,StartPage>>8);
Usart_SendByte(AS608_USART,StartPage);
Usart_SendByte(AS608_USART,PageNum>>8);
Usart_SendByte(AS608_USART,PageNum);
temp = 0x01+0x08+0x1b+BufferID+(StartPage>>8)+(u8)StartPage+(PageNum>>8)+(u8)PageNum;
SendCheck(temp);
data = JudgeStr(2000);
if(data)
{
ensure = data[9];
p->pageID = (data[10]<<8) +data[11];
p->mathscore = (data[12]<<8) +data[13];
}
else
ensure=0xff;
return ensure;
}

//读有效模板个数 PS_ValidTempleteNum
//功能:读有效模板个数
//参数: 无
//说明: 模块返回确认字+有效模板个数ValidN
u8 PS_ValidTempleteNum(u16 *ValidN)
{
u16 temp;
u8 ensure;
u8 *data;
SendHead();
SendAddr();
SendFlag(0x01); //命令包标识
SendLength(0x03);
Sendcmd(0x1d);
temp = 0x01+0x03+0x1d;
SendCheck(temp);
data=JudgeStr(2000);
if(data)
{
ensure=data[9];
*ValidN = (data[10]<<8) +data[11];
}
else
ensure=0xff;

// if(ensure==0x00)
// {
// printf("\r\n有效指纹个数=%d",(data[10]<<8)+data[11]);
// }
// else
// printf("\r\n%s",EnsureMessage(ensure));
return ensure;
}

//与AS608握手 PS_HandShake
//参数: PS_Addr地址指针
//说明: 模块返新地址(正确地址)
u8 PS_HandShake(u32 *PS_Addr)
{
SendHead();
SendAddr();
Usart_SendByte(AS608_USART,0X01);
Usart_SendByte(AS608_USART,0X00);
Usart_SendByte(AS608_USART,0X00);
delay_ms(200);
if(AS608_RX_STA&0X8000)//接收到数据
{
//判断是不是模块返回的应答包
if( AS608_RX_BUF[0]==0XEF&&AS608_RX_BUF[1]==0X01&&AS608_RX_BUF[6]==0X07)
{
*PS_Addr=(AS608_RX_BUF[2]<<24) + (AS608_RX_BUF[3]<<16)
+(AS608_RX_BUF[4]<<8) + (AS608_RX_BUF[5]);
AS608_RX_STA = 0;
return 0;
}
AS608_RX_STA=0;
}
return 1;
}

//模块应答包确认码信息解析
//功能:解析确认码错误信息返回信息
//参数: ensure
const char *EnsureMessage(u8 ensure)
{
const char *p;
switch(ensure)
{
case 0x00:
p="OK";break;
case 0x01:
p="数据包接收错误";break;
case 0x02:
p="传感器上没有手指";break;
case 0x03:
p="录入指纹图像失败";break;
case 0x04:
p="指纹图像太干、太淡而生不成特征";break;
case 0x05:
p="指纹图像太湿、太糊而生不成特征";break;
case 0x06:
p="指纹图像太乱而生不成特征";break;
case 0x07:
p="指纹图像正常,但特征点太少(或面积太小)而生不成特征";break;
case 0x08:
p="指纹不匹配";break;
case 0x09:
p="没搜索到指纹";break;
case 0x0a:
p="特征合并失败";break;
case 0x0b:
p="访问指纹库时地址序号超出指纹库范围";
case 0x10:
p="删除模板失败";break;
case 0x11:
p="清空指纹库失败";break;
case 0x15:
p="缓冲区内没有有效原始图而生不成图像";break;
case 0x18:
p="读写 FLASH 出错";break;
case 0x19:
p="未定义错误";break;
case 0x1a:
p="无效寄存器号";break;
case 0x1b:
p="寄存器设定内容错误";break;
case 0x1c:
p="记事本页码指定错误";break;
case 0x1f:
p="指纹库满";break;
case 0x20:
p="地址错误";break;
default :
p="模块返回确认码有误";break;
}
return p;
}

4,延时函数配置模块

(1)systick.h
1
2
3
4
5
6
7
8
9
10
11
#ifndef __SYSTICK_H
#define __SYSTICK_H

#include"stm32f10x.h"

void delay_us(u32 i);
void delay_ms(u32 i);


#endif /* __SYSTICK_DELAY_H */

(2)systick.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
#include "systick.h"

void delay_us(u32 i)
{
u32 temp;
SysTick->LOAD=9*i; //Set the reload value, at 72MHZ
SysTick->CTRL=0X01; //Enable, reduce to zero is no action, use external clock source
SysTick->VAL=0; //Clear counter
do
{
temp=SysTick->CTRL; //Read current countdown value
}
while((temp&0x01)&&(!(temp&(1<<16)))); //Waiting time to arrive
SysTick->CTRL=0; //Close counter
SysTick->VAL=0; //Empty counter
}
void delay_ms(u32 i)
{
u32 temp;
SysTick->LOAD=9000*i; //Set the reload value, at 72MHZ
SysTick->CTRL=0X01; //Enable, reduce to zero is no action, use external clock source
SysTick->VAL=0; //Clear counter
do
{
temp=SysTick->CTRL; //Read current countdown value
}
while((temp&0x01)&&(!(temp&(1<<16)))); //Waiting time to arrive
SysTick->CTRL=0; //Close counter
SysTick->VAL=0; //Empty counter
}

5,主函数main.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
/**
******************************************************************************
* @file main.c
* @author Soso
* @date 2019-12-17
* @brief STM32f103 fingerprint identification system,
* serial port display interface information.
******************************************************************************
*/

#include "stm32f10x.h"
#include "time.h"
#include "as608.h"
#include "usart.h"
#include "systick.h"

SysPara AS608Para; //指纹模块AS608参数
uint16_t ValidN = 0; //模块内有效模板个数
int InputNum = -1;

void ShowErrMessage(uint8_t ensure);
void ShowMenu(void); // Main display menu
void Show_DelFR_Menu(void); // Delete display menu
void Add_FR(void); // Add figerprint
void Press_FR(void); // Press fingerprint
void Del_FR(void); // Delete fingerprint

int main(void)
{
uint8_t ensure;

COUNTER_TIM_Init(1000,720); // 10ms
USART_Config();
PS_StaGPIO_Init(); //初始化读FR状态引脚

printf("\r\n----------------------------------------------------\r\n\r\n");
printf("AS608 Fingerprint module test.\r\n");
printf(" Author: @Soso\r\n");
printf("Connect with AS608....\r\n");
while(PS_HandShake(&AS608Addr)) //与AS608模块握手
{
printf("Cannot connect with AS608!\r\n");
delay_ms(1000);
printf("Try to connect again....\r\n");
delay_ms(1000);
}
printf("Connect success!\r\n"); //通讯成功
printf("Baudrate:%d Addr:0x%x\r\n",AS608_USART_BAUDRATE,AS608Addr); //显示波特率
delay_ms(100);
ensure=PS_ValidTempleteNum(&ValidN);//读库指纹个数
if(ensure!=0x00)
ShowErrMessage(ensure); //显示确认码错误信息
ensure=PS_ReadSysPara(&AS608Para); //读AS608模块参数
if(ensure==0x00)
printf("RemainNum:%d Level:%d\r\n",AS608Para.PS_max-ValidN,AS608Para.PS_level); //显示剩余指纹数量和安全等级
else
ShowErrMessage(ensure);

ShowMenu();


while(1)
{
if(InputNum == 1) //录指纹
{
Add_FR();
ShowMenu();
}
else if(InputNum == 2)
{
Del_FR();
ShowMenu();
}
else if(InputNum == 3)
{
Press_FR(); //刷指纹
ShowMenu();
}

}
}


//显示确认码错误信息
void ShowErrMessage(uint8_t ensure)
{
printf("%s\r\n",EnsureMessage(ensure));
}
// 显示主目录界面
void ShowMenu(void)
{
printf("\r\n----------------------------------------------------\r\n\r\n");
printf("Welcome to AS608 fingerprint module.\r\n");
printf("1. Add fingerprint.\r\n");
printf("2. Delete fingerprint.\r\n");
printf("3. Identification fingerprint.\r\n");
printf("Please select an option: ");
scanf("%d",&InputNum);
}
// 显示删除指纹界面
void Show_DelFR_Menu(void)
{
printf("\r\n----------------------------------------------------\r\n\r\n");
printf(" Delete fingerprint\r\n");
printf("Input 555 clear the fingerprint library.\r\n");
printf("Input 666 back to main menu.\r\n");
printf("Input ID and press Enter(0=< ID <=299): "); //显示输入ID并按下“Enter”
}

//录指纹
void Add_FR(void)
{
uint8_t i=0,ensure,processnum=0;
int ID;

printf("\r\n----------------------------------------------------\r\n\r\n");
while(1)
{
switch(processnum)
{
case 0:
i++;
printf("Pleas touch finger!\r\n"); //请按手指
while(!PS_Sta); //等待手指按下
ensure=PS_GetImage();
if(ensure==0x00)
{
ensure=PS_GenChar(CharBuffer1);//生成特征
if(ensure==0x00)
{
printf("Fingerprint correct.\r\n");//指纹正确
i=0;
processnum=1;//跳到第二步
}else ShowErrMessage(ensure);
}else ShowErrMessage(ensure);
break;

case 1:
i++;
printf("Pleas touch finger again!\r\n");//再按一次手指
while(GPIO_ReadInputDataBit(AS608_GPIO_PORT,AS608_TOUCH_PIN) == 0);//等待手指按下
ensure=PS_GetImage();
if(ensure==0x00)
{
ensure=PS_GenChar(CharBuffer2);//生成特征
if(ensure==0x00)
{
printf("Fingerprint correct\r\n");//指纹正确
i=0;
processnum=2;//跳到第三步
}else ShowErrMessage(ensure);
}else ShowErrMessage(ensure);
break;

case 2:
printf("Compare twice fingerprint\r\n");//对比两次指纹
ensure=PS_Match();
if(ensure==0x00)
{
printf("Twice fingerprint are same.\r\n");//两次指纹是一样的
processnum=3;//跳到第四步
}
else
{
printf("Compare fail,pleas touch again!\r\n");//对比失败,请重新按手指
ShowErrMessage(ensure);
i=0;
processnum=0;//跳回第一步
}
break;

case 3:
printf("Generate fingerprint template.\r\n");//产生一个指纹模板
ensure=PS_RegModel();
if(ensure==0x00)
{
printf("Generate fingerprint success.\r\n");//生成指纹模板成功
processnum=4;//跳到第五步
}
else
{
processnum=0;
ShowErrMessage(ensure);
}
break;

case 4:
do
{
printf("Intput ID and save with ENTER(0=< ID <=299): ");//输入ID并按“Enter”保存
scanf("%d",&ID);
}while(!(ID<300));//输入DI必须小于300
ensure=PS_StoreChar(CharBuffer2,ID);//储存模板
if(ensure==0x00)
{
printf("\r\nAdd fingerprint success!!!\r\n");//添加指纹成功
PS_ValidTempleteNum(&ValidN);//读库指纹个数
printf("Number of remaining fingerprints: %d\r\n",AS608Para.PS_max-ValidN);//显示剩余指纹个数
return ;
}
else
{
processnum=0;
ShowErrMessage(ensure);
}
break;
}
if(i==5) //超过5次没有按手指则退出
{
printf("Warning: No finger press.\r\n");
break;
}
}
}

//刷指纹
void Press_FR(void)
{
SearchResult seach;
uint8_t ensure;

printf("\r\n----------------------------------------------------\r\n\r\n");
printf("Please press your finger.\r\n");
while(!PS_Sta);//等待手指按下
ensure=PS_GetImage();
if(ensure==0x00)//获取图像成功
{
ensure=PS_GenChar(CharBuffer1);
if(ensure==0x00) //生成特征成功
{
ensure=PS_HighSpeedSearch(CharBuffer1,0,300,&seach);
if(ensure==0x00)//搜索成功
{
printf("Search fingerprint success.\r\n");//搜索指纹成功
printf("Match ID:%d Match score:%d\r\n",seach.pageID,seach.mathscore);//显示匹配指纹的ID和分数
}
else
ShowErrMessage(ensure);
}
else
ShowErrMessage(ensure);
}
}

//删除指纹
void Del_FR(void)
{
uint8_t ensure;
int num;

Show_DelFR_Menu(); // 显示删除指纹界面
scanf("%d",&num); //获取返回的数值

if(num==555)
goto MENU ; //返回主页面
else if(num==666)
ensure=PS_Empty();//清空指纹库
else if(num>=0 && num < 300)
ensure=PS_DeletChar(num,1);//删除单个指纹
if(ensure==0)
{
printf("\r\nDelete fingerprint success!!!\r\n");//删除指纹成功
}
else
ShowErrMessage(ensure);
PS_ValidTempleteNum(&ValidN);//读库指纹个数
printf("Number of remaining fingerprints: %d\r\n",AS608Para.PS_max-ValidN);//显示剩余指纹个数

MENU:
InputNum = 0;
ShowMenu();
}

/*********************************************END OF FILE*********************************************/

三、硬件接线说明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
【 !】 引脚分配

STM32 串口模块
PB11(Rx) -> Tx
PB10(Tx) -> Rx
+3.3V -> +3.3V
GND -> GND
波特率:115200

STM32 ATK-AS608
+3.3V -> Vi
PA3(Rx) -> Tx
PA2(Tx) -> Rx
GND -> GND
PA1 -> WAK
+3.3V -> Vt
波特率:115200

四、最终效果

Q73TzQ.jpg


STM32F103学习笔记——AS608指纹识别模块的使用
https://kevinloongc.github.io/posts/5803b452.html
作者
Kevin Loongc
发布于
2019年12月17日
许可协议