10.3.3 SPI Programming via CommandLists |
SPI Modules can be used to transmit arbitrary data from commands in a CommandList.
Please refer to: 10.3.1 SPI Data Transfer Modes
using ( ClientAPI client = new ClientAPI( CardIP ) ) { client.System.ResetToDefaults(); // // Configure Port A to output SPI Module 0 signals. // IODirection[] directions = client.Gpio.GetDirections( IOPort.PortA ); directions[0] = IODirection.Output; directions[1] = IODirection.Input; client.Gpio.SetDirections( IOPort.PortA, directions ); client.Gpio.SetIOLevel( IOPort.PortA, IOVoltage.ThreePointThree ); Polarity[] polarities = client.Gpio.GetPolarities( IOPort.PortA ); polarities[1] = polarities[2] = polarities[3] = polarities[11] = Polarity.ActiveHigh; client.Gpio.SetPolarities( IOPort.PortA, polarities ); int[] functions = client.Gpio.GetFunctions( IOPort.PortA ); functions[1] = // SPI0.SYNC functions[2] = // SPI0.CLK functions[3] = // SPI0.DO functions[11] = 3; // SPI0.DI client.Gpio.SetFunctions( IOPort.PortA, functions ); // // (Re-)Configure the SPI Module 0 signal parameters. // int module = 0; SpiConfig sc = client.Sfio.Spi.GetConfig(); SpiModule sm = sc.Modules[module]; sm.Enabled = true; sm.BitsPerWord = 32; sm.OutputSource = DataSource.SpiListCommand; sm.SpiSyncMode = SyncMode.MarkEndOfWord; sm.ClockPeriod = 0.09; sm.PostDelay = 0; sm.PreDelay = 0; sm.FrameDelay = 0; sc.Modules[module] = sm; client.Sfio.Spi.SetConfig( sc ); // // Prepare and transmit a message. // uint[] transmitMessage = new uint[] { 0x9999FFFF, 0x8888AAAA }; CommandList cl = new CommandList(); cl.AppendJumpAbs( 0, 0 ); cl.AppendSpiWrite( module, transmitMessage[0] ); cl.AppendMarkAbs( 10000, 10000 ); cl.AppendSpiWrite( module, transmitMessage[1] ); cl.AppendMarkAbs( 10000, -10000 ); cl.AppendJumpAbs( 0, 0 ); client.List.Set( 0, cl ); int? id; client.List.Execute( 0 ); client.List.WaitForListDone( out id, 500 ); }