如何用MAP_UART_transmitData()函数发送一个字符?这个函数的第二个参数应该是什么?比如要发送一个字符‘m’,第二个参数应该是什么?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
/! 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
第二个参数是发送的数据
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 Source
26, // BRDIV = 26
0, // UCxBRF = 0
111, // UCxBRS = 111
EUSCI_A_UART_NO_PARITY, // No Parity
EUSCI_A_UART_MSB_FIRST, // MSB First
EUSCI_A_UART_ONE_STOP_BIT, // One stop bit
EUSCI_A_UART_MODE, // UART mode
EUSCI_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();
}
}