SPI Communication with IC - Debugging Advice Sought

I got round to testing your code today and definitely it is progress! I am able to switch on some of the outputs now. Curiously, I can do this only once, even if I completely reset the IC. Here the code I used below - I've moved the reset commands into a subroutine since I am trying to reset the device and switch the outputs on a loop, and I've specified SPI mode 1 since that's what this IC uses (default is mode 0, I believe).

#include <SPI.h>

byte myData[] = { 0x00, 0x00, 0x0F } ; //24-bit command/data

void doReset() {

  //--hardware reset of the chip (MC33996)
  digitalWrite(9, HIGH);
  delay(3000); 
  digitalWrite(9, LOW);
  delay(3000); 
  digitalWrite(9, HIGH);   //Hardware reset of chip

}

void setup()
{
  Serial.begin(19200); //Serial Monitor is eanbled
  SPI.setDataMode( SPI_MODE1 ) ;
  SPI.begin();  //SPI Port of UNO is enabled; Mode-1, MSB-first; SS/ = Output and HIGH
  pinMode(9, OUTPUT);

  doReset() ;

}

void loop()
{

  //Wait for something
  while( !( Serial.available() > 0 ) ) {
    
  }

  // Flush input
  while( Serial.available() > 0 ) {
    Serial.read() ;
  }

  Serial.println( "AAAAAAAA" ) ;
  
  digitalWrite(SS, LOW);    //CS/ of chip is made LOW for data communication
  delayMicroseconds(100);   //for stabilization (optional)
  //----------------------
  SPI.transfer(myData, sizeof(myData));   //command byte and data bits for LED0 - LED3
  delayMicroseconds(100);   //for stabilization (optional)
  digitalWrite(SS, HIGH);   //data is latched at output at rising edge of CS/
  delayMicroseconds(100);   //for stabilization
  //----------------------

  delay(3000);   

  Serial.println( "BBBBBBBB" ) ;

  doReset() ;

  Serial.println( "CCCCCCCC" ) ;
 
//  digitalWrite(SS, LOW);    //Status information of chip is latched at falling edge 
//  byte x = SPDR;            //x hold status information : 00 good and FF bad
//  Serial.println(x, HEX);
//  digitalWrite(SS, HIGH);    //SS line is brought at LH-state.   (EDIT in respect of Post#2)
  //-----------------------
  
  delay(3000);              //sampling interval
}

Apologies for the ridiculous Serial.println debug commands :grinning: . Now the Arduino waits for some (any) input on the serial before it sends a command to the MCZ33996, leaves the device in that state for 3 seconds, then 3 seconds later runs the reset function.

Like I said, this will only allow me to switch the outputs exactly once, even if I let the loop run for say 20 seconds (to ensure that the Arduino is setting waiting for console input) then I manually bring the RST pin (27) on the MCZ33996 low either by removing the connection to pin 9 and/or manually connecting pin 27 to ground (through a resistor, to avoid drawing too much current from the Arduino).

This leads me to wonder whether the reset through pin 27 is actually working correctly, even though it does make the LEDs turn off... but is something I'll have to look into a bit more, apart from figuring out why the code you suggested is working and mine is not, since they appear (to my eyes) to do the same thing aside from the reset sequence (which may not be working for some reason). I should have access to an oscilloscope soon to see what's actually being sent to the MCZ33996.

Thanks again GolamMostafa, I really appreciate it! I'll update the thread when I've done some more investigation and made some more progress.

Scott