Go Down

Topic: Arduino Micro SPI Pin Mapping / Referencing (Read 7951 times) previous topic - next topic

robertspark

Hello,

Can't seem to find this anywhere so any direction / hand holding would be greatly appreciated.

If I was to reference the pins MOSI, MISO & SCK, for the micro, how would I do it / what would I call / define them?

I am aware that the pins for the uno can be defined as pins 11, 12 & 13 respectivly, but what would they be called / named or defined as on the micro.

I am aware that SS can be any pin, proving RX_LED / SS is defined as an output, but can you use RX_LED/SS as a slave select pin, or do you need to use one of the other pins, give it has an led on it (unless you de-solder the LED??)

There is a reference here to 14 (MISO), 15 (SCK), 16 (MOSI).
https://www.arduino.cc/en/Reference/SoftwareSerial

But nothing within the "connections" table here: https://www.arduino.cc/en/Reference/SPI

Thanks,

Rob

chucktodd

#1
Jul 24, 2015, 03:33 am Last Edit: Jul 24, 2015, 03:37 am by chucktodd Reason: leonardo mapping
Hello,

Can't seem to find this anywhere so any direction / hand holding would be greatly appreciated.

If I was to reference the pins MOSI, MISO & SCK, for the micro, how would I do it / what would I call / define them?

I am aware that the pins for the uno can be defined as pins 11, 12 & 13 respectivly, but what would they be called / named or defined as on the micro.

I am aware that SS can be any pin, proving RX_LED / SS is defined as an output, but can you use RX_LED/SS as a slave select pin, or do you need to use one of the other pins, give it has an led on it (unless you de-solder the LED??)

There is a reference here to 14 (MISO), 15 (SCK), 16 (MOSI).
https://www.arduino.cc/en/Reference/SoftwareSerial

But nothing within the "connections" table here: https://www.arduino.cc/en/Reference/SPI

Thanks,

Rob
MOSI, MISO, SCK, SS are defines to the hardware pins.

MOSI=7 does not work.  the Master Out Slave In hardware cannot be moved to another pin.

the SPI library can use any digital pin for a _CS function, SS is defined as a link to the hardware Slave Mode SPI ChipSelect (SS).

Arduino Micro pin Mapping

Scroll down to the image at the bottom of the page for this image



Micro Pin Mapping, same as Leonardo

you can use:
Code: [Select]

pinMode(MISO,OUTPUT);
digitalWrite(MISO,LOW);


what else do you need?

Chuck.
Currently building mega http server 90% done, the Last 10% is killing me.

robertspark

Thanks Chuck,

The reason for my asking was I was trying / hoping to use this library for the AD7706 16 bit ADC chip that uses SPI.

When having a look through the library files:
http://www.kerrywong.com/2011/03/20/ad7705ad7706-library/
http://www.kerrywong.com/2012/04/18/ad7705ad7706-library-revisited/
http://www.kerrywong.com/blog/wp-content/uploads/2012/04/AD770X1.1.tar.gz

, I noticed at the bottom of the file (AD770X.h) the following bit of code:

Code: [Select]
private:
    static const int pinMOSI = 11; //MOSI
    static const int pinMISO = 12; //MISO
    static const int pinSPIClock = 13; //SCK
    static const int pinCS = 4; //CS
    double VRef;
    unsigned int readADResult();


this all came about because when I was inputting the library I wondered where the SS pin was defined as I was obviously using a different pin (I'm actually using 2 SPI devices on the same bus, hence two SS/CS pins defined)

And that got me wondering if I needed to change the defined MOSI, MISO and SCK pins too that were numbered in the library? (no I haven't breadboarded it yet).

Thanks in advance for any guidance

Rob

Riva

#3
Jul 24, 2015, 08:50 am Last Edit: Jul 24, 2015, 08:52 am by Riva
Look in pins_arduino.h and you should see the MOSI,MISO etc defined.
For standard variant it looks like this...
Code: [Select]
static const uint8_t SS   = 10;
static const uint8_t MOSI = 11;
static const uint8_t MISO = 12;
static const uint8_t SCK  = 13;

So you could probably just use these constants instead of re-defining your own as in the example you posted.
Don't PM me for help as I will ignore it.

robertspark

Thanks very much Riva


 for anyone else wondering the answer lays within:

.... \Arduino\hardware\arduino\avr\variants\leonardo\pins_arduino.h

Code: [Select]

//Map SPI port to 'new' pins D14..D17
static const uint8_t SS   = 17;
static const uint8_t MOSI = 16;
static const uint8_t MISO = 14;
static const uint8_t SCK  = 15;



given,
....\Arduino\hardware\arduino\avr\variants\micro\pins_arduino.h
calls
#include "../leonardo/pins_arduino.h"


Thanks everyone for the guidance,

Rob

chucktodd

Thanks Chuck,

The reason for my asking was I was trying / hoping to use this library for the AD7706 16 bit ADC chip that uses SPI.

When having a look through the library files:
http://www.kerrywong.com/2011/03/20/ad7705ad7706-library/
http://www.kerrywong.com/2012/04/18/ad7705ad7706-library-revisited/
http://www.kerrywong.com/blog/wp-content/uploads/2012/04/AD770X1.1.tar.gz

, I noticed at the bottom of the file (AD770X.h) the following bit of code:

Code: [Select]
private:
    static const int pinMOSI = 11; //MOSI
    static const int pinMISO = 12; //MISO
    static const int pinSPIClock = 13; //SCK
    static const int pinCS = 4; //CS
    double VRef;
    unsigned int readADResult();


this all came about because when I was inputting the library I wondered where the SS pin was defined as I was obviously using a different pin (I'm actually using 2 SPI devices on the same bus, hence two SS/CS pins defined)

And that got me wondering if I needed to change the defined MOSI, MISO and SCK pins too that were numbered in the library? (no I haven't breadboarded it yet).

Thanks in advance for any guidance

Rob
With those const defines, that code will only work for UNO equivilents, MEGA, Leonardo .. are orginized differently.  I would review the code and see what other AssUMptions are made.

Chuck.
Currently building mega http server 90% done, the Last 10% is killing me.

Project88

Hello everyone!
I have the same problem with SS pin on my Arduino Micro, I know that on this pin hooked up RX LED and bootloader use it like out. But I want to use my micro in slave mode, is it possible or not?

Perehama

Hello everyone!
I have the same problem with SS pin on my Arduino Micro, I know that on this pin hooked up RX LED and bootloader use it like out. But I want to use my micro in slave mode, is it possible or not?
You probably want to start your own thread as this diverges from the previous responses.

a quote from the SPI Library documentation: "This library allows you to communicate with SPI devices, with the Arduino as the master device."

another quote:"Since this library supports only master mode, this pin should be set always as OUTPUT otherwise the SPI interface could be put automatically into slave mode by hardware, rendering the library inoperative."

To use your Arduino's Library in slave mode would require you write your own code.

See http://www.gammon.com.au/forum/?id=10892 for help.

Project88

#8
Apr 12, 2017, 11:10 am Last Edit: Apr 12, 2017, 11:18 am by Project88 Reason: Add information
You probably want to start your own thread as this diverges from the previous responses.

a quote from the SPI Library documentation: "This library allows you to communicate with SPI devices, with the Arduino as the master device."

another quote:"Since this library supports only master mode, this pin should be set always as OUTPUT otherwise the SPI interface could be put automatically into slave mode by hardware, rendering the library inoperative."

To use your Arduino's Library in slave mode would require you write your own code.

See http://www.gammon.com.au/forum/?id=10892 for help.
Thank you for advise, I know that for slave made I need write my own code, but even if I'll write it, it will not work becouse Micro in slave mode can't see SS pin like input, even if I'll try to change pins_arduino.h for set another pin like SS, it will not work, becouse on Mega32u4 there is speciall pin PB0 for this porpose, and on this pin hooked up RX LED :-( In result I can't figure out how set SS pin like input on Mirco while boot loader use it for blinking RX led when I load sketch on arduino.

This is link on my Arduino micro:

https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/hardware-overview-pro-micro

Riva

From the pro micro variants folder the pins_arduino.h file contains...
Code: [Select]

// Map SPI port to 'new' pins D14..D17
static const uint8_t SS   = 17;
static const uint8_t MOSI = 16;
static const uint8_t MISO = 14;
static const uint8_t SCK  = 15;

So can you just do a pinMode(SS, INPUT); or pinMode(17, INPUT); to make the SPI behave as a slave. The TX LED will no longer work.
Don't PM me for help as I will ignore it.

Project88

From the pro micro variants folder the pins_arduino.h file contains...
Code: [Select]

// Map SPI port to 'new' pins D14..D17
static const uint8_t SS   = 17;
static const uint8_t MOSI = 16;
static const uint8_t MISO = 14;
static const uint8_t SCK  = 15;

So can you just do a pinMode(SS, INPUT); or pinMode(17, INPUT); to make the SPI behave as a slave. The TX LED will no longer work.
If I right understood I can set 17 pin like input in program but my RX LED will never work?

Riva

If I right understood I can set 17 pin like input in program but my RX LED will never work?
Sorry I never fully followed through on your request.
Setting pin 17 to input will make the MCU hardware SPI work in slave mode but because the SS pin is not broken out to a user pin it cannot receive the CS low signal from a master SPI device to start clocking in data.
You will either need to use a soldering iron and replace R4 with a breakout wire or maybe use a software SPI slave.
Don't PM me for help as I will ignore it.

Perehama

Thank you for advise, I know that for slave made I need write my own code, but even if I'll write it, it will not work becouse Micro in slave mode can't see SS pin like input, even if I'll try to change pins_arduino.h for set another pin like SS, it will not work, becouse on Mega32u4 there is speciall pin PB0 for this porpose, and on this pin hooked up RX LED :-( In result I can't figure out how set SS pin like input on Mirco while boot loader use it for blinking RX led when I load sketch on arduino.

This is link on my Arduino micro:

https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/hardware-overview-pro-micro
Slave devices do not have SS pins. They have CS pins. The Master takes the SS output low which is connected to the CS input of the slave, so you will want to setup a pin as an input and then you can monitor the state of this pin to know when it goes low, the data that will be sent on the bus will be for your slave.

The SPI library doesn't do this, but Nick Gammon wrote and excellent guide on how to do this with example code, which I linked in my previous post.

Go Up