My question is, is it ok to have a serial data connection open but not really used until the Mega is interrupted?
Also, I have data constantly flowing through the ICSP ports. Will my idea of using another serial port interfere with data from the ICSP ports?
--The Short Stuff--
When an Arduino Mega receives an interrupt, I would like to send a message from the the Mega to an Arduino Micro asking to send more information.
--End of Short Stuff--
--The Long Stuff--
The Micro is constantly gathering and processing values from 6 sensors. When it is alarmed of some value, I want it to interrupt the Mega. After that, the micro will send over some arrays so the Mega may
calculate the next process to run.
All the while data is being sent from a CMUCam5 Pixy through the ICSP port.
--End of Long Stuff--
is it ok to have a serial data connection open but not really used until the Mega is interrupted?
Yes that is fine.
Will my idea of using another serial port interfere with data from the ICSP ports?
No.
The Micro is constantly gathering and processing values from 6 sensors. When it is alarmed of some value, I want it to interrupt the Mega. After that, the micro will send over some arrays so the Mega may
calculate the next process to run.
Not sure that you understand what an interrupt means. What you described is not an interrupt.
Grumpy_Mike:
Not sure that you understand what an interrupt means. What you described is not an interrupt.
I have left a couple of details out. My bad. The Mega is running a driving program. As soon as the micro detects an impending collision from my sensors, the micro is to tell the mega to turn a certain angle but then afterwards have the Mega continue its routine. There is so much already running on the mega. Having the mega analyze the situations that the micro already does, would slow down the Mega's ability to complete the objective.
Is using an ISR still the best method after describing the inner details?
Is using an ISR still the best method after describing the inner details?
I would say not.
You can't send serial stuff in a ISR because the interrupts disabled. So I can't see an interrupt being useful.
Your code should be written as a state machine and your "interrupt" condition can be just one extra state to check and peel off a process when triggered.
Robin2:
If the Micro sends data (by serial?) to the Mega can't the Mega just react when it receives the data.
I guess the Serial.available() function can work. That had not crossed my mind.
Robin2:
You need to provide some examples of the data that the Micro will send and information about how often it needs to send that information.
The Micro is sending a set of integers. In that set, the mega will learn what direction it needs to turn and by how much. The event happens pretty irregularly. It needs to happen at the moment. So if a forward loop is running, it needs to stop immediately and turn.
Grumpy_Mike:
Your code should be written as a state machine and your "interrupt" condition can be just one extra state to check and peel off a process when triggered.
Alright. That was pretty important to know. Thank you.
heliophobicdude:
It needs to happen at the moment.
"Moment" tells us nothing about the timing. Does it need to happen in microseconds, milliseconds or in under 1 second?
How long does your loop() take to run one complete cycle?
I'd be surprised if it takes more than a few milliseconds if there are no delays in it.
Now work out how long it takes your Micro to accept and respond to the Mega's request and send all the data to it.
Serial is pretty slow.
If the data is already on the Mega, you won't have to wait for the data to come across from the Micro.
If you have enough memory on the Mega, forget the Micro.