Arduino Micro SS pin

The Arduino Micro (I believe the Leonardo as well, but I don't own one) has an SS pin right beside the MOSI pin.

By looking at the port mapping http://arduino.cc/en/Hacking/PinMapping32u4 it seems that pin (phisycal pin 8) is mapped onto bit 0 of PORTB.

Do I have to go for direct http://arduino.cc/en/Reference/PortManipulation if I want to use the micro as a SPI slave or is there a way to reference the SS pin in a portable way like we do for analog and digital pins?

DDRB = DDRB | B00000001 // PB0 as OUTPUT
PORTB = PORTB | B00000001 // PB0 as HIGH

I have a library supporting SPI in slave mode, but it is written to use digital pins: is there a way to refer to the micro SS in a way compatible with digitalWrite and digitalRead functions?

Thanks everybody

You should be able to refer to it as "SS".

/hardware/arduino/variants/micro/pins_arduino.h includes ../leonardo/pins_arduino.h which defines SS as 17.

Have you got thus to work? I can't get a leonardo to act as slave, I think it is because it is physically attached to the Rx led.

Rx LED only needs like 0.5mA to pull it low. Is there something in pins_arduino.h for Leonardo that keeps the pin from acting normally? Like it's not defined as a user accessible pin? If so, that should be fixable.

From pins_arduino.h:

// New pins D14..D17 to map SPI port to digital pins // // MISO D14 PB3 MISO,PCINT3 // SCK D15 PB1 SCK,PCINT1 // MOSI D16 PB2 MOSI,PCINT2 // SS D17 PB0 RXLED,SS/PCINT0

So I'd use this pinMode (17, INPUT_PULLUP); // for slave side

and then the slave could respond to an interrupt or whatever to catch the command from a master and react accordingly.

Hard part: adding a wire to the board-edge of the RX LED so you have access to that pin, or to pin 8 of the 32U4.

That is, I think, the problem. The hardware spi seems to require that the pin is an input, and that it goes from high to low (this is possible on other arduino a, because the SS pin is not tied to the Rx led) But I think there is something else, because I can change the pin to an input, but then the write doesn't change the value, so you have to have a connection at the Rx led, or at some point between the main chip and the Rx led.

Unfortunately, I'm getting older and my eyes don't work as well as they used to, and my hands aren't as stable as they once were, so I'm a bit nervous about soldering on that tiny littl path between the two.

Interestingly, I've tried this setting it to output, setting high. It "flashes" Apparently, somewhere, the "core" code, or whatever is put in by the boot loader, or something else, is controlling this pin and "keeping" it as an output.

Has anyone been able to get a leonardo to act as a slave with spi?

Set to to input, solder a wire to the RX LED pad.

I don't particularly like the Leonardo design because of design choices like that. Take a nice chip, and then prevent users from accessing all the pins. Poor design.

Is that the right side of the led? I thought it needed to be on the other side, but then I have absolutely no knowledge of circuits, I was just tring to figure out where to put it without going backward through the led.

But, and I haven't tried this, yet... If something (in the real main code) is setting that to an output, as it think it is because I can't seem to keep it lit, then soldering a wire may still not solve the problem... No?

I traced it out using the eagle files. Confirm yourself, multimeter from the pad to the 32U4 pad. "real main code"? Try writing a simple sketch that makes D17 blink on/off, see if you can do it. If the USB interface code gets in the way, then a change can be made in that particular code.