i am using raspberyy pi 3 , RFID RC522. I want to read a card using wiringPi. I am trying this codes;
#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);
}
}
when I try this, it turns always '4'. How can read I don't understand.
You are sending uninitialized data to your slave SPI device.
buffer
content is indeterminate.Looking at the library doc
It means you should init your buffer with message to send. This data will be lost because of slave reply will be returned into the same buffer.
Looking at this example you should do sometning like: