TI中文支持网
TI专业的中文技术问题搜集分享网站

MSP432的串口问题

如何用MAP_UART_transmitData()函数发送一个字符?这个函数的第二个参数应该是什么?比如要发送一个字符‘m’,第二个参数应该是什么?

gaoyang9992006:

/! Transmits a byte from the UART Module.//!//! \param moduleInstance is the instance of the eUSCI A (UART) module.//! Valid parameters vary from part to part, but can include://! – \b EUSCI_A0_MODULE//! – \b EUSCI_A1_MODULE//! – \b EUSCI_A2_MODULE//! – \b EUSCI_A3_MODULE//! <br> It is important to note that for eUSCI modules, only "A" modules such//! as EUSCI_A0 can be used. "B" modules such as EUSCI_B0 do not support the//! UART mode//! \param transmitData data to be transmitted from the UART module//!//! This function will place the supplied data into UART transmit data register//! to start transmission//!//! Modified register is \b UCAxTXBUF//! \return None.////*****************************************************************************extern void UART_transmitData(uint32_t moduleInstance, uint_fast8_t transmitData);

——————————————————

看该头文件解释:第一个是moduleInstance,可以选择的参数是:

//! – \b EUSCI_A0_MODULE//! – \b EUSCI_A1_MODULE//! – \b EUSCI_A2_MODULE//! – \b EUSCI_A3_MODULE

第二个参数是发送的数据

gaoyang9992006:

所以第二个参数你就可以填写个‘m’,或者你前面定义个变量存放m,或者用指针都是可以的

gaoyang9992006:

     

volatile uint8_t TXData = 1;

  MAP_UART_transmitData(EUSCI_A0_MODULE, TXData);

—————————————————————————————

/** -------------------------------------------*MSP432 DriverLib - v01_04_00_18* -------------------------------------------** --COPYRIGHT--,BSD,BSD* Copyright (c) 2015, 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 - Loopback with 48MHz DCO BRCLK** Description: This demo connects TX to RX of the MSP432 UART* The example code shows proper initialization of registers* and interrupts to receive and transmit data. If data is incorrect P1.0 LED* is turned ON.**MCLK = HSMCLK = SMCLK = DCO of 48MHz**MSP432P401*-----------------*||*RST -|P1.3/UCA0TXD|----|*|||*-|||*|P1.2/UCA0RXD|----|*||*|P1.0|---> LED*||** Author: Timothy Logan
*******************************************************************************/
/* DriverLib Includes */
#include "driverlib.h"/* Standard Includes */
#include <stdint.h>#include <stdbool.h>volatile uint8_t TXData = 1;
volatile uint8_t RXData = 0;/* UART Configuration Parameter. These are the configuration parameters to* make the eUSCI A UART module to operate with a 115200 baud rate. These* values were calculated using the online calculator that TI provides* at:* http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html*/
const eUSCI_UART_Config uartConfig =
{EUSCI_A_UART_CLOCKSOURCE_SMCLK,// SMCLK Clock Source26,// BRDIV = 260,// UCxBRF = 0111,// UCxBRS = 111EUSCI_A_UART_NO_PARITY,// No ParityEUSCI_A_UART_MSB_FIRST,// MSB FirstEUSCI_A_UART_ONE_STOP_BIT,// One stop bitEUSCI_A_UART_MODE,// UART modeEUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION// Oversampling
};int main(void)
{/* Halting WDT*/MAP_WDT_A_holdTimer();/* Selecting P1.2 and P1.3 in UART mode and P1.0 as output (LED) */MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);/* Setting DCO to 48MHz (upping Vcore) */MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);/* Configuring UART Module */MAP_UART_initModule(EUSCI_A0_MODULE, &uartConfig);/* Enable UART module */MAP_UART_enableModule(EUSCI_A0_MODULE);/* Enabling interrupts */MAP_UART_enableInterrupt(EUSCI_A0_MODULE, EUSCI_A_UART_RECEIVE_INTERRUPT);MAP_Interrupt_enableInterrupt(INT_EUSCIA0);MAP_Interrupt_enableSleepOnIsrExit();while(1){MAP_UART_transmitData(EUSCI_A0_MODULE, TXData);MAP_Interrupt_enableSleepOnIsrExit();MAP_PCM_gotoLPM0InterruptSafe();}
}/* EUSCI A0 UART ISR - Echos data back to PC host */
void euscia0_isr(void)
{uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_MODULE);MAP_UART_clearInterruptFlag(EUSCI_A0_MODULE, status);if(status & EUSCI_A_UART_RECEIVE_INTERRUPT){RXData = MAP_UART_receiveData(EUSCI_A0_MODULE);if(RXData != TXData)// Check value{MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);while(1);// Trap CPU}TXData++;MAP_Interrupt_disableSleepOnIsrExit();}}

jiahe fan:

回复 gaoyang9992006:

我一开始也是这么写的:  MAP_UART_transmitData(EUSCI_A0_MODULE, 'm');,可是在上位机上收到的字符完全不对,不知道是为什么,波特率是9600,用的是ti的12mhz的那个例程,稍微改动了一下,把接受中断里的发送函数改成了MAP_UART_transmitData(EUSCI_A0_MODULE, 'm');。难道是我的硬件有问题吗?是不是只要插上launchpad上那根usb线就好了?不需要其他的操作吧?

gaoyang9992006:

回复 jiahe fan:

如果能接收到数据,却内容不对,你连续发送10次m,试试看,如果能发送,且收到若干相同的字符或乱码,那么就是你时钟配置错误。

k t:

回复 jiahe fan:

我也是碰到这个问题,结果发现是串口字节倒序了。比如你发送的'm'二进制是0x01101101,而电脑收到的却是0x10110110。是不是固件库有BUG啊,不知道楼主解决这个问题了不

k t:

回复 jiahe fan:

哇,太感谢了。才发现的

赞(0)
未经允许不得转载:TI中文支持网 » MSP432的串口问题
分享到: 更多 (0)