Mega chip select pins

Hi guys,

Is it possible to use any digital pin as a chip select pin on the mega ?

I am building a board which is pretty heavily populated and I want to include a Micro SD adapter. Normally they seem to use pin 4 for the chip select but I'm already using that pin. Ideally I'd like to use pin 16 (TX2) or pin 17 (RX2).

Is it possible to just change the cs pin in my code or are there any hardware limitations?

Thanks in advance.

Yes, you can use any digital pin for CS as long as it is not also currently being used for something else

For instance, pins 16 and 17 are used by Serial2 but if you are not using it then they are available to be used as CS

1 Like

Thank you !

I meant to say that you can also use the analogue pins too because they also work as digital pins, so you have plenty of choice on a Mega

1 Like

Please note, that some SD Modules need some fix, if you going to use it with other SPI devices.
See today's discussion on that matter

Thank you for pointing this out.

I wasn't aware of this issue but (by sheer fluke !!) I'm only using 3 level shifters (MOSI, SCK and CS) with MISO connected directly to the SD socket so it should be Ok. I do currently have one other device (MCP2515 CanBus) on the bus and will potentially add a third (TFT Display) although my preference will probably be to go I2C with that.

Sanity checking the design revealed that D6 (device pin 15) was free so I've opted to go for that for the SD CS.

Thank you again !

Gareth

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.