Part Number: MSP430FR59941 I'm trying to get UART Tx to work with a custom MSP430FR59941 board. I see messages at the terminal window but they are all garbled up. The baud rate is set for 4800 both on the MSP430 and the terminal window (slow baudrate to minimize possible timing issues). I have another program that the messages are received properly so I know it's not a hardware setup issue. I also compared the CS registers and eUSCI_A2 registers between the project that works and the project that doesn't work after the initialization and all the register values match. I was wondering if there's something obvious that I'm missing. Here's the code for the project that doesn't work: #include #include #include #include "driverlib.h" #include "hal_peripheral_map.h" #define CLI_UART_USCI_BASE_ADDR EUSCI_A2_BASE #define UART_SERIAL_CLI_TX_PORT GPIO_PORT_P5 #define UART_SERIAL_CLI_TX_PIN GPIO_PIN4 #define UART_SERIAL_CLI_TX_MODE GPIO_PRIMARY_MODULE_FUNCTION #define UART_SERIAL_CLI_RX_PORT GPIO_PORT_P5 #define UART_SERIAL_CLI_RX_PIN GPIO_PIN5 #define UART_SERIAL_CLI_RX_MODE GPIO_PRIMARY_MODULE_FUNCTION #define LFXIN_PORT GPIO_PORT_PJ #define LFXIN_PIN GPIO_PIN4 #define LFXIN_MODE GPIO_PRIMARY_MODULE_FUNCTION #define LFXOUT_PORT GPIO_PORT_PJ #define LFXOUT_PIN GPIO_PIN5 #define LFXOUT_MODE GPIO_PRIMARY_MODULE_FUNCTION void Init_Clock(void); void Init_UART(void); void vTransmitString(const char * str, unsigned int len); void vDisableAllGpioInterrupts(void); void vInitalizeAllGpioAsInputs(void); void vInitializeClockSys(void); void vHalBoardInit(void); const char * const pcMessage = "Hello world!\r\n"; int main(void) { vHalBoardInit(); Init_UART(); while(1) { vTransmitString( pcMessage, strlen(pcMessage) ); __delay_cycles(8000000); } } void Init_UART(void) { EUSCI_A_UART_initParam param32kHz_4800 = { //Baudrate = 4800, clock freq = 32768Hz (ACLK) //UCBRx = 6 (prescalar), UCBRFx = 0, UCBRSx = 0xEE, UCOS16 = 0 .selectClockSource = EUSCI_A_UART_CLOCKSOURCE_ACLK, .clockPrescalar = 6, //UCBRx .firstModReg = 0, .secondModReg = 0xEE, //UCBRSx .parity = EUSCI_A_UART_NO_PARITY, .msborLsbFirst = EUSCI_A_UART_LSB_FIRST, .numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT, .uartMode = EUSCI_A_UART_MODE, .overSampling = EUSCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION // }; GPIO_setAsPeripheralModuleFunctionInputPin( UART_SERIAL_CLI_RX_PORT, UART_SERIAL_CLI_RX_PIN, UART_SERIAL_CLI_RX_MODE ); GPIO_setAsPeripheralModuleFunctionOutputPin( UART_SERIAL_CLI_TX_PORT, UART_SERIAL_CLI_TX_PIN, UART_SERIAL_CLI_TX_MODE ); if(STATUS_FAIL == EUSCI_A_UART_init(CLI_UART_USCI_BASE_ADDR, ¶m32kHz_4800)) { while(1); } //Enable UART module for operation EUSCI_A_UART_enable(CLI_UART_USCI_BASE_ADDR); //Enable Receive Interrupt EUSCI_A_UART_clearInterrupt(CLI_UART_USCI_BASE_ADDR, EUSCI_A_UART_RECEIVE_INTERRUPT | \ EUSCI_A_UART_TRANSMIT_INTERRUPT ); EUSCI_A_UART_enableInterrupt(CLI_UART_USCI_BASE_ADDR, EUSCI_A_UART_RECEIVE_INTERRUPT | \ EUSCI_A_UART_TRANSMIT_INTERRUPT); __enable_interrupt(); const char * const pcWelcomeMessageLocal = "\n\rDEBUG\r\n"; //Prints direct to the console vTransmitString( pcWelcomeMessageLocal, strlen(pcWelcomeMessageLocal) ); } void vTransmitString(const char * str, unsigned int len) { // Select UART TXD on P5.4 GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P5, GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION); for (unsigned int i = 0; i < len; i++) { EUSCI_A_UART_transmitData(EUSCI_A2_BASE, str[i]); // Wait for transmition to finish while(EUSCI_A_UART_queryStatusFlags(EUSCI_A2_BASE, EUSCI_A_UART_BUSY)); } GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN4); GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN4); } void vDisableAllGpioInterrupts(void) { GPIO_disableInterrupt(GPIO_PORT_PA, GPIO_PIN_ALL16); GPIO_disableInterrupt(GPIO_PORT_PB, GPIO_PIN_ALL16); } void vInitalizeAllGpioAsInputs(void) { GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN_ALL8); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P2, GPIO_PIN_ALL8); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P3, GPIO_PIN_ALL8); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P4, \ ~( EPPIC_PWSTRT_PIN \ | EPPIC_BLANK_DOUT_PORT \ | EPPIC_RST_DOUT_PORT )); GPIO_setAsInputPinWithPullDownResistor(GPIO_PORT_P4,\ ( EPPIC_PWSTRT_PIN \ | EPPIC_BLANK_DOUT_PORT \ | EPPIC_RST_DOUT_PORT ) ); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P5, GPIO_PIN_ALL8); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P6, GPIO_PIN_ALL8); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P7, GPIO_PIN_ALL8); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P8, GPIO_PIN_ALL8); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_PE, GPIO_PIN_ALL16); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_PJ, GPIO_PIN_ALL16); } void vInitializeClockSys(void) { GPIO_setAsPeripheralModuleFunctionInputPin( LFXIN_PORT, LFXIN_PIN, LFXIN_MODE); PMM_unlockLPM5(); /* Need to unlock XIN */ /* Set freq value for external clock source X1 = 32.768Khz, X2 = 0 */ CS_setExternalClockSource(32768, 0); CS_bypassLFXTWithTimeout(100); /* Initialize DCO to 8Mhz */ CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_6); CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); /* 8Mhz */ CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_4); /* 2Mhz */ CS_initClockSignal(CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); /* 32Khz */ /* What about MODOSC ? Who is using this clock? ADC? */ CS_turnOffVLO(); CS_turnOffHFXT(); CS_clearAllOscFlagsWithTimeout(100); CS_enableClockRequest(CS_ACLK | CS_SMCLK | CS_MCLK | CS_MODOSC); #ifdef _DEBUG /* Read back ACLK, MCLK, SMCLK configuusRation for debug/verification */ static uint32_t ulAclk=0, ulMclk=0, ulSmclk=0; ulAclk = CS_getACLK(); ulMclk = CS_getMCLK(); ulSmclk = CS_getSMCLK(); #endif } void vHalBoardInit(void) { //Stop watchdog timer WDT_A_hold(WDT_A_BASE); vDisableAllGpioInterrupts(); vInitalizeAllGpioAsInputs(); /* Initialize MSP430 Clocks */ vInitializeClockSys(); } #pragma vector=USCI_A2_VECTOR __interrupt void usci_uart_interrupt_vector_table(void) { switch(__even_in_range(UCA2IV,8)) { case UCIV__UCRXIFG: /*Vector 2 - RXIFG */ break; case UCIV__UCTXIFG: /*Vector 4 - TXIFG Transmit buffer empty */ break; case UCIV__UCSTTIFG: /*Vector 6 - Start bit received */ break; case UCIV__UCTXCPTIFG: /* Vector 8 -- Transmit Complete*/ break; default: /* default: No interrupt */ break; } }
↧