Hello,
New to the forum, still getting the hang of things with the G400. I am trying to use the SPI2 module on the G400 to access multiple IC’s. Now, the way that my circuit has been set up is to use a MUX that will select between which IC CS pin to access. I managed to get the SPI to work when I set a specific pin on the G400 but I am not sure how to tell the SPI communication protocol which switch case I would like to use if I implement the MUX. Any suggestions?
Thank You,
Dave
// Digital Potentiometer
// CS - Use MUX table, up to eight options
static OutputPort DIG_POT_EN = new OutputPort(GHI.Pins.G400.PD8, true); // bool true will set all CS to high
static OutputPort DIG_POT_S0 = new OutputPort(GHI.Pins.G400.PC23, true);
static OutputPort DIG_POT_S1 = new OutputPort(GHI.Pins.G400.PD0, true);
static OutputPort DIG_POT_S2 = new OutputPort(GHI.Pins.G400.PD2, true);
public static void Main()
{
int chann = 2;
SPI.Configuration SPI_DigPot = new SPI.Configuration(?????, //Chip Select Port
false, //ChipSelect Active State
0, //CLK Setup Time
0, //CLK Hold Time
false, //Clock Idle State
false, //Clcok Edge
400, //Clock Rate kHz
SPI.SPI_module.SPI2); //SPI Module
ushort[] Wiper_Pos_EN = new ushort[] { 0x0500 }; // Enable update of wiper positons
ushort[] Wiper = new ushort[] { 0x1802 }; // Wiper Position
ushort[] RDAC_Read = new ushort[] { 0x0800 }; // Prepare data read from RDAC register
ushort[] NOP = new ushort[] { 0x0000 }; // NOP instruction
MySPI.WriteRead(Wiper_Pos_EN, rx_data); //send data
DIG_POT_EN.Write(true); //set all CS to high
}
private void Update_Wiper_Channel(int DIG_POT_Channel)
{
switch (DIG_POT_Channel)
{
case 1: //Channel 1 Digital Pot CS is selected
DIG_POT_EN.Write(false);
DIG_POT_S0.Write(false);
DIG_POT_S1.Write(false);
DIG_POT_S2.Write(false);
break;
case 2: //Channel 2 Digital Pot CS is selected
DIG_POT_EN.Write(false);
DIG_POT_S0.Write(true);
DIG_POT_S1.Write(false);
DIG_POT_S2.Write(false);
break;
case 3: //Channel 3 Digital Pot CS is selected
DIG_POT_EN.Write(false);
DIG_POT_S0.Write(false);
DIG_POT_S1.Write(true);
DIG_POT_S2.Write(false);
break;
case 4: //Channel 4 Digital Pot CS is selected
DIG_POT_EN.Write(false);
DIG_POT_S0.Write(true);
DIG_POT_S1.Write(true);
DIG_POT_S2.Write(false);
break;
case 5: //Channel 5 Digital Pot CS is selected
DIG_POT_EN.Write(false);
DIG_POT_S0.Write(false);
DIG_POT_S1.Write(false);
DIG_POT_S2.Write(true);
break;
case 6: //Channel 6 Digital Pot CS is selected
DIG_POT_EN.Write(false);
DIG_POT_S0.Write(true);
DIG_POT_S1.Write(false);
DIG_POT_S2.Write(true);
break;
case 7: //Channel 7 Digital Pot CS is selected
DIG_POT_EN.Write(false);
DIG_POT_S0.Write(false);
DIG_POT_S1.Write(true);
DIG_POT_S2.Write(true);
break;
case 8: //Channel 8 Digital Pot CS is selected
DIG_POT_EN.Write(false);
DIG_POT_S0.Write(true);
DIG_POT_S1.Write(true);
DIG_POT_S2.Write(true);
break;
default:
break;
}
}