public UsbToSpiDevice() { _hidComHandler = new HidSharpCommunicationHandler(); _nvram = new NonVolatileRam(_hidComHandler); _ram = new VolatileRam(_hidComHandler); _extInterruptPin = new ExternalInterruptPin(_hidComHandler); _spiDataTransfer = new SpiDataTransfer(_hidComHandler); _eeprom = new EepromMemory(_hidComHandler); }
static void TestVoltatileRam(IVolatileRam ram) { Console.Write("*** Test RAM: "); try { // set the chip configuration ChipSettings chipSettings = new ChipSettings(); chipSettings.InterruptBitMode = DedicatedFunction.NoInterruptCounting; chipSettings.RemoteWakeUpEnabled = false; chipSettings.SpiBusReleaseEnable = false; // these are never used by the volatile RAM //chipSettings.AccessControl = NramChipAccessControl.PasswordProtected; //chipSettings.Password = "******"; chipSettings.PinDirections = new PinDirection[] { PinDirection.Output, PinDirection.Output, PinDirection.Output, PinDirection.Output, PinDirection.Output, PinDirection.Output, PinDirection.Output, PinDirection.Output, PinDirection.Output }; chipSettings.PinModes = new PinMode[] { PinMode.GPIO, PinMode.GPIO, PinMode.GPIO, PinMode.GPIO, PinMode.GPIO, PinMode.GPIO, PinMode.GPIO, PinMode.DedicatedFunction, // release status bit PinMode.GPIO }; chipSettings.DefaultOutput = new bool[] { true, false, false, true, false, false, false, true, true }; ram.ConfigureChip(chipSettings); ChipSettings readSettings = ram.ReadChipConfiguration(); // configure SPI SpiSetup spiSetup = new SpiSetup(); spiSetup.BitRate = 200000; spiSetup.BytesToTransfer = NumberOfBytes; spiSetup.ChipSelectToDataDelay = 0; spiSetup.BetweenDataDelay = 0; spiSetup.DataToChipSelectDelay = 0; spiSetup.Mode = SpiModes.Spi2; spiSetup.ActiveChipSelectValues = new bool[] { true, true, true, true, true, true, true, true, true }; spiSetup.IdleChipSelectValues = new bool[] { false, false, false, false, false, false, false, false, false }; ram.ConfigureSpi(spiSetup); // read spi configuration SpiSetup readSpiSetup = ram.ReadSpiConfiguration(); // set the gpio output bool[] output = new bool[] { false, true, true, false, true, true, false, true, true }; ram.GpioPinsValue = output; Console.WriteLine("completed successfully"); } catch (Exception ex) { PrintException(ex); } }