大家
当前与MSP430FR2433配合使用,我的目标是使用UART传输消息。我正处于这个项目的开始,所以我目前的目标是在同一启动板上的两个UART之间仅发送一条消息。您会在代码下面找到它,其中包含硬件初始化(时钟,UART等...)。但是,没有结果,当看上去正确配置的腻子(波特率,端口,流量控制)进入串行模式时,它什么也观察不到。对于代码的长度,我们感到抱歉。...并希望对您有所帮助,在此先非常感谢您。
#include <msp430fr2433.h>
#include "driverlib/MSP430FR2xx_4xx/driverlib.h"
#include <stdlib.h>
#include "C:/ti/ccsv8/tools/compiler/ti-cgt-msp430_18.1.3.LTS/include/string.h"
#include "C:/ti/ccsv8/tools/compiler/ti-cgt-msp430_18.1.3.LTS/include/time.h"
#include "C:/ti/ccsv8/tools/compiler/ti-cgt-msp430_18.1.3.LTS/include/stdio.h"
#define DCOFREQ 8000000 //8MHz
#define TXLED BIT0
#define RXLED BIT6
#define MAX_STRBUF_SIZE 1024
void systemInit(void);
void initCs(void);
void initEusci(void);
void initEusci1(void);
void UART_receiveString(char);
void UART_transmiteString1(char*);
void UART_transmiteString(char*);
bool rxStringReady;
char rxString[MAX_STRBUF_SIZE];
char txString1[MAX_STRBUF_SIZE] = {"ok"}; // 0110 1111 01101011
volatile uint32_t i; // Used in the main function in the for loop
int iii = 0;
int main(void)
{
systemInit(); // System initialization
UART_transmiteString1(txString1);
while(1)
{
UART_transmiteString1(txString1);
for(i=100000; i>0; i--);
}
}
void systemInit(void)
{
// Stop watchdog timer
WDT_A_hold(WDT_A_BASE);
printf("Hello in System Init\n");
// Initialization of the clock
initCs();
// LED output
P1DIR |= RXLED + TXLED;
P1OUT &= 0x00;
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
//Initialization of the UARTs.
initEusci();
initEusci1();
// Enable gobal interrupts
__enable_interrupt();
}
void initCs(void)
{
// Initialization of the clocks
CS_initClockSignal(CS_SMCLK, CS_DCOCLKDIV_SELECT, CS_CLOCK_DIVIDER_1);
// For demonstration purpose, change DCO clock freq to 8MHz
CS_initFLLSettle((DCOFREQ/1000), (DCOFREQ/32768));
}
// EUSCI 0
void initEusci(void)
{
// Configure UCA1TXD and UCA1RXD
P1SEL0 |= BIT4 | BIT5;
P1SEL1 &= ~(BIT4 | BIT5);
// Configure UART
// http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html
// 115 200 bps this value depends on the transmitter used
EUSCI_A_UART_initParam param = {0};
param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
param.clockPrescalar = 4;
param.firstModReg = 5;
param.secondModReg = 85;
param.parity = EUSCI_A_UART_NO_PARITY;
param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
param.uartMode = EUSCI_A_UART_MODE;
param.overSampling = EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
if(STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, ¶m))
{
return;
}
EUSCI_A_UART_enable(EUSCI_A0_BASE);
// Interruption
EUSCI_A_UART_clearInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);
// Enable USCI_A0 RX interrupt
EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT); // Enable interrupt
}
// EUSCI interrupt service routine 0
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
printf("i m before the switch\n");
switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG))
{
printf("i m in the switch\n");
case USCI_NONE: break;
// Function which run the halt
case USCI_UART_UCRXIFG:
// Read buffer
UART_receiveString(UCA0RXBUF);
// Write in buffer
UART_transmiteString(rxString);
break;
case USCI_UART_UCTXIFG: break;
case USCI_UART_UCSTTIFG: break;
case USCI_UART_UCTXCPTIFG: break;
default: break;
}
}
void UART_receiveString(char data)
{
printf("%c\n", data);
bool rxInProgress = false;
unsigned int charCnt = 0;
if(!rxInProgress) // if it's wrong, start the interruption with this condition
{
if ((data != '\n') ) // if it's a new line, the value of the timer change to 0.
{
rxInProgress = true;
charCnt = 0;
rxString[charCnt] = data;
}
}
else
{ // in progress
charCnt++;
if((data != '\n'))
{
if (charCnt >= MAX_STRBUF_SIZE) // If it has come to transmit a length greater than MAX_STRBUF_SIZE to read the data.
{
rxInProgress = false;
}
else
{
rxString[charCnt] = data; // Read the data and write them in a table.
}
}
else
{
rxInProgress = false;
rxString[charCnt] = '\0';
// String receive complete
rxStringReady = true;
}
}
}
void UART_transmiteString(char *str)
{
int ii = 0;
for(ii = 0; ii < strlen(str); ii++)
{
if (str[ii] != 0)
{
// Transmit Character
while (EUSCI_A_UART_queryStatusFlags(EUSCI_A0_BASE, EUSCI_A_UART_BUSY));
EUSCI_A_UART_transmitData(EUSCI_A0_BASE, str[ii]);
}
}
}
// EUSCI 1
void initEusci1(void) {
// Configure UCA1TXD and UCA1RXD
P2SEL0 |= BIT6 | BIT5;
P2SEL1 &= ~(BIT6 | BIT5);
// Configure UART
// http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html
EUSCI_A_UART_initParam param = {1};
param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
param.clockPrescalar = 4;
param.firstModReg = 5;
param.secondModReg = 85;
param.parity = EUSCI_A_UART_NO_PARITY;
param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
param.uartMode = EUSCI_A_UART_MODE;
param.overSampling = EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
if(STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A1_BASE, ¶m))
{
return;
}
EUSCI_A_UART_enable(EUSCI_A1_BASE);
// Interruptions do not need to be enabled
}
void UART_transmiteString1(char *str1)
{
int i1 = 0;
printf("%d\n", strlen(str1));
for(i1 = 0; i1 < strlen(str1); i1++)
{
if (str1[i1] != 0)
{
// Transmit Character
while (EUSCI_A_UART_queryStatusFlags(EUSCI_A1_BASE, EUSCI_A_UART_BUSY));
EUSCI_A_UART_transmitData(EUSCI_A1_BASE, str1[i1]);
}
}
}
答案 0 :(得分:1)
尝试使用调试器,并在代码中使用断点循环。除了此下载之外,还可以从TI下载参考代码(这些参考代码很小),从小处开始并逐步扩展代码。