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.
工具/软件:Code Composer Studio
你好
我在企业中从事一个项目、我有带 MSP430 MCU 的 TI Launchpad 套件和一个模拟评估模块- BOOSTXL-PGA460。
我使用在 Code compose studio 中制作的程序与 PGA460进行通信。
为了开发程序、我快速使用 了驱动程序库中软件 MSP430ware 中的程序、并根据我的情况进行调整。
使用的微控制器是 MSP430F5529。
以下是我用于程序的代码:
//
//! 此示例展示了如何将 UART 模块配置为环回
//! 验证接收到的数据是否已发送。
//!
//! MSP430F5438A
//! --------
//! RST -| P3.4/UCA0TXD|---|
//! | | ||
//! | | ||
//! | P3.5/UCA0RXD|---|
//! | |
//!
//!
//! 此示例使用以下外设和 I/O 信号。 您必须执行的操作
//! 查看这些内容并根据您自己的董事会的需要进行更改:
//! UART 外设
//! - GPIO 端口外设(用于 UART 引脚)
//! UCA0TXD
//! UCA0RXD
//!
//! 此示例使用以下中断处理程序。 来使用该示例
//! 在您自己的应用程序中、您必须将这些中断处理程序添加到
//! 矢量表。
//! - USCI_A0_Vector。
//
#include "driverlib.h"
//
//
//选择波特率
//
//
#define BAUD_RATE 9600 // JS--
//#define BAUD_RATE 2400 //JS++// nota:se EU alterar esta variável
// o d é bito binário observado no osciloscópio é sempre 9600bps - para já vou deixar como está ó n
//
//
//初始化接收到的数据
//
//
uint8_t receivedData = 0x00;
//
//
//初始化传输数据
//
//
uint8_t transmitData = 0x00;
uint8_t check = 0;
uint8_t i1 = 0;//JS++
uint8_t i2 = 0;//JS++
uint8_t i3 = 0;//JS++
void main (void)
{
//停止 WDT
WDT_A_HOLD (WDT_A_base);
GPIO_setAsOutputPin (GPIO_PORT_P2、GPIO_PIN2);// PD como saída
GPIO_setAsOutputPin (GPIO_PORT_P7、GPIO_PIN4);//Porto SEL COMO saída
GPIO_setOutputLowOnPin (GPIO_PORT_P2、GPIO_PIN2);//coloca Pino 为零
GPIO_setOutputLowOnPin (GPIO_PORT_P7、GPIO_PIN4);//coloca Pino 为零
// FIM JS++
//JS--
GPIO_setPeripheralModuleFunctionInputPin (
GPIO_PORT_P3、
GPIO_PIN3 + GPIO_PIN4
);
//FIM JS++
//FIM JS++
P3.4中的//上拉电阻 器// JS++
GPIO_setAsInputPinWithPullUpResistor (GPIO_PORT_P3、GPIO_PIN4);//JS++
USCI_A_UART_initParam param ={0};
param.selectClockSource = USCI_A_UART_CLOCKSOURCE_SMCLK;
param.clockPrescalar = 109;
param.firstModReg = 0;
param.secondModReg = 2;
param.parity = USCI_A_uart_no_parity;
param.msborLsbFirst = USCI_A_UART_LSB_FIRST;
// param.numberofStopBits = USCI_A_UART_One_stop_bit;//JS--
param.numerofStopBits = USCI_A_UART_Two_stop_bits;//JS--
param.uartMode = USCI_A_UART_MODE;
param.oversaming= USCI_A_UART_LOW_FREQUENCY BAUDRATE_generation;
if (STATUS_FAIL = USCI_A_UART_init (USCI_A0_BASE、¶m)){
返回;
}
//启用 UART 模块以进行操作
USCI_A_UART_ENABLE (USCI_A0_BASE);
//启用接收中断
USCI_A_UART_clearInterrupt (USCI_A0_BASE、
USCI_A_UART_receive_interrupt);
USCI_A_UART_enableInterrupt (USCI_A0_BASE、
USCI_A_UART_receive_interrupt);
_enable_interrupt ();//JS--
transmitData = 0x55;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
transmitData = 0x0A;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
transmitData = 0x68;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
transmitData = 0x42;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
transmitData = 0x4B;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
for (i2=0;i2<20;i2++)
{
// for (i3=0;i3<255;i3++)
// {
对于(i1=0;i1<255;i1++);//JS++
// }
}
transmitData = 0x55;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
transmitData = 0x09;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
transmitData = 0x68;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
transmitData = 0x8E;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
USCI_A_UART_clearInterrupt (USCI_A0_BASE、
USCI_A_UART_Receive_interrupt_FLAG);
while (1)
{
transmitData = 0x55;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
transmitData = 0x09;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
transmitData = 0x68;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
transmitData = 0x8E;
//将数据加载到缓冲区中
USCI_A_UART_transmitData (USCI_A0_BASE、
传输数据);
for (i2=0;i2<20;i2++)
{
// for (i3=0;i3<255;i3++)
// {
对于(i1=0;i1<255;i1++);//JS++
// }
}
}
}
#if defined (__TI_Compiler_version__)|| Defined (__IAR_systems_ICC__)
#pragma vector=USCI_A0_Vector
_interrupt void USCI_A0_ISR (void)
#Elif defined (_GNU_)
void __attribute__((中断(USCI_A0_Vector)) USCI_A0_ISR (void)
其他
错误编译器不受支持!
#endif
{
I3 = 0;
开关(_偶数_IN_RANGE (UCA0IV、4)){
//Vector 2 - RXIFG
案例2:
接收数据= USCI_A_UART_receiveData (USCI_A0_BASE);
// if (!(receivedData == transmitData) //检查值//JS--
// { //JS--
// while (1); //JS--
// } //JS--
支票=1;
中断;
默认值:break;
}
}
//---- 我的程序结束
在调试模式下、我在_interrupt void USCI_A0_ISR (void)旋转内放置了一个断点(在指令 i3=0中)、程序从不会在这里停止。
我分别发送 RXD 和 TXD (在 PGA460上)中看到的信号:
最后一个信号是 PGA 的 UART 发送到 MSP430的信号、其中包含我在微控制器中从未检测到的3个字节。 为什么?
请帮帮我。
何塞·西莫斯
您需要使接收到的数据变得易失性、以便编译器知道它可能随时更改。 如果不使其变为易失性,编译器就会假定它在 main()中保持不变。
您好!
我将变量 volatile 放在 main 之前并运行程序。 程序不 会在中断中的断点停止、其中 i1=0:
volatile uint8_t receivedData;
//
//
//初始化传输数据
//
//
uint8_t transmitData = 0x00;
uint8_t check = 0;
uint8_t i1 = 0;//JS++
uint8_t i2 = 0;//JS++
uint8_t i3 = 0;//JS++
void main (void)
{
…
中断中的代码
#if defined (__TI_Compiler_version__)|| Defined (__IAR_systems_ICC__)
#pragma vector=USCI_A0_Vector
_interrupt void USCI_A0_ISR (void)
#Elif defined (_GNU_)
void __attribute__((中断(USCI_A0_Vector)) USCI_A0_ISR (void)
其他
错误编译器不受支持!
#endif
{
I3 = 0;
开关(_偶数_IN_RANGE (UCA0IV、4)){
//Vector 2 - RXIFG
案例2:
接收数据= USCI_A_UART_receiveData (USCI_A0_BASE);
// if (!(receivedData == transmitData) //检查值//JS--
// { //JS--
// while (1); //JS--
// } //JS--
支票=1;
中断;
默认值:break;
}
}
我再次请求帮助。
何塞·西莫斯
我还尝试在中断中仅放置易失性变量、但它不起作用(程序不会在中断中的指令 i4=0中停止-请参阅更改)
#if defined (__TI_Compiler_version__)|| Defined (__IAR_systems_ICC__)
#pragma vector=USCI_A0_Vector
_interrupt void USCI_A0_ISR (void)
#Elif defined (_GNU_)
void __attribute__((中断(USCI_A0_Vector)) USCI_A0_ISR (void)
其他
错误编译器不受支持!
#endif
{
volatile uint8_t receivedData;
volatile uint8_t i4;
I4=0;
//i=0 ;
开关(_偶数_IN_RANGE (UCA0IV、4)){
//Vector 2 - RXIFG
案例2:
接收数据= USCI_A_UART_receiveData (USCI_A0_BASE);
// if (!(receivedData == transmitData) //检查值//JS--
// { //JS--
// while (1); //JS--
// } //JS--
支票=1;
中断;
默认值:break;
}
}
何塞·西莫斯
后退一步、尝试 TiRex 的环回示例。
您好、Jose、
在您描述的情况下 、它没有进入中断服务函数。 您可以参考以下代码、也可以使用 P3.3和 P3.4端口。
http://dev.ti.com/tirex/explore/node?node=AO.y3PbPXQlPwKTmMax5Sw__IOGqZri__LATEST
此致
Johnson
谢谢、这个建议解决了我的问题。
感谢你的建议。 我用另一个示例解决了我的问题:
http://dev.ti.com/tirex/explore/node?node=AO.y3PbPXQlPwKTmMax5Sw__IOGqZri__LATEST
Jos é Simões í a
您好、Jose、
恭喜! 我很高兴在 E2E 上见到您、 请稍后直接在 E2E 上咨询您是否有任何问题。
此致
Johnson