I’m trying to transmit data from MSP430FG4618 to a PC via RS232. The baud rate setting is 115200bps with 8 data bits and 1 stop bit (no parity bit and no flow control). In the other words, if I’m correct, each character (byte) I send from MSP430 to PC is 9 bits. Therefore, at 115200bps, I can send a maximum of 115200/9=12800 characters/sec. As shown in my following code, I’m sending 128000 characters and it takes 11 seconds to complete. It takes 110 seconds to send 1280000 characters. In the other words, it’s about 10% slower. I think there might be one of the following possibilities:
1. The internal clock is not precise enough.
2. My code is not efficient enough.
3. It takes 10 bauds to transmit a character (8bits).
Or there's something else.
Can anyone answer my question?
Thanks.//Sending 128000 characters to PC at baud rate of 115200bps. It should take about 10 seconds to send
//each character has 9 bits (8 data bits + 1 stop bit)
#include "msp430xG46x.h"
#include <stdio.h>
#include <string.h>
void USCIA0_UART_P2_Init();
void USCIA0_UART_Transmit(unsigned char c);
void SendString(char* str);
void delay(unsigned int); //delay in ms
void main(void)
{
unsigned long i;
WDTCTL = WDTPW + WDTHOLD; //Stop WDT
FLL_CTL0 = (DCOPLUS | XCAP18PF); //Enable Frequency Multiplier (DCO+) and XIN/XOUT caps to 18pF
SCFI0 = (FLLD_2 | FN_8); //Set Multiplier to 2, and DCO range to 8MHz nominal
SCFQCTL = 121; //7.995392Mhz (D=2, N=121, fACLk=32768) f=D*(N+1)*fACLK
USCIA0_UART_P2_Init(); //Configure USCI for UART Mode and Use P2.4&P2.5 which are connected to the DB 9 connector
P1DIR &= ~BIT0|~BIT1; //set 2 push buttons to be input
while ((P1IN&BIT0)) {} // Push button 1 to start sending characters
for (i=1280000; i>=1; i--) //send 128000 characters - should take about 10 seconds to transmit
SendString("x"); //send a single character x
}
//---------------------------------------------------------------------------------------------------------------
void USCIA0_UART_P2_Init()
{
UCA0CTL1 |= UCSWRST; //Configure the USCI with the reset bit held high
P4SEL &= ~0x0C0; //P4.7,6 != USCI_A0 RXD/TXD
P2SEL |= 0x30; //Set the USCI to use P2.4 and P2.5 for RX/TX
UCA0CTL1 |= UCSSEL_2; //Use SMCLK
UCA0BR0 = 0x45; //Set Bit Rate to 115200bps with a 8Mhz clock
UCA0BR1 = 0x00;
UCA0MCTL = 0x4A; //Modulation
UCA0CTL1 &= ~UCSWRST; //Done configuring so take USCI out of reset
IE2 |= UCA0RXIE; //Enable USCI_A0 RX interrupt
return;
}
//---------------------------------------------------------------------------------------------------------------
/*
* The following function sends byte over RS-232 using the USCI A0 in UART mode
*/
void SendString(char* str)
{
while(!(IFG2 & UCA0TXIFG)); //Wait until transmit buffer is empty
UCA0TXBUF=str[0];
//return;
}