Tool/software: Code Composer Studio
Hi Everybody,
I'm trying to create communication between pc and MSP but i'm only getting the last character
The baudrate both pc and msp is 9600
Here's the code for the serial communication:
void InitSerialCommunication() { P1SEL |= RXD + TXD ; // P1.1 = RXD, P1.2=TXD P1SEL2 |= RXD + TXD ; // P1.1 = RXD, P1.2=TXD UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 = 0x68; // 1MHz 9600 UCA0BR1 = 0x00; // 1MHz 9600 UCA0MCTL = UCBRS2 + UCBRS0; // Modulation UCBRSx = 5 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** } int HasRequest() { return (IFG2 & UCA0RXIFG); } void Transmit(char* data, int size) { while(size > 0) { UCA0TXBUF = *data++; size--; __delay_cycles(DELAY_CHAR);//required to get all characters (if more than 10 characters or clock has changed, consider increase delay time) } } void Recieve(char* data) { if(!HasRequest()) return; *data = UCA0RXBUF; __delay_cycles(DELAY_CHAR); }
DELAY_CHAR = 1000
and here's the main code (i'm using lcd to see the result )
#include <msp430g2553.h> #include "LCD.h" #include "SerialCommunication.h" /* * main.c */ #define SDA_BIT BIT7 #define SCL_BIT BIT6 #define LCD_ADDRESS 0x27 #define WAIT_TIME 255 char key; #define SIZE_M 5 char R[SIZE_M]; char counter = 0; void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer DCOCTL = 0; // Select lowest DCOx and MODx settings< BCSCTL1 = CALBC1_1MHZ; // Set DCO DCOCTL = CALDCO_1MHZ; InitLCD(SDA_BIT, SCL_BIT, LCD_ADDRESS); InitSerialCommunication(); key = NONEKEY; StartLCD(); __enable_interrupt(); char address = 0x80; while(1) { Transmit("hiyou",5); //__delay_cycles(4500); while(HasRequest()) { Recieve(&R[counter++]); } if(counter > 0) { WriteMsg(R,counter,address,counter); counter = 0; } } }
Thank you all