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

MSP430FR5994: 关于DMA实现UART通信。

Part Number:MSP430FR5994

我根据官方例程更改了一些配置想实现基于MSP430FR5994的UART发送数据,却发现串口助手接受皆为乱码。

以下为我更改后的代码。

#include "driverlib.h"

static char String1[] = { "Hello World\r\n" };

void main (void)
{//Stop Watchdog TimerWDT_A_hold(WDT_A_BASE);GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);PMM_unlockLPM5();//P3.4 = USCI_A0 TXDGPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2,GPIO_PIN0,GPIO_TERNARY_MODULE_FUNCTION);EUSCI_A_UART_initParam param = {0};param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;param.clockPrescalar = 6;param.firstModReg = 13;param.secondModReg = 14;param.parity = EUSCI_A_UART_NO_PARITY;param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;param.uartMode = EUSCI_A_UART_MODE;param.overSampling = EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;if (STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, &param)) {return;}//Enable UART module for operationEUSCI_A_UART_enable(EUSCI_A0_BASE);//Initialize and Setup DMA Channel 0/** Configure DMA channel 0* Configure channel for repeated single transfers* DMA interrupt flag will be set after every 12 transfers* Use DMA Trigger Source 1 (TA0CCR0IFG)* Transfer Byte-to-byte* Trigger Upon Rising Edge of Trigger Source Signal*/DMA_initParam param1 = {0};param1.channelSelect = DMA_CHANNEL_0;param1.transferModeSelect = DMA_TRANSFER_REPEATED_SINGLE;param1.transferSize = (sizeof String1 - 1);param1.triggerSourceSelect = DMA_TRIGGERSOURCE_1;param1.transferUnitSelect = DMA_SIZE_SRCBYTE_DSTBYTE;param1.triggerTypeSelect = DMA_TRIGGER_RISINGEDGE;DMA_init(&param1);/** Configure DMA channel 0* Use String1 as source* Increment source address after every transfer*/DMA_setSrcAddress(DMA_CHANNEL_0,(uint32_t)(uintptr_t)String1,DMA_DIRECTION_INCREMENT);/** Base Address of the DMA Module* Configure DMA channel 0* Use UART TX Buffer as destination* Don't move the destination address after every transfer*/DMA_setDstAddress(DMA_CHANNEL_0,EUSCI_A_UART_getTransmitBufferAddress(EUSCI_A0_BASE),DMA_DIRECTION_UNCHANGED);//Enable transfers on DMA channel 0DMA_enableTransfers(DMA_CHANNEL_0);//For DMA0 triggerTimer_A_initCompareModeParam initCompareModeParam = {0};initCompareModeParam.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_2;initCompareModeParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE;initCompareModeParam.compareOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE;initCompareModeParam.compareValue = 1;Timer_A_initCompareMode(TIMER_A0_BASE, &initCompareModeParam);//Timer sourced by SMCLK, starts in up-modeTimer_A_initUpModeParam initUpModeParam = {0};initUpModeParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;initUpModeParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;initUpModeParam.timerPeriod = 0x8192;initUpModeParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;initUpModeParam.captureCompareInterruptEnable_CCR0_CCIE =TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE;initUpModeParam.timerClear = TIMER_A_SKIP_CLEAR;initUpModeParam.startTimer = true;Timer_A_initUpMode(TIMER_A0_BASE, &initUpModeParam);EUSCI_A_UART_transmitData(EUSCI_A0_BASE,UCA0TXBUF);

////Enter LPM3
//_BIS_SR(LPM3_bits);__delay_cycles(500000);GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
}

Ben Qin:

你好,不做更改例程是否可以通讯?

,

?? ?:

您好,如果只是修改引脚(将例程中P3.3改为P2.0)和库函数名字(将例程中USCI_XXXX改为EUSCI_XXXX)以确保在MSP430FR5994中该例程可行的话,串口接收仍为乱码。

,

Ben Qin:

如果是要使用uart,请参考该代码:

https://dev.ti.com/tirex/explore/node?node=A__ACN5D3ILDAeVpt7cG-tbig__msp430ware__IOGqZri__LATEST

你使用的例程不是FR5994的。

,

?? ?:

你好,我知道例程不是FR5994的,我想修改后移植使用。请问有有通过DMA实现的UART事例代码吗。谢谢

,

Ben Qin:

?? ? 说:请问有有通过DMA实现的UART事例代码吗

这个是没有的。

?? ? 说:修改引脚(将例程中P3.3改为P2.0)和库函数名字(将例程中USCI_XXXX改为EUSCI_XXXX

可能在DMA和USCI寄存器上的配置会有所不同,请检查一下。

,

?? ?:

#include <msp430.h>
#include <stdint.h>
#include "driverlib.h"static uint8_t data = 0x30;int main(void)
{// 停止看门狗定时器WDT_A_hold(WDT_A_BASE);// 配置时钟CS_setDCOFreq(CS_DCORSEL_0,CS_DCOFSEL_0); // 设置DCO频率为12MHzCS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // 设置SMCLK时钟源为DCOCLK// 配置GPIO P1.0为输出,并设置为高电平GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);// 配置GPIO P2.0为UART模块输入功能GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN0,GPIO_TERNARY_MODULE_FUNCTION);// 配置UART模块EUSCI_A_UART_initParam param1 = {0};param1.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;param1.clockPrescalar = 8;param1.firstModReg = 0;param1.secondModReg = 214;param1.parity = EUSCI_A_UART_NO_PARITY;param1.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;param1.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;param1.uartMode = EUSCI_A_UART_MODE;param1.overSampling = EUSCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION;if (STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, &param1)) {return;}while (1){EUSCI_A_UART_transmitData(EUSCI_A0_BASE, data);__delay_cycles(500000);}
}

我将dma代码删除想要简单实现UART发送数据,但接受的数据仍为乱码.请问如何解决.

,

Ben Qin:

用这个例程试一下看能否通讯:

https://dev.ti.com/tirex/explore/node?node=A__ACN5D3ILDAeVpt7cG-tbig__msp430ware__IOGqZri__LATEST

赞(0)
未经允许不得转载:TI中文支持网 » MSP430FR5994: 关于DMA实现UART通信。
分享到: 更多 (0)