Thursday 7 August 2014

stm32 - Communication between two STMs over 2 meter with small latency


I want to send messages back and forth between two STM32s. Probably STM32F407VET6, but it would be nice if I can try already something for a simple one (STM32F103C8T6).


My requirements:



  • round trip delay time: preferably 1 ms max (excluding processing), for messages with a payload of around 8 bytes.


  • distance around 2 meters

  • speed: pure data: around 128 kbps (excluded overhead) so probably around 200 kbps


I checked between SPI and I2C, and seems that SPI is easier (to setup) and I have enough GPIO pins.


However, I read that 2 meters and fast data rate might be a problem. Also I cannot find info about the round trip delay.


Of course I can check all this myself, but it saves me a lot of effort to set this up.


For the cabling between the two STMs I am intending to use an RS232 connector (and probably cable), but if there are better alternatives, please let me know (UTP cable maybe and internet connector?). Or are there more appropriate cabling/connectors for this?


(update, link to MCP2551 according answer remark) MCP2551 adapter: adapter



Answer



The only problem with SPI you have to face is clocking speed and distance - if the clocking speed is too high then the data coming back from the slave might be too much misaligned to be able to adequately receive it. That's the short story.



So, if you transmit at 128 kbps then the clock is 128 kHz and one symbol of data is approximately 7.8 us. You then have to consider how long it takes for a data to fly down the cable and that is based approximately on 70% of the speed of light.


Light travels 1 metre in 3.33 ns and so 2 metres of cable takes about 10 ns to be received and, when the slave responds, it does so on clock edges that are 10 ns "late" compared to the master's perception of time so, there's another 10 ns to add on to the overal skew of data coming back to the master.


So, 20 ns of skew in a basic clock period of 7.8 us isn't really going to be a problem.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...