Pin 4 in Example stetch in Arduino IDE ->SD->ReadWrite.ino
SPI pins for Uno and Nano models:
SD card attached to SPI bus as follows:
** SDO - pin 11
** SDI - pin 12
** CLK - pin 13
** CS - pin 4 (For For Uno
So, which is correct? I get the chip working with pin 4, but not work with pin 10, so I assume the datasheet should be incorrect?
the number in the first column is a location on the header, not the gpio number.
GND, AREF and other not GPIO pins have a number too. the second column has the GPIO number for other pins.
I agree that the table is confusing.
Thank you, I would like to point out, in the datasheet and schematic, chip select SS (PB2) is defined at D10,
but, UNO R3 can also work if connect SS wire to D4, and update the pin number in the sketch to 4. Seems the chip select SS can use any Digital pin of UNO R3.
Look into the manufacturer's data sheets for the definitions of the SPI Pins. The SPI Pins can also be found on the pin diagram of ATmega328P MCU (Fig-1).
The function of the SS pin is actually not a CS although it can be used like that. SS has a special function.
If you use the Arduino as a SPI master
The SS pin can be used as an output and hence as a CS pin for an external peripheral.
You can also configure the SS pin as an input in which case it (obviously) can not act as a CS pin for an external peripheral. You will need to keep the SS pin high, else the Arduino changes from SPI master to SPI slave (and will not automatically change back if you make the pin high again).
If you use the Arduino as a SPI slave
The SS pin is an input and acts as a CS pin so another microcontroller can select is as a slave.
We have 4-Wire SPI Port. When these codes: SPI.h and SPI.begin() are included in a sketch in UNO Plaform, the UNO becomes a SPI-Master with the following definitions:
DPin-10: SS (Software name when hardware name is SS/) as output and HIGH.
DPin-11: MOSI and output and LOW
DPin-12: MISO and input
DPin-13: SCK and output and LOW
Before, communication begns, the user must assert LOW on SS line to select the SPI-Slave.
After that, the execution of byte y = SPI.transfer(0x23); (for example) automatically generates 8 SCK pulses over the SCK line while 0x23 (0010 0011) are being transferred synchronously over the MOSI line.
The same SCK pulses brings-in the data from the Slave using MISO line and saves them into the y variable of Master.
In Arduino UNO sketch, the SS name (NOT CS) has definition in the SPI.h Library. So, SS/-pin (DPin-10) of UNO is connected with CS/-pin (active low) of the Slave.
It seems that you misunderstood the matter. There is no direct logic relation between master's SS pin and slave's CS.
The correct meaning of SS pin is described in @sterretje post #8
As I said, not necessarily. The code that makes use of the underlaying SPI library will use the pin that is specified as the CS pin. If that is the SS pin, it will make the SS pin LOW during the transaction, else that SS pin will stay HIGH.
The only thing that the SPI library does is make the SS pin HIGH and an output when calling the begin() method.
The BarometricPressureSensor.ino example does not use the SS pin (pin 10).