Hi, I’m happy to finally have something to contribute.
Some background first. When I settled on a Blinks project to start, I dove straight in and started coding the project’s systems. Once I was further along, I decided to get tiles talking to one another.
Hooboy did that trip me up. I knew I needed something more involved than the simple “values on faces”. So I started playing with datagrams. Slippery little beasts, let me tell you. I had some success passing data between tiles, but corner cases became a real issue. I had the dreaded red blink of a failed communication, and without a way to set breakpoints and step through code I was getting frustrated with my slow progress. Also, coding around corner cases was costing me precious code & data space.
Eventually I knew I had to tackle this communications hurdle independently before I could include it in my project. I created a new project and settled on a more simplified communications protocol. I finally got it working and wanted to share in case others are interested.
My protocol builds on the standard “value on face”, which is a more reliable way to send data. It uses four of the six bits as payload and the other two bits to handshake between the tiles.
It works like this. Tile A sends data in [3:0] and sets “toggle” bit=1. When Tile B sees this, it saves the data, and sets its “ack” bit=1. When Tile A sees that Tile B’s ack bit equals its own toggle bit, it knows it can send the next payload. Tile A then sends new data in [3:0] and sets its toggle bit=0. When Tile B sees the toggle bit change, it knows there is new data, captures and processes it, and sets its ack bit back to zero. This continues as long as there is more data to send.
I am treating these successive pairs of 4-bit values as command+data, but you could actually treat them independently, as a single 8-bit value, or whatever.
The key feature is the handshake between the toggle and ack bits that lets tiles know when it is safe to send a new piece of data. It turns the “value on face” interface from a simple “here’s my state” to something that the tiles can use to more easily talk to one another (query+response).
One of my goals was to make something simple (fewer corner cases) with a small footprint on both code and variables. I’m going to need all the space I can eke out once I get back to my main project.
Here’s the code. I welcome input!