This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

transmitting data from microcontroller tm4c123GH6PM to another microcontroller

Other Parts Discussed in Thread: TM4C123GH6PM

I  am using Tiva C Series TM4C123GH6PM with Code Composer Studio for transmitting data from  MCU#1 to MCU#2 . I am sending data in form of  frames. The data sent from the TM4c123GH6PM will be serialized. It means that MCU#1 sends  data-frames in form of bytes to MCU#2.  After intensive tests, I noticed that some bytes are lost.  For example, I send repeatedly  a frame of the following form : 

    header (#), double 30 , Terminator ('\0') 

The Bytes of double is 30:0,0,0,0,0,0,94,64 and I only get the following Bytes: 0,0,0,0,0,94. The two MCU´s are connected by cables and they use uart to communicate between them.  Here is the whole code for sending:

    

First question: I want to ask why some bytes are lost, since I am using  cables?

second question: I know that there is some reconstruction algorithms for erasure canals. But I think that it is two complicated for my case, since I will tranfer data in the air (in worst case).  How can I resolve the problem of loosing data? I can  use CRC-Algorithm but it is intented for detecting error-transmission. It will not resolve my problem.

Edit: I put an old version of code responsible for receiving the data from MCU#1. Now I put the  last version of my code that can be compiled. Like I said, I am losing some bytes, when I am  transmitting data from MCU#1 to MCU#2. The frequency that I am using is 50MHZ. I need to transfer my data from MCU#2 to computer, so I cannot allow to lose data between MCU#1 and MCU#2. 

My main question: How can I solve the problem of losing bytes?

-->My code is too simple. I avoided to use complicated expressions. But I still lose my data

  • Hello Jo

    On the receiving side, first you have called SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); and then call SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); to change the frequency again: Why?

    Second of all reduce the rate between the communicating UART's and instead of printing the characters, store them in a array with the status bit for the frame to see if there are any issues

    Thirdly add delay between the transmitted characters to see if each byte is being transmitted and received clearly.

    Regards
    Amit
  • In the real world you must assume that their will be corruption and loss in communications. The only questions are how much and how will you respond.

    I'm not certain this will even compile, send BlockofBytes appears to be missing a closing brace.

    You would do yourself a favour if you cleaned up your code. You have extraneous casts and cannot seem to settle on using array or pointer notation for arguments.

    That said follow Amit's suggestions to narrow down your possible problems.

    Robert
  • Another note for consideration as you develop, your current protocol appears to depend on the binary representation of a double being identical between sender and receiver. That is, in general, a shaky assumption.

    Robert
  • Also

    Use a terminal program to verify sender and receiver independently.

    You do not initialize UART0 in both programs, or so it appears.

    Robert
  • Hello Robert,

    I would prefer the user not using printf statement to ensure that the receive and re-transmit is not the cause

    Regards
    Amit
  • @  do you mean reducing baudrate?

    @ I am using UART0 to resend my data from MCU#2 to PC. I will use it, when I am sure that I am receiving whole the data I need.

    @  what do you suggest to use for testing the data-transfer?

  • Agreed Amit, that is one reason to test with a terminal rather than both units at once.

    Robert
  • Jo my said:
    I am using UART0 to resend my data from MCU#2 to PC. I will use it, when I am sure that I am receiving whole the data I need.

    It appears you are already using it (unless your prints are directed elsewhere).

    Robert

  • Hello Jo,

    Yes, reduce the Baud Rate. To test the data transfer, send the data at a low baud rate first to make sure that the bytes are being received. Also ensure that for each byte being received a GPIO is toggled 0->1->0 that can be monitored on the scope or LA to reduce any data overhead processing.

    Regards
    Amit