Hi,
I am having an issue with the SPI communication on a G400D. I am communicating to an IO Expander, MCP23S17. Attached is a screen capture of my issue.
I have a dedicated GPIO pin for the chip select (blue on screen capture) and send over 16bits of register address followed by 16 bits of data (8bits actual data, 8 bits ignored) (yellow trace on screen capture)
I had this working correctly, but suddenly I am seeing an extra clock pulse(GREEN trace) before some of my messages.
It seems to be completely at random and if that extra clock pulse is not there, I can set the desired bit on my IO expander.
What could be causing this issue?
ushort[] Motor_IOCONFIG = new ushort[] { 0x400A };// I/O Configuration Register
ushort[] Motor_IODIRA = new ushort[] { 0x4000 }; // I/O Direction Register A
ushort[] Motor_IODIRB = new ushort[] { 0x4010 };// I/O Direction Register B
ushort[] Motor_GPPUB = new ushort[] { 0x4016 };// Pull Up Resistor Configuration for port B
ushort[] Motor_GPIOB = new ushort[] { 0x4019 };// Port Register reflect the value on the port B
ushort[] Motor_GPPUA = new ushort[] { 0x4006 }; // Pull Up Resistor Configuration for port A
ushort[] Motor_GPIOA = new ushort[] { 0x4009 };
ushort[] GPINTENA = new ushort[] { 0x4002 }; // Controls Interrupt-On-Change for each pin
ushort[] DEFVALA = new ushort[] { 0x4003 };
ushort[] IOCON_Data = new ushort[] { 0xA2 };
ushort[] DIR_Input_Data = new ushort[] { 0xFF };
ushort[] DIR_Output_Data = new ushort[] { 0x00 };
ushort[] PU_EN_Data = new ushort[] { 0xFF };
ushort[] PU_DIS_Data = new ushort[] { 0x00 };
//ushort[] PORTA_Status = new ushort[] {0x00};
SpiBase.ConfigureSpi(Stepper_Motor_IOExpander_SPI);
Motor_IOExpander_Reset.Write(false); // Reset IO Expander
Motor_IOExpander_Reset.Write(true);
Motor_IOExpander_CS.Write(false);
MotorControlSPI.WriteRead(Motor_IOCONFIG, SPI_DataReceived); // IO Expander IO Configuration Register Address
MotorControlSPI.WriteRead(IOCON_Data, SPI_DataReceived); // IO Expander IO Configuration Data
Motor_IOExpander_CS.Write(true);
Motor_IOExpander_CS.Write(false); // PortA Direction
MotorControlSPI.WriteRead(Motor_IODIRA, SPI_DataReceived); // Pins set as Output
MotorControlSPI.WriteRead(DIR_Output_Data, SPI_DataReceived);
Motor_IOExpander_CS.Write(true);
Motor_IOExpander_CS.Write(false); // PortB Direction
MotorControlSPI.WriteRead(Motor_IODIRB, SPI_DataReceived); // Pins set as Inputs
MotorControlSPI.WriteRead(DIR_Input_Data, SPI_DataReceived);
Motor_IOExpander_CS.Write(true);
PORTA_Status[0] = (ushort)PORTA_VALUES(PORTA_Status[0], "YRESET", "DISABLE");
PORTA_Status[0] = (ushort)PORTA_VALUES(PORTA_Status[0], "YSLEEPN", "DISABLE");
Motor_IOExpander_CS.Write(false);
MotorControlSPI.WriteRead(Motor_GPIOA, SPI_DataReceived);
MotorControlSPI.WriteRead(PORTA_Status, SPI_DataReceived);
Motor_IOExpander_CS.Write(true);