Hi Everyone. I am currently trying to use the backdoor UART to receive multiple bytes from PC Host. I used the example code "uart_pc_echo_12mhz_brclk" and tested the code with Coolterm. My bytes("abcd") is sent from Coolterm. I was succssfully interruped. When I check the value of "UCA0RXBUF".I saw the "a" there, then i continue the excution and get interrupted again.However, instead of seeing "b". I am seeing "d" in UCA0RXBUF. Somehow my middle bytes are missing. I appoligize if the this is very simple question. Did i parse my bytes incorrectly? if so. How do i extract all of my bytes from UCA0RXBUF? Thank you, Eddy /* * ------------------------------------------- * MSP432 DriverLib - v3_21_00_05 * ------------------------------------------- * * --COPYRIGHT--,BSD,BSD * Copyright (c) 2016, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --/COPYRIGHT--*/ /****************************************************************************** * MSP432 UART - PC Echo with 12MHz BRCLK * * Description: This demo echoes back characters received via a PC serial port. * SMCLK/DCO is used as a clock source and the device is put in LPM0 * The auto-clock enable feature is used by the eUSCI and SMCLK is turned off * when the UART is idle and turned on when a receive edge is detected. * Note that level shifter hardware is needed to shift between RS232 and MSP * voltage levels. * * MSP432P401 * ----------------- * | | * | | * | | * RST -| P1.3/UCA0TXD|----> PC (echo) * | | * | | * | P1.2/UCA0RXD| //#include "printf.h" #include #include "msp.h" #include #include #include #include #include #include //#include /* UART Configuration Parameter. These are the configuration parameters to * make the eUSCI A UART module to operate with a 9600 baud rate. These * values were calculated using the online calculator that TI provides * at: * software-dl.ti.com/.../index.html */ const eUSCI_UART_Config uartConfig = { EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source 78, // BRDIV = 78 2, // UCxBRF = 2 0, // UCxBRS = 0 EUSCI_A_UART_NO_PARITY, // No Parity EUSCI_A_UART_LSB_FIRST, // LSB First EUSCI_A_UART_ONE_STOP_BIT, // One stop bit EUSCI_A_UART_MODE, // UART mode EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling }; /* Graphic library context */ //Receive UART Variables #define NUM_RX_CHARS 64 char rxMsgData[NUM_RX_CHARS] = ""; int numMsgsRx = 0; int tempIndex = 5; int numChars = 0; #define MAX_STR_LENGTH 271 #define FALSE 0 #define TRUE 1 typedef struct{ unsigned char newStringReceived; char txString[MAX_STR_LENGTH]; char rxString[MAX_STR_LENGTH]; }s_test; extern s_test test; s_test test = { FALSE, "", "" }; /* Variable for storing lux value returned from OPT3001 */ float lux; /* Timer_A Up Configuration Parameter */ const Timer_A_UpModeConfig upConfig = { TIMER_A_CLOCKSOURCE_ACLK, // ACLK Clock SOurce TIMER_A_CLOCKSOURCE_DIVIDER_1, // ACLK/1 = 3MHz 200, // 200 tick period TIMER_A_TAIE_INTERRUPT_DISABLE, // Disable Timer interrupt TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE, // Disable CCR0 interrupt TIMER_A_DO_CLEAR // Clear value }; /* Timer_A Compare Configuration Parameter (PWM) */ Timer_A_CompareModeConfig compareConfig_PWM = { TIMER_A_CAPTURECOMPARE_REGISTER_3, // Use CCR3 TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE, // Disable CCR interrupt TIMER_A_OUTPUTMODE_TOGGLE_SET, // Toggle output but 100 // 50% Duty Cycle }; int main(void) { /* Halting WDT */ MAP_WDT_A_holdTimer(); /* Set the core voltage level to VCORE1 */ MAP_PCM_setCoreVoltageLevel(PCM_VCORE1); /* Set 2 flash wait states for Flash bank 0 and 1*/ MAP_FlashCtl_setWaitState(FLASH_BANK0, 2); MAP_FlashCtl_setWaitState(FLASH_BANK1, 2); // the UART DOES NOT WORK FOR more than 24Mhz MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_24); MAP_CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2 ); MAP_CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2 ); MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2 ); MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_2); Init_I2C_GPIO(); I2C_init(); /* Selecting P1.2 and P1.3 in UART mode */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); /* Setting DCO to 12MHz */ /* Configuring UART Module */ MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig); /* Enable UART module */ MAP_UART_enableModule(EUSCI_A0_BASE); /* Enabling UART interrupts */ MAP_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT); MAP_Interrupt_enableInterrupt(INT_EUSCIA0); MAP_Interrupt_enableSleepOnIsrExit(); MAP_Interrupt_enableMaster(); //sample test code for i2c, this code is not interrupt based. //I2C_write8(0x39,0x80, 0x03); //I2C_write8(0x39,0x81, 0x01); //int16_t raw; //int16_t raw_2; //raw = I2C_read8(0x39,0x60); //raw_2 = I2C_read16(0x80); //I2C_write8(0x39,0x80, 0x03); //I2C_write8(0x39,0x81, 0x01); //raw = I2C_read8(0x39,0x60); //raw_2 = I2C_read16(0x80); char *s = "printf test"; char c = '!'; int i = -12345; unsigned u = 4321; long int l = -123456780; long unsigned n = 1098765432; unsigned x = 0xABCD; %x\r\n", x); while(1) { MAP_PCM_gotoLPM0(); } } /* EUSCI A0 UART ISR - Echoes data back to PC host */ /* This code works the following way * 1) Open a cool term serial port * 2) the board has backdoor uart and will shows up as comm port * 3)connect to that port in coolterm * 4)send some strings * 5)add a break point at below interrupt. * 6)the byte send should be stored in the "receiveByte" address * 7)Then the byte will be eched back to the cool term */ void EUSCIA0_IRQHandler(void) { uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_BASE); char receiveByte = UCA0RXBUF; //This is the address where the received byte is stored MAP_UART_clearInterruptFlag(EUSCI_A0_BASE, status); if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG) { MAP_UART_transmitData(EUSCI_A0_BASE, receiveByte); } }
↧