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

msp432 驱动库串口问题

工程师你们好,在使用 tidrivers中的串口部分的时候,我发现无法实现串口的部分接收功能,之前我试过在CC1310上是可以实现的,使用UART_control的时候发现没有一个命令是能够使用的,均返回UART_STATUS_UNDEFINEDCMD,如果是我配置有问题能否给出一个使用事例?不然只能通过定义协议来完成串口通讯就太鸡肋了吧

gaoyang9992006:

http://www.ti.com.cn/tool/cn/mspdriverlib?keyMatch=msp432driverlib&tisearch=Search-CN-Everything

是用的这个里面的库?

MSP432DRIVERLIB:
MSP432 DriverLib for MSP432 devices
这个驱动库里提供的有串口的例子啊。

gaoyang9992006:

给你提供一下这个库里的参考例子

/** -------------------------------------------*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 - Loopback with 24MHz 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 24MHz**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:* software-dl.ti.com/.../index.html*/
const eUSCI_UART_Config uartConfig =
{EUSCI_A_UART_CLOCKSOURCE_SMCLK,// SMCLK Clock Source13,// BRDIV = 130,// UCxBRF = 037,// UCxBRS = 37EUSCI_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 24MHz (upping Vcore) */FlashCtl_setWaitState(FLASH_BANK0, 2);FlashCtl_setWaitState(FLASH_BANK1, 2);MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_24);/* Configuring UART Module */MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig);/* Enable UART module */MAP_UART_enableModule(EUSCI_A0_BASE);/* Enabling interrupts */MAP_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);MAP_Interrupt_enableInterrupt(INT_EUSCIA0);MAP_Interrupt_enableSleepOnIsrExit();while(1){MAP_UART_transmitData(EUSCI_A0_BASE, TXData);MAP_Interrupt_enableSleepOnIsrExit();MAP_PCM_gotoLPM0InterruptSafe();}
}/* EUSCI A0 UART ISR - Echos data back to PC host */
void EUSCIA0_IRQHandler(void)
{uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_BASE);MAP_UART_clearInterruptFlag(EUSCI_A0_BASE, status);if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG){RXData = MAP_UART_receiveData(EUSCI_A0_BASE);if(RXData != TXData)// Check value{MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);while(1);// Trap CPU}TXData++;MAP_Interrupt_disableSleepOnIsrExit();}}

gaoyang9992006:

回复 gaoyang9992006:

/** -------------------------------------------*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|<---- PC*||** Author: Timothy Logan
*******************************************************************************/
/* DriverLib Includes */
#include "driverlib.h"/* Standard Includes */
#include <stdint.h>#include <stdbool.h>/* 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 Source78,// BRDIV = 782,// UCxBRF = 20,// UCxBRS = 0EUSCI_A_UART_NO_PARITY,// No ParityEUSCI_A_UART_LSB_FIRST,// LSB 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 */MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);/* Setting DCO to 12MHz */CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);/* Configuring UART Module */MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig);/* Enable UART module */MAP_UART_enableModule(EUSCI_A0_BASE);/* Enabling interrupts */MAP_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);MAP_Interrupt_enableInterrupt(INT_EUSCIA0);MAP_Interrupt_enableSleepOnIsrExit();MAP_Interrupt_enableMaster();while(1){MAP_PCM_gotoLPM0();}
}/* EUSCI A0 UART ISR - Echoes data back to PC host */
void EUSCIA0_IRQHandler(void)
{uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_BASE);MAP_UART_clearInterruptFlag(EUSCI_A0_BASE, status);if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG){MAP_UART_transmitData(EUSCI_A0_BASE, MAP_UART_receiveData(EUSCI_A0_BASE));}}

huacong tan:

回复 gaoyang9992006:

请问 driverlib 与 tidrivers有什么区别,推荐用哪个进行开发?

Susan Yang:

回复 huacong tan:

推荐您看一下下面帖子给出的回复

e2e.ti.com/…/667978

MSP432的话推荐使用TI Drivers ,它主要是用于SimpleLink平台

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