Pages: [1]   Go Down
Author Topic: SD card library - Why does pin 10 have to be configured as an output?  (Read 333 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The documentation states that the library won't function properly if pin 10 isn't configured as an output, even if you aren't using it as the chipselect.  I haven't been able to find any explanation as to why it won't function correctly or if it is just specific features that won't function correctly.  Can someone explain what it is that won't work if you don't configure pin 10 as an output?  I've commented that line out in some of the example sketches and it seems to still work fine.  I am using a Leonardo with the sd card wired up to the spi pins and I'm using pin A4 as the chipselect.
Logged

Arduino Uno;
Mega328

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The documentation states that the library won't function properly if pin 10 isn't configured as an output, even if you aren't using it as the chipselect.  I haven't been able to find any explanation as to why it won't function correctly or if it is just specific features that won't function correctly.  Can someone explain what it is that won't work if you don't configure pin 10 as an output?  I've commented that line out in some of the example sketches and it seems to still work fine.  I am using a Leonardo with the sd card wired up to the spi pins and I'm using pin A4 as the chipselect.

It has to do with the internal SPI hardware inside the AVR chip, using that pin to configure itself to be in master or slave mode depending on the pin mode of that pin, output mode = master mode, input mode = slave mode. The AVR datasheet is the source of such gory details. If you were using a totally software drive SPI function then that would not be an issue, but you would not be able to obtain the high performance possible with the hardware SPI unit.

Lefty
Logged

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The documentation states that the library won't function properly if pin 10 isn't configured as an output, even if you aren't using it as the chipselect.  I haven't been able to find any explanation as to why it won't function correctly or if it is just specific features that won't function correctly.  Can someone explain what it is that won't work if you don't configure pin 10 as an output?  I've commented that line out in some of the example sketches and it seems to still work fine.  I am using a Leonardo with the sd card wired up to the spi pins and I'm using pin A4 as the chipselect.

It has to do with the internal SPI hardware inside the AVR chip, using that pin to configure itself to be in master or slave mode depending on the pin mode of that pin, output mode = master mode, input mode = slave mode. The AVR datasheet is the source of such gory details. If you were using a totally software drive SPI function then that would not be an issue, but you would not be able to obtain the high performance possible with the hardware SPI unit.

Lefty

Perfect explanation!  Thank you.  The shield that I made uses pin 10 for another function but I guess lucky for me that functionality uses the pin as an output also.  I guess I would have had problems if the other functionality used that pin as an input.
Logged

Arduino Uno;
Mega328

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The documentation states that the library won't function properly if pin 10 isn't configured as an output, even if you aren't using it as the chipselect.  I haven't been able to find any explanation as to why it won't function correctly or if it is just specific features that won't function correctly.  Can someone explain what it is that won't work if you don't configure pin 10 as an output?  I've commented that line out in some of the example sketches and it seems to still work fine.  I am using a Leonardo with the sd card wired up to the spi pins and I'm using pin A4 as the chipselect.

It has to do with the internal SPI hardware inside the AVR chip, using that pin to configure itself to be in master or slave mode depending on the pin mode of that pin, output mode = master mode, input mode = slave mode. The AVR datasheet is the source of such gory details. If you were using a totally software drive SPI function then that would not be an issue, but you would not be able to obtain the high performance possible with the hardware SPI unit.

Lefty

Perfect explanation!  Thank you.  The shield that I made uses pin 10 for another function but I guess lucky for me that functionality uses the pin as an output also.  I guess I would have had problems if the other functionality used that pin as an input.

That is correct. The AVR SPI hardware does not force you to use pin 10 as the SPI SS signal to the external device and the SPI library never touches pin 10, But it does use pin 10 mode as the SPI mode selector. The user's sketch determine which pin(s) to use as the SS pin(s) for the external device(s) and manipulates it before and after each SPI function command to a or each specific device. By having unique SS pins for different SPI devices one can communicate with multiple SPI devices using the common SPI pins and only unique SS pins, if that makes sense.

Lefty
Logged

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Definitely! Thanks!
Logged

Arduino Uno;
Mega328

Pages: [1]   Go Up
Jump to: