I'm using an Arduino 2560 to drive a number of 16 bit IO boards, each with a unique address. Addresses are placed on pins 14 to 21. Input is on pins 22 to 37, output on pins 38 to 53. The programming interface is an Atmel JTAGICE. Everything works fine until the program exits the sketch and returns to teh loop. The serialEventRun() function is then executed and hardware is activated that should remain dormant. There are no serial communications other that the initial
Serial.begin (9600);
I've looked at the serialEventRun code and there isn't anything there that seems to do anything other than read some buffers. Getting data onto one of these boards is a multi step process. First the data must be loaded onto the output bus, the 7 bit address set on the address line and then a 1 ms strobe pulse is sent to complete the address and upload the data to the output pins. I have tried setting a null address ( effectively shutting down all output boards) and flushing the input buffer with a loop containing a serial.read instruction, all with no success.
So this bit of code is sending out very specific instructions - setting data, addresses, and activating a strobe pulse - that I don't want.
Is there any way to intercept these commands and prevent them from messing things up? I don't want to just erase the code as it may make a buffer overflow, creating even more problems.
You don't even need to define your own main(), you can just define your own serialEventRun() in the sketch. Since it's weakly defined in the core, your definition in the sketch will override the default definition:
Thanks for the reply, but I found out what it was doing - which is rather interesting.
I was stepping through the code using F10. When I stepped past the serialEventRun line, it executed the entire sketch before pausing at the next statement (the first statement in loop), thus triggering the code I was working on. Adding some breakpoints just prior to the problem code (no brilliant insight, just a shotgun approach) let me see the problem. I figured this out around 1AM; still have to figure out a solution.