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.
Best Answer
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.