Xwire: Programming
Case 1: Interconnecting 2 or more controllers
Programming several SPLat controllers to exchange data via Xwire is extremely simple. It consists of the following steps:
- Decide which is to be the master. There can only be one master. The master can talk to all slaves but slaves cannot talk directly to each other.
- Arrange for the data you want to exchange to be in contiguous Tx and Rx blocks in RAM. Use
mEQUdirectives to define absolute RAM addresses. You can also use usedefXXX(defBYTE,defFLOAT) etc. providing you also usedefBLOCKto ensure you get contiguous areas of memory. - Set Xwire addressing in your slave board(s). Your SPLatWare program must usually do this (though hardware jumpers may also be involved). In some cases the Firmware loaded into the board may also come into the equation. Refer to the Xwire documentation for the board you are using.
- Create Xwire configuration tables in NVEM0. These tell each slave board where its Tx and Rx RAM blocks are located. In the master they also tell it which slaves (addresses) to expect.
- In the initialisation code of your programs, invoke the Xwire configuration table.
Case 2: Xwire peripheral board(s) connected to a master controller
We make a number of boards that we call Xwire peripherals. Some have quite sophisticated functionality in their own right, and work as semi-autonomous subsystems. An Xwire peripheral is always a slave, but we have pre-programmed it to do its job.
- Study the Xwire peripheral’s product documentation to learn how its Xwire address is set and how its Tx and Rx data is structured.
- Arrange for the data you want to exchange to be in contiguous Tx and Rx blocks in RAM in the master controller (all that is taken care of automatically for the Xwire peripheral). Use
mEQUdirectives to define absolute RAM addresses. You can also use usedefXXX(defBYTE,defFLOAT) etc. providing you also usedefBLOCKto ensure you get contiguous areas of memory. - Set Xwire addressing in your peripheral board(s). Refer to the Xwire documentation for the boards you are using.
- Create Xwire configuration tables in NVEM0. These tell each slave board where its Tx and Rx RAM blocks are located. In the master they also tell it which slaves (addresses) to expect.
- In the initialisation code of your master program, invoke the Xwire configuration table.
| Hint: It is always a good idea with an Xwire hookup to start with a very basic connection, with the minimum amount of programming, to show it is working. For example, with a thermocouple Xwire board SX10500, make a very basic program that just displays the temperature on the LCD, if you have one, or stores in RAM for readout via SPLatLink (The SL button in SPLat/PC’s Module window) if you don’t have an LCD. Do this as a small test program, with no other functionality. If you are using multiple Xwire slaves, do it separately for each one, and only when you have them all tamed start combining them. One of the biggest sources of problems is when people try to get too may things working all at the same time. Do it one thing at a time. Divide and conquer. |