SPI slave power supply shutdown

Hello,
I am using a mega as master and an slave integrated circuit.
When I shut down the integrated circuit, the sck pin remain high.
Putting the sck high with the power supply off will destroy the circuit.
So I have to put the sck down before shuting down the supply of the IC.

if I put this code:

digitalWrite(SCK, LOW);

This doesn't work, the pin remain high.
If i print the SCK pin, like

Serial.print(SCK);

The number 13 is written in the console.
That is very surprising because for the Mega, according to the Arduino doc the sck pin is 52 !
Pin 13 is corresponding to SCK but for the arduino Uno....

But, the SPI bus is running correctli...

I try to force the pin 52 to low but the pin doesnt go down !

Any help will be welcome..

Best regards
Thierry

That is very surprising because for the Mega, according to the Arduino doc the sck pin is 52 !
Pin 13 is corresponding to SCK but for the arduino Uno....

Obviously, the code you couldn't be bothered posting assigns the value 13 to SCK.

Hello,

Yes I see the SCK pin is afected at pin 13.
I use the Mega and the sck pin is 52....

Very stange... but the library is running well...

do you know what can I do for changing the state of the sck pin ?

Best regards

Thierry

You must change the SPI mode. The default is mode zero. SCK LOW and pulses HIGH during clock pulses.

Modes 2 and 3 will leave the SCK line HIGH and pulses LOW. Is that your problem?

The SCK pin for the Mega2560 is D52. If that code shows D13, then you are not setting your board type correctly.

Hello

I use the standard library and the spi bus is working correctly.
I do not special initialisation, I just use SPI.begin() and transaction

It is very stange the sck pin is show at pin 13

I will try to make a fake transaction using SPI setting in mode 0.

Are you sure the mode 0 live the sck at low ?

Best regards

Thierry

Mode 0 leaves the SCK pin LOW. Which version Arduino compiler are you using? I have a Mega2560 here.

I have the version 1.7.9

Many thanks for your help

Can you try to print the sck pin ?

Thierry

I use IDE V1.6.7, and this code shows 52. It appears you are using code from the "other arduino website" (arduino.org).

void setup() {
  Serial.begin(115200);
  Serial.println(SCK);
}

void loop() {
}

How it's look like I have to change the compiler.

Can you try to this code:

digitalWrite(MOSI, LOW);

and verify the level of the mosi pin is low ?

Many thanks for your help

Thierry

P.S Do you know any commercial Mega with low power designe ?

It does change. I installed a jumper from D51 to D47 for a test. This test code first shows 1 for both MOSI and 47, then 0 for both.

void setup() {
  Serial.begin(115200);
  pinMode(MOSI,OUTPUT);
  digitalWrite(MOSI,HIGH);
  Serial.println(digitalRead(MOSI));
  Serial.println(digitalRead(47));
  digitalWrite(MOSI,LOW);
  Serial.println(digitalRead(MOSI));
  Serial.println(digitalRead(47));
}

void loop() {
}