0
\$\begingroup\$

Dear all i have a very simple question on serial data transmission.

signed int NUM;//32 bit
NUM=235;

the serial configuration is:

  • 115200 baud rate
  • 1 start
  • 1 stop
  • no parity.

How much time will it take to transmit this number(NUM) over the serial port?

furthermore, I send the data in two ways as follows. My IDE is Keil Microvision. 1> use printf("%d /n", NUM);

2> I have written a function

    void Send_Info(uint32 count1)
{
      int k;
        static uint8 NumPos[6]={0};

    NumPos[0]= count1 / 10000 + 0x30;        //tenthousand1
    NumPos[1]= count1 % 10000 / 1000 + 0x30; //thousand1
    NumPos[2]= count1 % 1000 / 100 + 0x30;   //hundred1 
    NumPos[3]= count1 % 100 / 10 + 0x30;     //decimal1 
    NumPos[4]= count1 % 10 + 0x30;           //unit1 
    NumPos[5]= 0x0D;                         //CR
     for(k = 0; k < 6; k++)
    {
            (void)stdout_putchar(NumPos[k]);
    }
}

All transmission happens inside an interrupt which occurs in every 0.5 sec.

\$\endgroup\$
  • 1
    \$\begingroup\$ That depends on the format in which you transmit it, any framing characters or breaks, to identify the data, etc. Since you haven't included code that does the transmission, this is unknowable. There is, for example a factor of two difference between transmitting a binary value and transmitting a printable hex representation, and potentially more than that for decimal, depending if you use leading zeroes, etc... \$\endgroup\$ – Chris Stratton Mar 5 '18 at 17:41
  • \$\begingroup\$ Modulus takes a long time to execute compared to other instructions, I'd use a printf and send it via hex string. The best way to find the timing is to debug with the profiler \$\endgroup\$ – laptop2d Mar 6 '18 at 16:30
5
\$\begingroup\$

The number of bits to transmit is 32. In addition, there is 1 start and 1 stop bit per 8 or 9 bits (depending what is selected for #data bits), assuming 8 data bits, there are 4 start bits and 4 stop bits, so in total 32 + 4 + 4 = 40 bits.

115200 baud means 11500 bits/sec, so 40 bits will take 40 / 115200 = appr. 0.000347 s = 347 us.

However, there might be a slight overhead / delay for the processing itself, but this is high likely negligible.

UPDATE

The question seems to have been edited. The above is true for sending 4 bytes (32 bits) of real data (resulting in 40 bits). In the example above 6 bytes are sent, but the formula stays the same.

\$\endgroup\$
  • \$\begingroup\$ Ohh... I was doubtful. I thought it is an 8bit number so it takes total 10 bits to transmit!!! Got it. Thanks \$\endgroup\$ – litun bls Mar 5 '18 at 17:44
  • 1
    \$\begingroup\$ @litunbls The UART configuration that you describe will always transmit ten total bits for every 8 data bits. Every bit takes the same amount of time as every other bit. \$\endgroup\$ – Solomon Slow Mar 5 '18 at 17:48
  • 1
    \$\begingroup\$ Regarding the delay, I see what you're trying to say but a modern UART Tx will most likely be buffered i.e. can accept at least 1 next byte while transmitting the current one. So the inter-byte gap would be zero and the only processing delay would be before the first Tx, which is outside of the transmission period. \$\endgroup\$ – TonyM Mar 5 '18 at 17:56
  • 1
    \$\begingroup\$ The number of bits to transmit is almost certainly not 32. That's just the data. There is almost certainly a delimiter, such as <CR> or ",", and there may be any number of other issues. For instance, sending 4 successive bytes of binary is a fairly rare way to send data - 8 bytes of hex data is far more likely, since this allows delimiters to be used in the first place. \$\endgroup\$ – WhatRoughBeast Mar 5 '18 at 17:57
  • 2
    \$\begingroup\$ Note that given the edited question shows an ASCII-encoded decimal being sent, this answer is now incorrect. \$\endgroup\$ – Jules Mar 5 '18 at 19:07
4
\$\begingroup\$

It looks like you are transmitting 6 ASCII characters. You don't say if these are sent as 7-bit or 8-bit characters, but suppose 8 bits per character, the worst case. So there are 6 frames consisting of 1 start bit, 8 data bits, and 1 stop bit, for a total of 60 bits. 60 bits / 115200 baud = 521us. This assumes that the transmit buffer is being reloaded before the previous character finishes so that there are no delays between frames.

\$\endgroup\$
  • \$\begingroup\$ How can I reduce the size of the data frame, so that transmission happens quickly!!! \$\endgroup\$ – litun bls Mar 6 '18 at 6:58
  • \$\begingroup\$ Can anyone tell me about how Keil Microvision provided 'printf()' statement works? I mean in which format this function sends data e.g ASCII or Binary? \$\endgroup\$ – litun bls Mar 6 '18 at 7:01
  • \$\begingroup\$ To minimize transmission time, you can set the number of bits per character to 7, which is the minimum for basic ASCII. But only if the micro you are using and the receiver can be configured for 7-bit characters. \$\endgroup\$ – user28910 Mar 6 '18 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.