Tool/software: Code Composer Studio
I am trying to write a code to enter a string of characters/integers in serial monitor with UART interface (for MSP430g2553 module). But there are some issues in defining "gets and puts". Can anyone help me with this
Here is the code:
#include <msp430.h>
#include <stdint.h>
#include <stdio.h>
int gets(void)
{
while(!(IFG2 & UCA0RXIFG));
IFG2 &= ~UCA0RXIFG;
return UCA0RXBUF;
}
int puts(int c)
{
while(!(IFG2 & UCA0TXIFG)); // wait for TX buffer to be empty
UCA0TXBUF = c;
return c;
}
void print(const char *s)
{
while(*s) puts(*s++);
}
void printx(const uint32_t c)
{
unsigned char hex_table[] = { };
puts(hex_table[(c & 0xF0) >> 4]);
puts(hex_table[c & 0x0F]);
}
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; /* No watchdog reset */
BCSCTL1 = CALBC1_1MHZ; /* run with 1MHz DCO */
DCOCTL = CALDCO_1MHZ;
__delay_cycles(1000000); /* slight delay */
// Configure P1.1 and P1.2 as UART controlled pins
P1DIR &= ~(BIT1 | BIT2); // Revert to default to GPIO input
P1SEL = BIT1 | BIT2; // P1.1=RXD, P1.2=TXD
P1SEL2 = BIT1 | BIT2; // P1.1=RXD, P1.2=TXD
UCA0CTL1 = UCSWRST; // Hold USCI in reset to allow configuration
UCA0CTL0 = 0; // No parity, LSB first, 8 bits, one stop bit, UART (async)
UCA0BR0 = 104;
UCA0BR1 = 0x00;
UCA0MCTL = UCBRS0;
UCA0CTL1 = UCSSEL_2; // Use SMCLK for bit rate generator, then release reset
while(1)
{
int c = gets();
//printf("You pressed " %c"\r\n", c, ( (c >= " " && c <= '~') ? c : '.'));
print("You pressed 0x");
printx(c);
print(" string ");
puts( ((c >= " " && c <= '~') ? c : '.') );
print("'\r\n");
{
uint32_t c;
for(c = " "; c <= '~'; ++c)
{
puts(c);
if ( c == ' '+64 || c == ' '+32 )
{
print("\r\n");
}
}
}
print("\r\ndone!\r\n");
}
return 0;
}