cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best/easiest way to communicate between 2 STM32's (SPI,I2C, ...?)

HBleu.1
Associate
 
11 REPLIES 11
Paul1
Lead

Personally I would

  • Given little data, and slipring between enclosures
  • Low speed (Robust, with option for RC filters)
  • Minimum wires (Less failure points in slipring)

Use UART, 3 wires: Tx, Rx, Gnd, maybe 2400bps-115200bps (use slowest that given reasonable performance and response time). Use Checksums (CRC16 should be plenty) so that you are confident every packet is 100% correct. If you extend cable then use shielded cable connected to Gnd at only one point on either side of slipring (no need to run shield through slipring). If very short distance (<12") then you can use 3V3 or 5V level UART signals, otherwise much safer and recommended to use RS-232 drivers. You can get IC's like MAX232 that will generate their own line voltages using some small caps from a 3V3 or 5V source.

Paul's 4cent protocol analyzer (R + D):

You can also make a simple RS232 sniffer so you can watch the data flow using your PC using a FTDI cable like TTL-232R-3v3. Put a 2Kohm resistor from your Data Rx to cable's Rx, and a simple diode from Data Tx to same Rx pin on the FTDI cable. That will basically -or- the data together. Diode points from your Data Tx so it passes zeros (diode passes zeros = high/positive, RS232 line idles as 1 = low/negative on RS232).

Use a simple Terminal program like TeraTerm or Coolterm (Many more, some have font options to display 8bit data).

Paul

Paul1
Lead

UART: Ensure both sides using Resonator or Crystal for clock. Easier if same frequency on both sides. You don't have to use a standard baudrate (multiples of 300bps) as most terminal programs support custom baudrates. Try to pick a baudrate that divides evenly into your MCU clock on each side to avoid raudrate discrepancies.

Theoretically you could run a low speed clock through your slipring and PLL it up to speed, but I wouldn't.

UART depends on percentage error, so it doesn't really matter if slow or fast data, if the baudrate doesn't divide evenly into clocks on both sides you might end up with too much difference between the sides and get random data errors. Just don't do that, its really not worth the agony.

As you'll probably have other things like USB controlling you clock choice, then don't feel you need to use standard UART baudrates, really no need.

Paul