Hello, the ATMEGA32U4 has I/O pins PB0, PB1, PB2, and PB3 that have specified alternate functionality of SS, SCLK, MOSI, and MISO, respectively. I am using these pins with an AD7739 ADC. I would like to use another subordinate AD7739 for data collection into another I/O pin.
Can any given I/O pin (say, PB6) be used as SCLK/MOSI/MISO to the second ADC or would I be restricted to the PB0/1/2/3 only?
Good point. SS or slave select can be any pin, so if the AD7739 is “well behaved” with regard to SPI (some devices are not) you should have no problem connecting two of them in parallel.
Your code will select each device by setting its SS pin active, read the data from that device, then de-select it. The default SS pin PB0 must be set to OUTPUT, regardless whether you use it for SS, or the SPI module will not function as expected.
In my case, the wirings/connections are not able to be changed, so putting two ADCs to share MOSI, MISO, and SCLK while having different SS is not an option. My board is wired such that I have the second ADC’s SPI set of SS, SCLK, MOSI, and MISO on the general I/O ports PORTB7, PORTB6, PORTC7, and PORTC6 respectively. I’m just trying to find out if it is even possible to use those ports for those functions.
So, any I/O port can be used as an SS, however not any given I/O can be used as MOSI, MISO, or SCLK?
the wirings/connections are not able to be changed
How strange.
As already stated, any given I/O can be used as MOSI, MISO and SCK if you use software SPI. Since you claim to be stuck with poor choices for MCU board and wiring, software SPI would be your only option for the second ADC.
On the other hand, according to your latest post, you are not even free to choose another pin for SS, so you really have no option except to get another MCU board.
I’ve been thinking more about my issue - let’s say that I am able to write software SPI to receive data from ADC2. Would ADC1 (hardware SPI) and ADC2 (software SPI) be able to transmit/receive their own data simultaneously? Would I need to worry about any performance issues? Would I be saving any time compared to the normal hardware SPI having the ADCs on different SSs?
Your code can only do one thing at a time, so even if you were to read/write to both the hardware SPI and software SPI ports at the same time, it wouldn’t matter since the 32U4 can only deal with one of them. You’d be better off to keep things simple and put both devices on the same SPI port with different CS/SS lines and just read/write one at a time by selecting it.
If for some reason you must use software SPI, the library in the link below worked for me on a Leonardo which is also a ATMega32U4 based board.