It is possible to do your own CS (chip select) managing, but i prefer the way the SPI class manages this.
So i've made a little factory for making it easy to switch between spi devices.
Use:
byte spiIdDisplay = SpiFactory.AddConfig(new SPI.Configuration(PIN_LCD_CS , false , 0 , 0 , false , true , 10000 , SPI.SPI_module.SPI1 )); byte spiIdTouch = SpiFactory.AddConfig( new SPI.Configuration(PIN_TOUCH_CS , false , 1 , 1 , false , true , 590 , SPI.SPI_module.SPI1 ) );
and when you want to use a SPI device:
SPI spi = SpiFactory.GetSPI( spiIdTouch ); ....
/// <summary> /// De SPI interface kan meerdere devices aansturen, maar het MF heeft hiervoor geen voorziening. /// /// Ik kies ervoor om verschillende configuraties te gebruiken, en het SPI object telkens te herconfigureren. /// /// Static class gebruikt omdat dit vermoedelijk minder ruimte inneemt dan een Singleton /// </summary> public static class SpiFactory { static ArrayList Configurations = new ArrayList(); static SPI currentSPI = null; // Er zullen nooit 256 devices zijn ! static byte currentId = 0xFF; /// <summary> /// de ID van de configuratie wordt teruggegeven, zodat dit later /// gebruikt kan worden om een nieuw SPI object te configureren. /// </summary> public static byte AddConfig( SPI.Configuration config ) { Configurations.Add(config); return (byte)(Configurations.Count - 1); } public static SPI GetSPI(byte spiId) { if (currentId == spiId) return currentSPI; if (currentSPI != null) currentSPI.Dispose(); SPI.Configuration config = (SPI.Configuration)Configurations[spiId]; currentSPI = new SPI(config); currentId = spiId; return currentSPI; } }