Hello, everybody,
currently working with the MSP430FR2433, my goal is to use UARTs to transmit a message. I am at the beginning of this project so my current goal is to send only one message between two UARTs on the same launchpad. You will find below the code, it contains the hardware initialization (clock, UART etc...). However, there is no result, Putty which seems to be correctly configured (bauds, port, flow control) does not observe anything when it is put into serial mode. I'm sorry for the length of the code... And hope to have some help, in advance thank you very much.
#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 // software-dl.ti.com/.../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 // software-dl.ti.com/.../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]); } } }