简体   繁体   English

更改Arduino uno SD.h上的SPI引脚

[英]Change SPI pins on Arduino uno SD.h

I have Arduino uno with ENC28J60 and microSD card reader, both work well independently. 我有带ENC28J60的Arduino uno和microSD卡读卡器,两者均可独立正常工作。 The only problem is that they both use the same pins 13,12,11,10. 唯一的问题是它们都使用相同的引脚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 我试图看一下SD.h库,因为它对我来说似乎更具可读性,并像这样更改Sd2PinMap中的设置

// 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. 我将它们匹配,因此新引脚也为PWM。 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. SPI通过使用独立的从选择线来支持多个器件。

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 ) 所需的安排如下所示(来自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. 这意味着两个器件可以共享时钟(SCK),输入(MISO)和输出(MOSI)引脚。 But each device needs to use a separate select (SS) pin. 但是每个设备都需要使用单独的选择(SS)引脚。

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: 例如对于https://github.com/arduino-libraries/SD,您可以使用:

boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);

and for https://github.com/njh/EtherCard you can use: 对于https://github.com/njh/EtherCard,您可以使用:

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. 这些方法允许您更改选择引脚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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