首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >射频识别RC522读卡器wiringPi

射频识别RC522读卡器wiringPi
EN

Stack Overflow用户
提问于 2016-12-19 08:36:45
回答 1查看 1.7K关注 0票数 0

我正在使用raspberyy 3,RFID RC522。我想用wiringPi读一张卡片。我正在尝试这个密码;

代码语言:javascript
复制
#include<stdio.h>
#include<conio.h>
#include<wiringPi.h>
#include<wiringPiSPI.h>

int main()
{
    int chan = 1;
    int speed = 1000000;

    if (wiringPiSPISetup(chan, speed) == -1)
    {
        printf("Could not initialise SPI\n");
        return;
    }
    printf("When ready hit enter.\n");
    (void) getchar(); // remove the CR
    unsigned char buff[100];

    while (1)
    {
        int ret = wiringPiSPIDataRW(chan, buff, 4);
        printf("%d %s \n", ret, buff);

    }
}

当我尝试这个,它总是'4‘。怎么能读懂我不懂。

EN

回答 1

Stack Overflow用户

发布于 2016-12-19 10:00:37

您正在向从SPI设备发送未初始化的数据。

代码语言:javascript
复制
unsigned char buff[100];

while (1)
{
    int ret = wiringPiSPIDataRW(chan, buff, 4);
    printf("%d %s \n", ret, buff);

}

buffer内容是不确定的。

看着图书馆博士

int wiringPiSPIDataRW (int通道,无符号字符*数据,int wiringPiSPIDataRW); 这将在选定的SPI总线上执行同步的写/读事务。缓冲区中的数据被从SPI总线返回的数据覆盖。

这意味着您应该在缓冲区中插入要发送的消息。此数据将丢失,因为从应答将返回到同一个缓冲区。

看看这个例子,你应该做一些如下的事情:

代码语言:javascript
复制
 unsigned char buff[100] = {0};

 // Following bytes must be set according to your slave SPI device docs.
 buffer[0] = ??; 
 buffer[1] = ??;
 buffer[2] = ??;
 buffer[3] = ??;
 wiringPiSPIDataRW(chan, buffer, 4);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41218617

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档