简体   繁体   中英

Change SPI pins on Arduino uno SD.h

I have Arduino uno with ENC28J60 and microSD card reader, both work well independently. The only problem is that they both use the same pins 13,12,11,10. Is there a Way how to change it for another?

I tried to have a look at the SD.h library as it seems more readable to me and change the settings in Sd2PinMap like this

// SPI port
uint8_t const SS_PIN = 5;
uint8_t const MOSI_PIN = 6;
uint8_t const MISO_PIN = 7;
uint8_t const SCK_PIN = 4;

It seems that it didn't take any effect. I matched them so new pins are PWM as well. Is there anything else that should be set? Can they even be changed?
Thanks for your answers

SPI supports multiple devices by using separate slave select lines.

The arrangement that you want is illustrated below (from https://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/SPI_three_slaves.svg/350px-SPI_three_slaves.svg.png )

具有多个从机的SPI

This means that both devices can share the clock (SCK), input (MISO) and output (MOSI) pins. But each device needs to use a separate select (SS) pin.

Depending on what library you are using to access these devices, then you can configure them to use different select pins.

eg for https://github.com/arduino-libraries/SD you can use:

boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);

and for https://github.com/njh/EtherCard you can use:

static uint8_t begin (const uint16_t size, const uint8_t* macaddr,
                      uint8_t csPin = SS);

These methods allow you to change the select pins.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM