debugging

After my decent failure getting boards to talk to each other over a serial bus, I had a lot of debugging to do.

I knew this wasn't a problem with the boards speaking serial improperly - here I scoped the serial signal on MISO (blue) as well as the serial signal from the master board to my laptop (yellow). Here, the master board simply read the value of MISO and echoed that digital signal to the serial pin, and the proper message made it to my laptop from the slave board.

(ignore that the signals are inverse from each other - I forgot to turn off this setting on the scope)

But, after having the master board try to read and then echo the character it read, the results looked more like this...

It seemed like a timing error, so I checked for clock drift between microctrollers, verified they had the same serial code, etc. But to no avail

Turns out, my 20MHz boards couldn't operate at a baud rate of 115,200... After lowering the baud rate to 19,200, everything worked swimmingly. So, I carried on getting them to do something!

To reiterate, the communication protocol begins with slave boards listening to MOSI and nobody connected to MISO. When a slave board hears its address on MOSI, it connects to MISO and sends its information. The master board shouldn't ask for more information on MOSI until it hears back a response on MISO.

When programming, I ran into a few major problems:

• If a slave board is busy computing when its name comes MOSI serial, it will miss its name and never transmit. So, I made the slave boards only compute when they know it's their turn to talk. When they're not computing, they simply wait for their name on MOSI. I'll wait to see if this makes the delay too heinous when there are more boards and more touchpads, but for now it works fine!

• If the slave board misses hearing it's name, the master board will never hear a response because it will never be sent! So, I have a timer on the master board that interrupts the master board while it listens for a response that won't come.

Here is a demo of all three microcontrollers talking together! When a touchpad is touched on one board, it blinks. When the same touchpad is touched on both boards, it stays solid.

This is the foundation of turning the state of touches into midi notes!

My now-functioning code can be found here.