我正在尝试通过PuTTY编写两个MSP430s来实现即时消息,但是我不知道如何在没有调试器的情况下将键入的信息放到MSP430上。我使用的是CCS,它是一个MSP430 F2274。我有一个程序,在这个程序中,用户在一个MSP430上的按钮上输入摩尔斯电码,通过以下方法成功输出到PuTTY off另一个MSP430。
void displayString(char array[], char size) {
WDTCTL = WDTPW + WDTHOLD; // Disable WDT
DCOCTL = CALDCO_8MHZ; // Load 8MHz constants
BCSCTL1 = CALBC1_8MHZ; //
P3SEL |= 0x30; // P3.4,5 = USCI_A0 TXD/RXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 0x41; // 8MHz 9600
UCA0BR1 = 0x03; // 8MHz 9600
UCA0MCTL = UCBRS1; // Modulation UCBRSx = 2
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
int count;
for(count=0; count<size; count++){
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = array[count]; // TX -> RXed character
}
}是否有人可以使用类似的设置发送执行相反操作(在MSP430上键入信息)的代码?谢谢。
发布于 2014-07-17 06:23:59
我使用的是picocom:
$ picocom -r -b 9600 /dev/ttySxxxxUART初始化代码:
void uart_setup()
{
// Configure UART pins
P2SEL1 |= BIT0 + BIT1;
P2SEL0 &= ~(BIT0 + BIT1);
// Configure UART 0
UCA0CTL1 |= UCSWRST; // perform reset
UCA0CTL1 = UCSSEL_1; // Set ACLK = 32768 as UCBRCLK
UCA0BR0 = 3; // 9600 baud
UCA0BR1 = 0;
UCA0MCTLW |= 0x5300; // 32768/9600 - INT(32768/9600)=0.41
// UCBRSx value = 0x53 (See UG)
UCA0CTL1 &= ~UCSWRST; // release from reset
//UCA0IE |= UCRXIE; // Enable RX interrupt
}覆盖putchar():
int putchar(int c)
{
if (c == '\n') putchar('\r');
while (!(UCA0IFG & UCTXIFG));
UCA0TXBUF = c;
return 0;
}然后您可以简单地调用printf(...)将文本从MSP430输出到串行端口。
发布于 2014-07-17 08:43:18
如果您仍然希望保留putchar()和prtinf()用于调试目的-打印到调试器调试窗口中,那么您可以使用单独的read函数:
unsigned char ReadByteUCA_UART(void)
{
//while ((IFG2&UCA0RXIFG)==0); // wait for RX buffer (full)
while(UCA0STAT&UCBUSY);
return (UCA0RXBUF);
} https://stackoverflow.com/questions/24788804
复制相似问题