1

I followed this tutorial to connect one RC522 RFID reader in a Raspberry Pi.

http://www.nikolaus-lueneburg.de/2014/06/rfid-rc522-modul-mit-spi-schnittstelle/

I'm able to connect it to work with slave 1, using the CE0 pin (P24 - GPIO8) on Raspbberry 1 B+.

I would like to connect two equal RC522 RFID readers in the Raspberry Pi. But with the code provided in the tutorial I wasn't able to connect the reader as Slave 2 (CE1, in pin P26). And consequently, I couldn't connect both at the same time.

Details: The code from the tutorial we are using is here: https://code.google.com/archive/p/rpi-rc522/source/default/source

The modifications we tried is in the function on the file main.c

uint8_t HW_init(uint32_t spi_speed, uint8_t gpio) {
uint16_t sp;

sp=(uint16_t)(250000L/spi_speed);
if (!bcm2835_init()) {
    syslog(LOG_DAEMON|LOG_ERR,"Can't init bcm2835!\n");
    return 1;
}
if (gpio<28) {
    bcm2835_gpio_fsel(gpio, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_write(gpio, LOW);
}

bcm2835_spi_begin();
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);      // The default
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);                   // The default
bcm2835_spi_setClockDivider(sp); // The default
bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);      // the default
return 0;
}

We tried to change the 2 occurrences of BCM2835_SPI_CS0 to BCM2835_SPI_CS1, but it don't detect any card in this way, changing the CS pin from p24 to p26). The gpio parameter is defined in a config file, with default value to 18, and changing it don't seems to affect it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.