Communicating between 2 different micro controllers

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I am very new to micro controllers and electronics in general and sometimes it is very hard to find the right words for the question so decided to ask question here.



So for example my arduino controller runs at 16MHz clock speed. therefore i can set pin and high low at 16MHz (it takes 1 cycle to set pin high or low,so i assume it is 16MHz ) which produces some kind of digital output -> 00100000.



Another micro controller runs at clock speed of 13MHz. if i send digital output directly in to one of its pins it will loose some of the data. because it will not be able to read some bits that i send. so the DATA will be corrupted.



My question is, how do i get them to work as planned (1st sends 2nd reads) without corruption of the data. in other words do i need to sync them somehow, or i should use another device in middle as some kind of a buffer ? or to send data at a lower rate ?



Question number 2:



If i can send data at a lower rate from MCU#1 to MCU#2 there can simply be a phasing difference which will result in the same data corruption.



Combined question:



Can somebody direct me in to the right direction so i can learn more on that topic.










share|improve this question









New contributor




Anton Stafeyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    3
    down vote

    favorite












    I am very new to micro controllers and electronics in general and sometimes it is very hard to find the right words for the question so decided to ask question here.



    So for example my arduino controller runs at 16MHz clock speed. therefore i can set pin and high low at 16MHz (it takes 1 cycle to set pin high or low,so i assume it is 16MHz ) which produces some kind of digital output -> 00100000.



    Another micro controller runs at clock speed of 13MHz. if i send digital output directly in to one of its pins it will loose some of the data. because it will not be able to read some bits that i send. so the DATA will be corrupted.



    My question is, how do i get them to work as planned (1st sends 2nd reads) without corruption of the data. in other words do i need to sync them somehow, or i should use another device in middle as some kind of a buffer ? or to send data at a lower rate ?



    Question number 2:



    If i can send data at a lower rate from MCU#1 to MCU#2 there can simply be a phasing difference which will result in the same data corruption.



    Combined question:



    Can somebody direct me in to the right direction so i can learn more on that topic.










    share|improve this question









    New contributor




    Anton Stafeyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I am very new to micro controllers and electronics in general and sometimes it is very hard to find the right words for the question so decided to ask question here.



      So for example my arduino controller runs at 16MHz clock speed. therefore i can set pin and high low at 16MHz (it takes 1 cycle to set pin high or low,so i assume it is 16MHz ) which produces some kind of digital output -> 00100000.



      Another micro controller runs at clock speed of 13MHz. if i send digital output directly in to one of its pins it will loose some of the data. because it will not be able to read some bits that i send. so the DATA will be corrupted.



      My question is, how do i get them to work as planned (1st sends 2nd reads) without corruption of the data. in other words do i need to sync them somehow, or i should use another device in middle as some kind of a buffer ? or to send data at a lower rate ?



      Question number 2:



      If i can send data at a lower rate from MCU#1 to MCU#2 there can simply be a phasing difference which will result in the same data corruption.



      Combined question:



      Can somebody direct me in to the right direction so i can learn more on that topic.










      share|improve this question









      New contributor




      Anton Stafeyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am very new to micro controllers and electronics in general and sometimes it is very hard to find the right words for the question so decided to ask question here.



      So for example my arduino controller runs at 16MHz clock speed. therefore i can set pin and high low at 16MHz (it takes 1 cycle to set pin high or low,so i assume it is 16MHz ) which produces some kind of digital output -> 00100000.



      Another micro controller runs at clock speed of 13MHz. if i send digital output directly in to one of its pins it will loose some of the data. because it will not be able to read some bits that i send. so the DATA will be corrupted.



      My question is, how do i get them to work as planned (1st sends 2nd reads) without corruption of the data. in other words do i need to sync them somehow, or i should use another device in middle as some kind of a buffer ? or to send data at a lower rate ?



      Question number 2:



      If i can send data at a lower rate from MCU#1 to MCU#2 there can simply be a phasing difference which will result in the same data corruption.



      Combined question:



      Can somebody direct me in to the right direction so i can learn more on that topic.







      microcontroller avr communication






      share|improve this question









      New contributor




      Anton Stafeyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Anton Stafeyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 7 hours ago





















      New contributor




      Anton Stafeyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 8 hours ago









      Anton Stafeyev

      234




      234




      New contributor




      Anton Stafeyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Anton Stafeyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Anton Stafeyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          The points you make are absolutely valid. What you missing are some details that you could get by reading more on communication protocols. Here are some of them.



          1. The communication speed should always be chosen from the maximum required speed, not the one that can be achieved.

          The reason for this is that with some exceptions (transceivers, buffers etc.) the data transferred must be either obtained or processed somehow. Input from human interface certainly works in completely different time dimension. And if your controller takes several seconds to process 1 MB of data, it would be pointless to transfer it at 16 Mbps speed.



          1. Because signal-to-noise ratio decreases with distance, the maximum achievable bandwidth decreases too.

          There is term "bandwidth-distance product" often used in communication. This is another reason why direct MCU-to-MCU connections rarely use that high data rates.



          1. In modern MCUs the communication speeds are often independent from the CPU clocks.

          For example, Xmega MCUs have peripheral clocks running at 2 or even 4 times the CPU speeds. Furthermore, controllers with USB interfaces often have their own oscillators.



          1. Various communication protocols are now supported in hardware.

          Synchronous protocols like SPI (or I2C on slave side) have their clock signals coming from the different MCU. So, the hardware can use that clock to shift data to/from the buffer and only involve processor at the end of a message. More advanced MCUs with DMA support can even move the data between different peripherals or memory without involving CPU at all.



          Asynchronous protocols like UART or CAN require synchronized clocks. They begin timing at start bit and then sample the inputs once approximately at the mid-clock point (UART) or up to three times at about 75% of clock pulse (CAN). Obviously the data integrity depends on the clocking precision. While CAN controllers can adjust their clocks using phase shift information, more simpler UARTs can not.



          One common practice to achieve better UART synchronization is to use crystals with frequencies easily divisible to common serial baud rates. For example, instead of running aforementioned Xmega controllers at their maximum 32 MHz you can often see them with 14.7456 crystals, running at 29.5 MHz.



          Regardless of the protocol, the combination of hardware buffering and DMA transfers make transfer bandwidth fairly independent from CPU clocks.



          1. Finally, when communication speeds go up it is more common to see separate controller chips rather than direct connection to MCU.

          Not only that, but you can usually see parallel bus connection between MCU and high-speed transceivers like LAN or LVDS display. This is because the communication bus throughput becomes faster than can be passed in serial trough single MCU pin.



          You've mentioned Ethernet in one of your comments. You should realize that with 1 Gbps Ethernet speeds no 16 MHz MCU stands a chance of processing that avalanche of traffic. For those speeds you should be looking at much more capable hardware, like used in RPi, for example.



          By the way, this last point is just another form of point #1, i.e. if you cannot reduce data rate to something your MCU can handle, it logically follows that you need faster processor to deal with data flow.






          share|improve this answer






















          • Man thanks for the answer. that does help a lot. but as usual 1 answer creates thousand questions. and i guess few of them can be answered right on the spot. since you have said that MCU simply wont have enough speed to process the data that comes from another end, what would be a solution in general if i would like to send my sensor data to the remote server. i don't really need to receive anything back. and since it is a remote server, i would prefer HTTP as a final layer of all protocols used. or even could be UDP stream of data.
            – Anton Stafeyev
            44 mins ago











          • Well, that's easy. Any sensor has its own data acquisition rate(s). The precision often depends on this rate, so it is common to run them slower than possible to achieve better precision. On the other hand you have a server, which also has maximum data rate defined by protocol and server capability. Not only that, but the server's availability changes with load i.e. number of concurrent requests it has to process. Figure out maximum desirable data rate of a sensor and maximum available data rate of a server at maximum load. The lesser of the two would be your target data rate.
            – Maple
            31 mins ago










          • Since you've mentioned HTTP/UDP, I must point out that your entire question Is invalid. You are not just communicating between two MCUs. You are communicating over known transfer channel, which requires quite high data rates to handle protocol overhead. Regardless of the acquisition data rate your controller has to handle packet envelopes and basically entire TCP/IP stack. My advice would be to use some of the modules with built-in ethernet/wifi controllers and all required software for that. The reading of the sensor itself would be the lesser of your problems.
            – Maple
            21 mins ago











          • well thats the point. a module with wifi or ethernet talks over SPI to the MCU. and that process is rising so many questions that i want to nail every single bit going in and out :) all i was asking is the direction and you guys gave it to me:)
            – Anton Stafeyev
            10 mins ago










          • on practice i now i know that mcu wont be able to write at the speed ethernet requires, so if i would use something like micro-processor like arm cortex and implent the whole networking there. i would still need to talk over spi to my tiny mcu. so that was the seed of the question.
            – Anton Stafeyev
            5 mins ago

















          up vote
          2
          down vote













          You're quite right in your analysis of the problem, and it is of course solved.



          The solution is a serial protocol of your choice. A microcontroller will usually have one or more of the common inter-IC communication protocols:



          • UART

          • SPI

          • I2C

          UART is "clockless" so each side has to decide on a clock speed. The speed is low enough that each receiver can find the right bits and solves the "phase" problem by inserting extra bits that will always be low or high adjacent to a bit of the opposite polarity.



          SPI and I2C has a clock in addition to the data. The receiver will only act on the data when the clock changes. Usually the hardware takes care of everything. I2C has a standardized clock speed limit, while SPI has no such limit.



          Among these, SPI is arguably the easiest to implement in discrete hardware. It is essentially no more than a shift register, and it can interface directly with a number of cheap and common logic chips. There is also no lower speed limit, and jitter is not an issue since it is driven purely by the clock so it is easy to implement in software on a slow processor.






          share|improve this answer






















          • i will look at how this protocols are made and how hardware handles them. big thanks. but what if i need to communicate with a device i made my self that has no built in solutions. how would i solve phasing problems. anmd clocks
            – Anton Stafeyev
            7 hours ago










          • @AntonStafeyev I hope my recent edit to the answer helped with your question, otherwise just ask me to clarify again!
            – pipe
            6 hours ago










          • As SPI bidirectional is in reality a circular buffer, it is indeed quite simple to implement.
            – Peter Smith
            6 hours ago










          • Just make sure your clock/sample edge polarities match on the two devices.
            – isdi
            5 hours ago










          • just to make sure i am on the right track. for example i want to make a chip that will send data over tcp protocol. i will connect that chip to arduino via SPI protocol the, Ethernet device will receive data -> store it in buffer and then send packet over Ethernet to a pc for example. this is my short term goal for now.
            – Anton Stafeyev
            5 hours ago










          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("schematics", function ()
          StackExchange.schematics.init();
          );
          , "cicuitlab");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "135"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Anton Stafeyev is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f402400%2fcommunicating-between-2-different-micro-controllers%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          The points you make are absolutely valid. What you missing are some details that you could get by reading more on communication protocols. Here are some of them.



          1. The communication speed should always be chosen from the maximum required speed, not the one that can be achieved.

          The reason for this is that with some exceptions (transceivers, buffers etc.) the data transferred must be either obtained or processed somehow. Input from human interface certainly works in completely different time dimension. And if your controller takes several seconds to process 1 MB of data, it would be pointless to transfer it at 16 Mbps speed.



          1. Because signal-to-noise ratio decreases with distance, the maximum achievable bandwidth decreases too.

          There is term "bandwidth-distance product" often used in communication. This is another reason why direct MCU-to-MCU connections rarely use that high data rates.



          1. In modern MCUs the communication speeds are often independent from the CPU clocks.

          For example, Xmega MCUs have peripheral clocks running at 2 or even 4 times the CPU speeds. Furthermore, controllers with USB interfaces often have their own oscillators.



          1. Various communication protocols are now supported in hardware.

          Synchronous protocols like SPI (or I2C on slave side) have their clock signals coming from the different MCU. So, the hardware can use that clock to shift data to/from the buffer and only involve processor at the end of a message. More advanced MCUs with DMA support can even move the data between different peripherals or memory without involving CPU at all.



          Asynchronous protocols like UART or CAN require synchronized clocks. They begin timing at start bit and then sample the inputs once approximately at the mid-clock point (UART) or up to three times at about 75% of clock pulse (CAN). Obviously the data integrity depends on the clocking precision. While CAN controllers can adjust their clocks using phase shift information, more simpler UARTs can not.



          One common practice to achieve better UART synchronization is to use crystals with frequencies easily divisible to common serial baud rates. For example, instead of running aforementioned Xmega controllers at their maximum 32 MHz you can often see them with 14.7456 crystals, running at 29.5 MHz.



          Regardless of the protocol, the combination of hardware buffering and DMA transfers make transfer bandwidth fairly independent from CPU clocks.



          1. Finally, when communication speeds go up it is more common to see separate controller chips rather than direct connection to MCU.

          Not only that, but you can usually see parallel bus connection between MCU and high-speed transceivers like LAN or LVDS display. This is because the communication bus throughput becomes faster than can be passed in serial trough single MCU pin.



          You've mentioned Ethernet in one of your comments. You should realize that with 1 Gbps Ethernet speeds no 16 MHz MCU stands a chance of processing that avalanche of traffic. For those speeds you should be looking at much more capable hardware, like used in RPi, for example.



          By the way, this last point is just another form of point #1, i.e. if you cannot reduce data rate to something your MCU can handle, it logically follows that you need faster processor to deal with data flow.






          share|improve this answer






















          • Man thanks for the answer. that does help a lot. but as usual 1 answer creates thousand questions. and i guess few of them can be answered right on the spot. since you have said that MCU simply wont have enough speed to process the data that comes from another end, what would be a solution in general if i would like to send my sensor data to the remote server. i don't really need to receive anything back. and since it is a remote server, i would prefer HTTP as a final layer of all protocols used. or even could be UDP stream of data.
            – Anton Stafeyev
            44 mins ago











          • Well, that's easy. Any sensor has its own data acquisition rate(s). The precision often depends on this rate, so it is common to run them slower than possible to achieve better precision. On the other hand you have a server, which also has maximum data rate defined by protocol and server capability. Not only that, but the server's availability changes with load i.e. number of concurrent requests it has to process. Figure out maximum desirable data rate of a sensor and maximum available data rate of a server at maximum load. The lesser of the two would be your target data rate.
            – Maple
            31 mins ago










          • Since you've mentioned HTTP/UDP, I must point out that your entire question Is invalid. You are not just communicating between two MCUs. You are communicating over known transfer channel, which requires quite high data rates to handle protocol overhead. Regardless of the acquisition data rate your controller has to handle packet envelopes and basically entire TCP/IP stack. My advice would be to use some of the modules with built-in ethernet/wifi controllers and all required software for that. The reading of the sensor itself would be the lesser of your problems.
            – Maple
            21 mins ago











          • well thats the point. a module with wifi or ethernet talks over SPI to the MCU. and that process is rising so many questions that i want to nail every single bit going in and out :) all i was asking is the direction and you guys gave it to me:)
            – Anton Stafeyev
            10 mins ago










          • on practice i now i know that mcu wont be able to write at the speed ethernet requires, so if i would use something like micro-processor like arm cortex and implent the whole networking there. i would still need to talk over spi to my tiny mcu. so that was the seed of the question.
            – Anton Stafeyev
            5 mins ago














          up vote
          2
          down vote



          accepted










          The points you make are absolutely valid. What you missing are some details that you could get by reading more on communication protocols. Here are some of them.



          1. The communication speed should always be chosen from the maximum required speed, not the one that can be achieved.

          The reason for this is that with some exceptions (transceivers, buffers etc.) the data transferred must be either obtained or processed somehow. Input from human interface certainly works in completely different time dimension. And if your controller takes several seconds to process 1 MB of data, it would be pointless to transfer it at 16 Mbps speed.



          1. Because signal-to-noise ratio decreases with distance, the maximum achievable bandwidth decreases too.

          There is term "bandwidth-distance product" often used in communication. This is another reason why direct MCU-to-MCU connections rarely use that high data rates.



          1. In modern MCUs the communication speeds are often independent from the CPU clocks.

          For example, Xmega MCUs have peripheral clocks running at 2 or even 4 times the CPU speeds. Furthermore, controllers with USB interfaces often have their own oscillators.



          1. Various communication protocols are now supported in hardware.

          Synchronous protocols like SPI (or I2C on slave side) have their clock signals coming from the different MCU. So, the hardware can use that clock to shift data to/from the buffer and only involve processor at the end of a message. More advanced MCUs with DMA support can even move the data between different peripherals or memory without involving CPU at all.



          Asynchronous protocols like UART or CAN require synchronized clocks. They begin timing at start bit and then sample the inputs once approximately at the mid-clock point (UART) or up to three times at about 75% of clock pulse (CAN). Obviously the data integrity depends on the clocking precision. While CAN controllers can adjust their clocks using phase shift information, more simpler UARTs can not.



          One common practice to achieve better UART synchronization is to use crystals with frequencies easily divisible to common serial baud rates. For example, instead of running aforementioned Xmega controllers at their maximum 32 MHz you can often see them with 14.7456 crystals, running at 29.5 MHz.



          Regardless of the protocol, the combination of hardware buffering and DMA transfers make transfer bandwidth fairly independent from CPU clocks.



          1. Finally, when communication speeds go up it is more common to see separate controller chips rather than direct connection to MCU.

          Not only that, but you can usually see parallel bus connection between MCU and high-speed transceivers like LAN or LVDS display. This is because the communication bus throughput becomes faster than can be passed in serial trough single MCU pin.



          You've mentioned Ethernet in one of your comments. You should realize that with 1 Gbps Ethernet speeds no 16 MHz MCU stands a chance of processing that avalanche of traffic. For those speeds you should be looking at much more capable hardware, like used in RPi, for example.



          By the way, this last point is just another form of point #1, i.e. if you cannot reduce data rate to something your MCU can handle, it logically follows that you need faster processor to deal with data flow.






          share|improve this answer






















          • Man thanks for the answer. that does help a lot. but as usual 1 answer creates thousand questions. and i guess few of them can be answered right on the spot. since you have said that MCU simply wont have enough speed to process the data that comes from another end, what would be a solution in general if i would like to send my sensor data to the remote server. i don't really need to receive anything back. and since it is a remote server, i would prefer HTTP as a final layer of all protocols used. or even could be UDP stream of data.
            – Anton Stafeyev
            44 mins ago











          • Well, that's easy. Any sensor has its own data acquisition rate(s). The precision often depends on this rate, so it is common to run them slower than possible to achieve better precision. On the other hand you have a server, which also has maximum data rate defined by protocol and server capability. Not only that, but the server's availability changes with load i.e. number of concurrent requests it has to process. Figure out maximum desirable data rate of a sensor and maximum available data rate of a server at maximum load. The lesser of the two would be your target data rate.
            – Maple
            31 mins ago










          • Since you've mentioned HTTP/UDP, I must point out that your entire question Is invalid. You are not just communicating between two MCUs. You are communicating over known transfer channel, which requires quite high data rates to handle protocol overhead. Regardless of the acquisition data rate your controller has to handle packet envelopes and basically entire TCP/IP stack. My advice would be to use some of the modules with built-in ethernet/wifi controllers and all required software for that. The reading of the sensor itself would be the lesser of your problems.
            – Maple
            21 mins ago











          • well thats the point. a module with wifi or ethernet talks over SPI to the MCU. and that process is rising so many questions that i want to nail every single bit going in and out :) all i was asking is the direction and you guys gave it to me:)
            – Anton Stafeyev
            10 mins ago










          • on practice i now i know that mcu wont be able to write at the speed ethernet requires, so if i would use something like micro-processor like arm cortex and implent the whole networking there. i would still need to talk over spi to my tiny mcu. so that was the seed of the question.
            – Anton Stafeyev
            5 mins ago












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          The points you make are absolutely valid. What you missing are some details that you could get by reading more on communication protocols. Here are some of them.



          1. The communication speed should always be chosen from the maximum required speed, not the one that can be achieved.

          The reason for this is that with some exceptions (transceivers, buffers etc.) the data transferred must be either obtained or processed somehow. Input from human interface certainly works in completely different time dimension. And if your controller takes several seconds to process 1 MB of data, it would be pointless to transfer it at 16 Mbps speed.



          1. Because signal-to-noise ratio decreases with distance, the maximum achievable bandwidth decreases too.

          There is term "bandwidth-distance product" often used in communication. This is another reason why direct MCU-to-MCU connections rarely use that high data rates.



          1. In modern MCUs the communication speeds are often independent from the CPU clocks.

          For example, Xmega MCUs have peripheral clocks running at 2 or even 4 times the CPU speeds. Furthermore, controllers with USB interfaces often have their own oscillators.



          1. Various communication protocols are now supported in hardware.

          Synchronous protocols like SPI (or I2C on slave side) have their clock signals coming from the different MCU. So, the hardware can use that clock to shift data to/from the buffer and only involve processor at the end of a message. More advanced MCUs with DMA support can even move the data between different peripherals or memory without involving CPU at all.



          Asynchronous protocols like UART or CAN require synchronized clocks. They begin timing at start bit and then sample the inputs once approximately at the mid-clock point (UART) or up to three times at about 75% of clock pulse (CAN). Obviously the data integrity depends on the clocking precision. While CAN controllers can adjust their clocks using phase shift information, more simpler UARTs can not.



          One common practice to achieve better UART synchronization is to use crystals with frequencies easily divisible to common serial baud rates. For example, instead of running aforementioned Xmega controllers at their maximum 32 MHz you can often see them with 14.7456 crystals, running at 29.5 MHz.



          Regardless of the protocol, the combination of hardware buffering and DMA transfers make transfer bandwidth fairly independent from CPU clocks.



          1. Finally, when communication speeds go up it is more common to see separate controller chips rather than direct connection to MCU.

          Not only that, but you can usually see parallel bus connection between MCU and high-speed transceivers like LAN or LVDS display. This is because the communication bus throughput becomes faster than can be passed in serial trough single MCU pin.



          You've mentioned Ethernet in one of your comments. You should realize that with 1 Gbps Ethernet speeds no 16 MHz MCU stands a chance of processing that avalanche of traffic. For those speeds you should be looking at much more capable hardware, like used in RPi, for example.



          By the way, this last point is just another form of point #1, i.e. if you cannot reduce data rate to something your MCU can handle, it logically follows that you need faster processor to deal with data flow.






          share|improve this answer














          The points you make are absolutely valid. What you missing are some details that you could get by reading more on communication protocols. Here are some of them.



          1. The communication speed should always be chosen from the maximum required speed, not the one that can be achieved.

          The reason for this is that with some exceptions (transceivers, buffers etc.) the data transferred must be either obtained or processed somehow. Input from human interface certainly works in completely different time dimension. And if your controller takes several seconds to process 1 MB of data, it would be pointless to transfer it at 16 Mbps speed.



          1. Because signal-to-noise ratio decreases with distance, the maximum achievable bandwidth decreases too.

          There is term "bandwidth-distance product" often used in communication. This is another reason why direct MCU-to-MCU connections rarely use that high data rates.



          1. In modern MCUs the communication speeds are often independent from the CPU clocks.

          For example, Xmega MCUs have peripheral clocks running at 2 or even 4 times the CPU speeds. Furthermore, controllers with USB interfaces often have their own oscillators.



          1. Various communication protocols are now supported in hardware.

          Synchronous protocols like SPI (or I2C on slave side) have their clock signals coming from the different MCU. So, the hardware can use that clock to shift data to/from the buffer and only involve processor at the end of a message. More advanced MCUs with DMA support can even move the data between different peripherals or memory without involving CPU at all.



          Asynchronous protocols like UART or CAN require synchronized clocks. They begin timing at start bit and then sample the inputs once approximately at the mid-clock point (UART) or up to three times at about 75% of clock pulse (CAN). Obviously the data integrity depends on the clocking precision. While CAN controllers can adjust their clocks using phase shift information, more simpler UARTs can not.



          One common practice to achieve better UART synchronization is to use crystals with frequencies easily divisible to common serial baud rates. For example, instead of running aforementioned Xmega controllers at their maximum 32 MHz you can often see them with 14.7456 crystals, running at 29.5 MHz.



          Regardless of the protocol, the combination of hardware buffering and DMA transfers make transfer bandwidth fairly independent from CPU clocks.



          1. Finally, when communication speeds go up it is more common to see separate controller chips rather than direct connection to MCU.

          Not only that, but you can usually see parallel bus connection between MCU and high-speed transceivers like LAN or LVDS display. This is because the communication bus throughput becomes faster than can be passed in serial trough single MCU pin.



          You've mentioned Ethernet in one of your comments. You should realize that with 1 Gbps Ethernet speeds no 16 MHz MCU stands a chance of processing that avalanche of traffic. For those speeds you should be looking at much more capable hardware, like used in RPi, for example.



          By the way, this last point is just another form of point #1, i.e. if you cannot reduce data rate to something your MCU can handle, it logically follows that you need faster processor to deal with data flow.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 1 hour ago

























          answered 1 hour ago









          Maple

          4,3602223




          4,3602223











          • Man thanks for the answer. that does help a lot. but as usual 1 answer creates thousand questions. and i guess few of them can be answered right on the spot. since you have said that MCU simply wont have enough speed to process the data that comes from another end, what would be a solution in general if i would like to send my sensor data to the remote server. i don't really need to receive anything back. and since it is a remote server, i would prefer HTTP as a final layer of all protocols used. or even could be UDP stream of data.
            – Anton Stafeyev
            44 mins ago











          • Well, that's easy. Any sensor has its own data acquisition rate(s). The precision often depends on this rate, so it is common to run them slower than possible to achieve better precision. On the other hand you have a server, which also has maximum data rate defined by protocol and server capability. Not only that, but the server's availability changes with load i.e. number of concurrent requests it has to process. Figure out maximum desirable data rate of a sensor and maximum available data rate of a server at maximum load. The lesser of the two would be your target data rate.
            – Maple
            31 mins ago










          • Since you've mentioned HTTP/UDP, I must point out that your entire question Is invalid. You are not just communicating between two MCUs. You are communicating over known transfer channel, which requires quite high data rates to handle protocol overhead. Regardless of the acquisition data rate your controller has to handle packet envelopes and basically entire TCP/IP stack. My advice would be to use some of the modules with built-in ethernet/wifi controllers and all required software for that. The reading of the sensor itself would be the lesser of your problems.
            – Maple
            21 mins ago











          • well thats the point. a module with wifi or ethernet talks over SPI to the MCU. and that process is rising so many questions that i want to nail every single bit going in and out :) all i was asking is the direction and you guys gave it to me:)
            – Anton Stafeyev
            10 mins ago










          • on practice i now i know that mcu wont be able to write at the speed ethernet requires, so if i would use something like micro-processor like arm cortex and implent the whole networking there. i would still need to talk over spi to my tiny mcu. so that was the seed of the question.
            – Anton Stafeyev
            5 mins ago
















          • Man thanks for the answer. that does help a lot. but as usual 1 answer creates thousand questions. and i guess few of them can be answered right on the spot. since you have said that MCU simply wont have enough speed to process the data that comes from another end, what would be a solution in general if i would like to send my sensor data to the remote server. i don't really need to receive anything back. and since it is a remote server, i would prefer HTTP as a final layer of all protocols used. or even could be UDP stream of data.
            – Anton Stafeyev
            44 mins ago











          • Well, that's easy. Any sensor has its own data acquisition rate(s). The precision often depends on this rate, so it is common to run them slower than possible to achieve better precision. On the other hand you have a server, which also has maximum data rate defined by protocol and server capability. Not only that, but the server's availability changes with load i.e. number of concurrent requests it has to process. Figure out maximum desirable data rate of a sensor and maximum available data rate of a server at maximum load. The lesser of the two would be your target data rate.
            – Maple
            31 mins ago










          • Since you've mentioned HTTP/UDP, I must point out that your entire question Is invalid. You are not just communicating between two MCUs. You are communicating over known transfer channel, which requires quite high data rates to handle protocol overhead. Regardless of the acquisition data rate your controller has to handle packet envelopes and basically entire TCP/IP stack. My advice would be to use some of the modules with built-in ethernet/wifi controllers and all required software for that. The reading of the sensor itself would be the lesser of your problems.
            – Maple
            21 mins ago











          • well thats the point. a module with wifi or ethernet talks over SPI to the MCU. and that process is rising so many questions that i want to nail every single bit going in and out :) all i was asking is the direction and you guys gave it to me:)
            – Anton Stafeyev
            10 mins ago










          • on practice i now i know that mcu wont be able to write at the speed ethernet requires, so if i would use something like micro-processor like arm cortex and implent the whole networking there. i would still need to talk over spi to my tiny mcu. so that was the seed of the question.
            – Anton Stafeyev
            5 mins ago















          Man thanks for the answer. that does help a lot. but as usual 1 answer creates thousand questions. and i guess few of them can be answered right on the spot. since you have said that MCU simply wont have enough speed to process the data that comes from another end, what would be a solution in general if i would like to send my sensor data to the remote server. i don't really need to receive anything back. and since it is a remote server, i would prefer HTTP as a final layer of all protocols used. or even could be UDP stream of data.
          – Anton Stafeyev
          44 mins ago





          Man thanks for the answer. that does help a lot. but as usual 1 answer creates thousand questions. and i guess few of them can be answered right on the spot. since you have said that MCU simply wont have enough speed to process the data that comes from another end, what would be a solution in general if i would like to send my sensor data to the remote server. i don't really need to receive anything back. and since it is a remote server, i would prefer HTTP as a final layer of all protocols used. or even could be UDP stream of data.
          – Anton Stafeyev
          44 mins ago













          Well, that's easy. Any sensor has its own data acquisition rate(s). The precision often depends on this rate, so it is common to run them slower than possible to achieve better precision. On the other hand you have a server, which also has maximum data rate defined by protocol and server capability. Not only that, but the server's availability changes with load i.e. number of concurrent requests it has to process. Figure out maximum desirable data rate of a sensor and maximum available data rate of a server at maximum load. The lesser of the two would be your target data rate.
          – Maple
          31 mins ago




          Well, that's easy. Any sensor has its own data acquisition rate(s). The precision often depends on this rate, so it is common to run them slower than possible to achieve better precision. On the other hand you have a server, which also has maximum data rate defined by protocol and server capability. Not only that, but the server's availability changes with load i.e. number of concurrent requests it has to process. Figure out maximum desirable data rate of a sensor and maximum available data rate of a server at maximum load. The lesser of the two would be your target data rate.
          – Maple
          31 mins ago












          Since you've mentioned HTTP/UDP, I must point out that your entire question Is invalid. You are not just communicating between two MCUs. You are communicating over known transfer channel, which requires quite high data rates to handle protocol overhead. Regardless of the acquisition data rate your controller has to handle packet envelopes and basically entire TCP/IP stack. My advice would be to use some of the modules with built-in ethernet/wifi controllers and all required software for that. The reading of the sensor itself would be the lesser of your problems.
          – Maple
          21 mins ago





          Since you've mentioned HTTP/UDP, I must point out that your entire question Is invalid. You are not just communicating between two MCUs. You are communicating over known transfer channel, which requires quite high data rates to handle protocol overhead. Regardless of the acquisition data rate your controller has to handle packet envelopes and basically entire TCP/IP stack. My advice would be to use some of the modules with built-in ethernet/wifi controllers and all required software for that. The reading of the sensor itself would be the lesser of your problems.
          – Maple
          21 mins ago













          well thats the point. a module with wifi or ethernet talks over SPI to the MCU. and that process is rising so many questions that i want to nail every single bit going in and out :) all i was asking is the direction and you guys gave it to me:)
          – Anton Stafeyev
          10 mins ago




          well thats the point. a module with wifi or ethernet talks over SPI to the MCU. and that process is rising so many questions that i want to nail every single bit going in and out :) all i was asking is the direction and you guys gave it to me:)
          – Anton Stafeyev
          10 mins ago












          on practice i now i know that mcu wont be able to write at the speed ethernet requires, so if i would use something like micro-processor like arm cortex and implent the whole networking there. i would still need to talk over spi to my tiny mcu. so that was the seed of the question.
          – Anton Stafeyev
          5 mins ago




          on practice i now i know that mcu wont be able to write at the speed ethernet requires, so if i would use something like micro-processor like arm cortex and implent the whole networking there. i would still need to talk over spi to my tiny mcu. so that was the seed of the question.
          – Anton Stafeyev
          5 mins ago












          up vote
          2
          down vote













          You're quite right in your analysis of the problem, and it is of course solved.



          The solution is a serial protocol of your choice. A microcontroller will usually have one or more of the common inter-IC communication protocols:



          • UART

          • SPI

          • I2C

          UART is "clockless" so each side has to decide on a clock speed. The speed is low enough that each receiver can find the right bits and solves the "phase" problem by inserting extra bits that will always be low or high adjacent to a bit of the opposite polarity.



          SPI and I2C has a clock in addition to the data. The receiver will only act on the data when the clock changes. Usually the hardware takes care of everything. I2C has a standardized clock speed limit, while SPI has no such limit.



          Among these, SPI is arguably the easiest to implement in discrete hardware. It is essentially no more than a shift register, and it can interface directly with a number of cheap and common logic chips. There is also no lower speed limit, and jitter is not an issue since it is driven purely by the clock so it is easy to implement in software on a slow processor.






          share|improve this answer






















          • i will look at how this protocols are made and how hardware handles them. big thanks. but what if i need to communicate with a device i made my self that has no built in solutions. how would i solve phasing problems. anmd clocks
            – Anton Stafeyev
            7 hours ago










          • @AntonStafeyev I hope my recent edit to the answer helped with your question, otherwise just ask me to clarify again!
            – pipe
            6 hours ago










          • As SPI bidirectional is in reality a circular buffer, it is indeed quite simple to implement.
            – Peter Smith
            6 hours ago










          • Just make sure your clock/sample edge polarities match on the two devices.
            – isdi
            5 hours ago










          • just to make sure i am on the right track. for example i want to make a chip that will send data over tcp protocol. i will connect that chip to arduino via SPI protocol the, Ethernet device will receive data -> store it in buffer and then send packet over Ethernet to a pc for example. this is my short term goal for now.
            – Anton Stafeyev
            5 hours ago














          up vote
          2
          down vote













          You're quite right in your analysis of the problem, and it is of course solved.



          The solution is a serial protocol of your choice. A microcontroller will usually have one or more of the common inter-IC communication protocols:



          • UART

          • SPI

          • I2C

          UART is "clockless" so each side has to decide on a clock speed. The speed is low enough that each receiver can find the right bits and solves the "phase" problem by inserting extra bits that will always be low or high adjacent to a bit of the opposite polarity.



          SPI and I2C has a clock in addition to the data. The receiver will only act on the data when the clock changes. Usually the hardware takes care of everything. I2C has a standardized clock speed limit, while SPI has no such limit.



          Among these, SPI is arguably the easiest to implement in discrete hardware. It is essentially no more than a shift register, and it can interface directly with a number of cheap and common logic chips. There is also no lower speed limit, and jitter is not an issue since it is driven purely by the clock so it is easy to implement in software on a slow processor.






          share|improve this answer






















          • i will look at how this protocols are made and how hardware handles them. big thanks. but what if i need to communicate with a device i made my self that has no built in solutions. how would i solve phasing problems. anmd clocks
            – Anton Stafeyev
            7 hours ago










          • @AntonStafeyev I hope my recent edit to the answer helped with your question, otherwise just ask me to clarify again!
            – pipe
            6 hours ago










          • As SPI bidirectional is in reality a circular buffer, it is indeed quite simple to implement.
            – Peter Smith
            6 hours ago










          • Just make sure your clock/sample edge polarities match on the two devices.
            – isdi
            5 hours ago










          • just to make sure i am on the right track. for example i want to make a chip that will send data over tcp protocol. i will connect that chip to arduino via SPI protocol the, Ethernet device will receive data -> store it in buffer and then send packet over Ethernet to a pc for example. this is my short term goal for now.
            – Anton Stafeyev
            5 hours ago












          up vote
          2
          down vote










          up vote
          2
          down vote









          You're quite right in your analysis of the problem, and it is of course solved.



          The solution is a serial protocol of your choice. A microcontroller will usually have one or more of the common inter-IC communication protocols:



          • UART

          • SPI

          • I2C

          UART is "clockless" so each side has to decide on a clock speed. The speed is low enough that each receiver can find the right bits and solves the "phase" problem by inserting extra bits that will always be low or high adjacent to a bit of the opposite polarity.



          SPI and I2C has a clock in addition to the data. The receiver will only act on the data when the clock changes. Usually the hardware takes care of everything. I2C has a standardized clock speed limit, while SPI has no such limit.



          Among these, SPI is arguably the easiest to implement in discrete hardware. It is essentially no more than a shift register, and it can interface directly with a number of cheap and common logic chips. There is also no lower speed limit, and jitter is not an issue since it is driven purely by the clock so it is easy to implement in software on a slow processor.






          share|improve this answer














          You're quite right in your analysis of the problem, and it is of course solved.



          The solution is a serial protocol of your choice. A microcontroller will usually have one or more of the common inter-IC communication protocols:



          • UART

          • SPI

          • I2C

          UART is "clockless" so each side has to decide on a clock speed. The speed is low enough that each receiver can find the right bits and solves the "phase" problem by inserting extra bits that will always be low or high adjacent to a bit of the opposite polarity.



          SPI and I2C has a clock in addition to the data. The receiver will only act on the data when the clock changes. Usually the hardware takes care of everything. I2C has a standardized clock speed limit, while SPI has no such limit.



          Among these, SPI is arguably the easiest to implement in discrete hardware. It is essentially no more than a shift register, and it can interface directly with a number of cheap and common logic chips. There is also no lower speed limit, and jitter is not an issue since it is driven purely by the clock so it is easy to implement in software on a slow processor.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 6 hours ago

























          answered 7 hours ago









          pipe

          9,26931951




          9,26931951











          • i will look at how this protocols are made and how hardware handles them. big thanks. but what if i need to communicate with a device i made my self that has no built in solutions. how would i solve phasing problems. anmd clocks
            – Anton Stafeyev
            7 hours ago










          • @AntonStafeyev I hope my recent edit to the answer helped with your question, otherwise just ask me to clarify again!
            – pipe
            6 hours ago










          • As SPI bidirectional is in reality a circular buffer, it is indeed quite simple to implement.
            – Peter Smith
            6 hours ago










          • Just make sure your clock/sample edge polarities match on the two devices.
            – isdi
            5 hours ago










          • just to make sure i am on the right track. for example i want to make a chip that will send data over tcp protocol. i will connect that chip to arduino via SPI protocol the, Ethernet device will receive data -> store it in buffer and then send packet over Ethernet to a pc for example. this is my short term goal for now.
            – Anton Stafeyev
            5 hours ago
















          • i will look at how this protocols are made and how hardware handles them. big thanks. but what if i need to communicate with a device i made my self that has no built in solutions. how would i solve phasing problems. anmd clocks
            – Anton Stafeyev
            7 hours ago










          • @AntonStafeyev I hope my recent edit to the answer helped with your question, otherwise just ask me to clarify again!
            – pipe
            6 hours ago










          • As SPI bidirectional is in reality a circular buffer, it is indeed quite simple to implement.
            – Peter Smith
            6 hours ago










          • Just make sure your clock/sample edge polarities match on the two devices.
            – isdi
            5 hours ago










          • just to make sure i am on the right track. for example i want to make a chip that will send data over tcp protocol. i will connect that chip to arduino via SPI protocol the, Ethernet device will receive data -> store it in buffer and then send packet over Ethernet to a pc for example. this is my short term goal for now.
            – Anton Stafeyev
            5 hours ago















          i will look at how this protocols are made and how hardware handles them. big thanks. but what if i need to communicate with a device i made my self that has no built in solutions. how would i solve phasing problems. anmd clocks
          – Anton Stafeyev
          7 hours ago




          i will look at how this protocols are made and how hardware handles them. big thanks. but what if i need to communicate with a device i made my self that has no built in solutions. how would i solve phasing problems. anmd clocks
          – Anton Stafeyev
          7 hours ago












          @AntonStafeyev I hope my recent edit to the answer helped with your question, otherwise just ask me to clarify again!
          – pipe
          6 hours ago




          @AntonStafeyev I hope my recent edit to the answer helped with your question, otherwise just ask me to clarify again!
          – pipe
          6 hours ago












          As SPI bidirectional is in reality a circular buffer, it is indeed quite simple to implement.
          – Peter Smith
          6 hours ago




          As SPI bidirectional is in reality a circular buffer, it is indeed quite simple to implement.
          – Peter Smith
          6 hours ago












          Just make sure your clock/sample edge polarities match on the two devices.
          – isdi
          5 hours ago




          Just make sure your clock/sample edge polarities match on the two devices.
          – isdi
          5 hours ago












          just to make sure i am on the right track. for example i want to make a chip that will send data over tcp protocol. i will connect that chip to arduino via SPI protocol the, Ethernet device will receive data -> store it in buffer and then send packet over Ethernet to a pc for example. this is my short term goal for now.
          – Anton Stafeyev
          5 hours ago




          just to make sure i am on the right track. for example i want to make a chip that will send data over tcp protocol. i will connect that chip to arduino via SPI protocol the, Ethernet device will receive data -> store it in buffer and then send packet over Ethernet to a pc for example. this is my short term goal for now.
          – Anton Stafeyev
          5 hours ago










          Anton Stafeyev is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          Anton Stafeyev is a new contributor. Be nice, and check out our Code of Conduct.












          Anton Stafeyev is a new contributor. Be nice, and check out our Code of Conduct.











          Anton Stafeyev is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f402400%2fcommunicating-between-2-different-micro-controllers%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery