one arduino as both master and slave

Here’s my setup:I have one arduino mega controlling a system of stepper motors, and performing a bunch of calculations. I have a system of remote load cells that are fed into an arduino nano that is then relaying the info back to the mega using an nRF24L01 transmitter. I also need my PC to communicate with the mega. To keep the mega running calculations as quickly as it needs to, I can’t seem to have it control the RF and USB communications, which brings me to what I’m trying to do:

Is it possible to have the RF receiver(SPI) and PC (USB) input to an arduino uno that is a slave to the mega so that the mega can be running calculations while the uno constantly communicates with the RF receiver and buffers any PC inputs until the mega asks for the relevant data via an SPI interrupt function on the uno?

My assumption is that there is something in the RF24.h library that is keeping the UNO from switching to slave mode when D10 is set low by the mega. I’m not familiar enough with SPI or the RF24 to know how to fix it. The SS for the RF receiver is switched to D8, which I set high in the interrupt so that it isn’t sending data overlapping the UNO on MISO. I can’t find how to fix this. I’d appreciate any guidance.

Thank you

spi_slave_test.ino (1.72 KB)

lotrfan1991:
To keep the mega running calculations as quickly as it needs to, I can’t seem to have it control the RF and USB communications,

I don’t understand why this should be a problem. I don’t think receiving data using an nRF24 is any more of a burden for a Mega than (say) receiving the same data on a serial port from another Arduino.

Can you post the Mega code that illustrates that problem ?

You seem to be thinking of having 3 Arduinos - a Mega, a Nano and an Uno to act as a “bridge” between the Nano and the Mega.

Even if that threesome proves to be essential why not transfer data from the Uno to the Mega using serial comms - the Mega has 3 spare USARTs.

…R

You can also set up an I2C link and run it at 800Kbps. Even though one is a master and the others are slaves you can still do two-way communication. The master can ask for data from a slave or send a message to it. You can also have the master query a slave periodically if it has something to say. In addition, a slave can raise a digital pin on the master as a faster way of saying I have something to send you.

The issue I was having was that I'm needing the Mega to perform on the order of a few milliseconds per loop, but the serial communication was slowing things down too much. My idea was to have a separate arduino serve as a sort of buffer and handle all of the communications, and just send what info was needed by the mega to it when asked.

I've just been going through my mega code and realized that I had some poorly written pieces that were causing the poor serial communication. I can fix those and both serial and nRF24 should be able to be fed directly into the mega without issues, I believe.

So, problem found to not need to be solved.

lotrfan1991:
I had some poorly written pieces that were causing the poor serial communication.

The examples in Serial Input Basics may be helpful. They are simple, reliable and non-blocking.

...R