RC522 SPI驱动 mini2440

来源:互联网 发布:科普是什么意思网络词 编辑:程序博客网 时间:2024/05/22 12:57

参考http://blog.csdn.net/fulinus/article/details/40898677
一、下面是简单的编程步骤:
The MFRC522 has the capability to perform a digital self test. The self test is started by
using the following procedure:
1. Perform a soft reset.
2. Clear the internal buffer by writing 25 bytes of 00h and implement the Config
command.
3. Enable the self test by writing 09h to the AutoTestReg register.
4. Write 00h to the FIFO buffer.
5. Start the self test with the CalcCRC command.
6. The self test is initiated.
7. When the self test has completed, the FIFO buffer contains the following 64 bytes:

FIFO buffer byte values for MFRC522 version 1.0:
00h, C6h, 37h, D5h, 32h, B7h, 57h, 5Ch,
C2h, D8h, 7Ch, 4Dh, D9h, 70h, C7h, 73h,
10h, E6h, D2h, AAh, 5Eh, A1h, 3Eh, 5Ah,
14h, AFh, 30h, 61h, C9h, 70h, DBh, 2Eh,
64h, 22h, 72h, B5h, BDh, 65h, F4h, ECh,
22h, BCh, D3h, 72h, 35h, CDh, AAh, 41h,
1Fh, A7h, F3h, 53h, 14h, DEh, 7Eh, 02h,
D9h, 0Fh, B5h, 5Eh, 25h, 1Dh, 29h, 79h
FIFO buffer byte values for MFRC522 version 2.0:
00h, EBh, 66h, BAh, 57h, BFh, 23h, 95h,
D0h, E3h, 0Dh, 3Dh, 27h, 89h, 5Ch, DEh,
9Dh, 3Bh, A7h, 00h, 21h, 5Bh, 89h, 82h,
51h, 3Ah, EBh, 02h, 0Ch, A5h, 00h, 49h,
7Ch, 84h, 4Dh, B3h, CCh, D2h, 1Bh, 81h,
5Dh, 48h, 76h, D5h, 71h, 061h, 21h, A9h,
86h, 96h, 83h, 38h, CFh, 9Dh, 5Bh, 6Dh,
DCh, 15h, BAh, 3Eh, 7Dh, 95h, 03Bh, 2Fh

关于RFID程序:
环境:mini2440
首先可以参考网上的教程在mini2440上,让其支持SPI

引脚相关,下面驱动程序里边的其中0代表接低电平,1代表接高电平
对于SPI驱动:
Spi_device板信息用spi_board_info结构体来描述,它描述了SPI外设(RC522模块)使用的主机控制器序号,片选信号,数据比特率,传输方式等。故要先填充struct spi_board_info这个结构体。

1.修改arch/arm/mach-s3c2440/mach-mini2440.c文件

#include <linux/spi/spi.h>#include <../mach-s3c2410/include/mach/spi.h>static struct spi_board_info s3c2410_spi0_board[] ={        [0] = {                .modalias = "spidev",                .bus_num = 0,                .chip_select = 0,                .irq = IRQ_EINT9,                .max_speed_hz = 500 * 1000,                }};static struct s3c2410_spi_info s3c2410_spi0_platdata = {        .pin_cs = S3C2410_GPG(2),        .num_cs = 1,        .bus_num = 0,        .gpio_setup = s3c24xx_spi_gpiocfg_bus0_gpe11_12_13,};static struct spi_board_info s3c2410_spi1_board[] ={        [0] = {                .modalias = "spidev",                .bus_num = 1,                .chip_select = 0,                .irq = IRQ_EINT2,                .max_speed_hz = 500 * 1000,                }};static struct s3c2410_spi_info s3c2410_spi1_platdata = {        .pin_cs = S3C2410_GPG(3),        .num_cs = 1,        .bus_num = 1,        .gpio_setup = s3c24xx_spi_gpiocfg_bus1_gpg5_6_7,};

2.在mini2440_devices[]平台数组中添加如下代码:

&s3c_device_spi0,&s3c_device_spi1,

3.最后在mini2440_machine_init函数中加入如下代码:

s3c_device_spi0.dev.platform_data= &s3c2410_spi0_platdata;spi_register_board_info(s3c2410_spi0_board, ARRAY_SIZE(s3c2410_spi0_board));s3c_device_spi1.dev.platform_data= &s3c2410_spi1_platdata;spi_register_board_info(s3c2410_spi1_board, ARRAY_SIZE(s3c2410_spi1_board));

4.最后需要修改arch/arm/plat-s3c24xx/KConfig文件
找到如下代码做更改:

config S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13        bool         help          SPI GPIO configuration code for BUS0 when connected to          GPE11, GPE12 and GPE13.config S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7        bool         help          SPI GPIO configuration code for BUS 1 when connected to          GPG5, GPG6 and GPG7.

更改为:

config S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13        bool "S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13"        help          SPI GPIO configuration code for BUS0 when connected to          GPE11, GPE12 and GPE13.config S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7        bool "S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7"        help          SPI GPIO configuration code for BUS 1 when connected to          GPG5, GPG6 and GPG7.

5.最后在生成zImage之前,配置内核选上上面做的更改。
A.make menuconfig
B.>System Type

选上S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13
C.>Device Drivers
选上SPI support
在SPI support 里边除TLE62X0,其他都选上

6.make zImage

7.在Documentation/spi下,修改spidev_test.c文件,将device name改为/dev/spidev1.0
然后交叉编译
arm-linux-gcc -I ~/linux-2.6.32.2/include/ spidev_test.c

启动内核,查看dev目录下是否有spidev1.0
否者需要编译内核下drivers/spi/spidev.c生成spidev.ko文件
短接SPI MOSI和SPI MISO
加载驱动程序,并执行测试程序。

出现一下表示成功:

FF FF FF FF FF FF40 00 00 00 00 95FF FF FF FF FF FFFF FF FF FF FF FFFF FF FF FF FF FFDE AD BE EF BA ADF0 0D

到这里,RC522的工作已完大半,已经加载了驱动程序spidev.ko,我们已经加载了驱动程序到2440里边,然后这个驱动程序提供了open read write这些函数,我们现在就可以按照上门的编程顺序完成RFID的测试程序:已上传
http://download.csdn.net/detail/wang__rongwei/9440094

这个驱动程序纸只代表一种实现方法,他把一些硬件初始化都放在应用程序里边,当然我们也可以在驱动程序里边添加ioctl来实现这些,然后应用程序只是简单的读出卡号

0 0
原创粉丝点击