Hi. I am having trouble with multiple devices on an SPI bus. One of the devices is an SD card, which is controlled through the SD library from adafruit. My other devices are ADC's, which I used to control manually, just toggling pins as needed - they are on the SPI pins though. Trying to combine the two causes my ADC code to fail.
Am I correct to assume that using the SPI library removes my ability to manually access those pins? If so what is normally done in this situation? I don't have enough pins to use different ones for my ADC's.
The SD library might be changing the SPI 'mode' (polarity of data and clock edge), the direction of shift (MSB or LSB first), or the data rate (clock divider). You might need to set those whenever you change devices.
steve108:
Am I correct to assume that using the SPI library removes my ability to manually access those pins? If so what is normally done in this situation? I don't have enough pins to use different ones for my ADC's.
IO expander?
With SPI active certain pin states are overridden. See the Atmega328 datasheet page 168:
When the SPI is enabled, the data direction of the MOSI, MISO, SCK, and SS pins is overridden according to Table 18-1 on page 168. For more details on automatic port overrides, refer to ”Alternate Port Functions” on page 80.
If you are going to chop and change you would need to do a SPI.end () to turn off SPI mode, do your other stuff, and then do SPI.begin () to re-enable it when required.
I presume you are using the SS lines to disable the SPI devices or it has no hope of working.
Okay thanks. What confused me is that I am still using the SPI pins in the normal spi I/O mode (MOSI, MISO, SCK). I just want to manually change the state from high to low on mosi and sck. I am going to look in to rewiring with a mux to free up some pins.