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.

[参考译文] MSP430FR2355:通过 UART 接收9个字节? -RXBuffer 如何工作?

Guru**** 2517600 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1160166/msp430fr2355-receiving-9-bytes-over-uart---how-does-the-rxbuffer-work

器件型号:MSP430FR2355

您好、再说一次、

我的项目包括一个 C02传感器(MH-Z19C)、它通过 UART 以9字节的形式发送 CO2浓度(https://www.winsen-sensor.com/d/files/infrared-gas-sensor/mh-z19c-pins-type-co2-manual-ver1_0.pdf 第6页)。 但是、我将进入 isue、"Registers"选项卡告诉我、RX 缓冲区中有一个值、而我的示波器清楚地显示 MSP430和传感器发送正确的信号、如果我尝试从缓冲区中调整该值、则不起作用。 我假设我的代码是错误的、因为寄存器 UCA0RXBUF 中有一个值。

我已经将 TX 线缆从传感器连接到 MSP430 (1.6)上的 RX 引脚、并将 TX 连接到 RX 相应地。
波特率(9600)适合 MSP 和传感器。

`s 我的代码:

________________________________________________________________

#include
#include
#include "eusci_a_uart.h"

//计数变量
volatile uint16_t i;
volatile uint16_t k;
volatile uint16_t h;

//发送到传感器的字节
const char byte0 = 0xFF;
const char byte1 = 0x01;
const char 字节2 = 0x86;
const char byte37 = 0x00;
const char 字节8 = 0x79;

volatile char rbyte0;

//延迟功能
void delay_ms (无符号 int ms)

   while (ms)
   {
       _DELAY_CYCLLES (1000);1/1000表示1MHz、16000表示16MHz
       MS---;
   }


void main (void){
    //停止看门狗计时器
   WDT_A_HOLD (WDT_A_base);
   
   //接收函数的变量
   volatile currchar Data;
   volatile uint16_t RecCount = 0;
   volatile char ReccData[9];
   volatile char oldData = 0x00;
   UCA0CTLW0 |= UCSWRST;
   GPIO_setPeripheralModuleFunctionOutputPin (GPIO_PORT_P1、GPIO_PIN7、
   GPIO_PRIMARY_MODULE_FUNCTION);
   GPIO_setPeripheralModuleFunctionInputPin (GPIO_PORT_P1、GPIO_PIN6、
   GPIO_PRIMARY_MODULE_FUNCTION);
   //激活时钟
   GPIO_setPeripheralModuleFunctionOutputPin (GPIO_PORT_P2、GPIO_PIN6、
   GPIO_secondary 模块功能);
   GPIO_setPeripheralModuleFunctionInputPin (GPIO_PORT_P2、GPIO_PIN7、
   GPIO_secondary 模块功能);
   PMM_unlockLPM5 ();

   EUSCI_A_UART_initParam eUSCI_initParam ={
                                             EUSCI_A_UART_CLOCKSOURCE_SMCLK、// selectClockSource
                                             6、//预分频 UCBRx
                                             13、   // firstModReg UCBRFx
                                             34、//次级调制器 UCBRSx
                                             EUSCI_A_UART_even 奇偶校验、EUSCI_A_UART_LSB_FIRST、
                                             EUSCI_A_UART_One_stop_bit、EUSCI_A_UART_AUTOMODE_BAUDRAT_DETECning_mode、
                                             EUSCI_A_UART_overSAMPLING_BAUDRATE_generation
                                         };
   
   EUSCI_A_UART_init (EUSCI_A0_BASE、&eUSCI_initParam);
   EUSCI_A_UART_ENABLE (EUSCI_A0_BASE);
   EUSCI_A_UART_enableInterrupt (EUSCI_A0_BASE、
           EUSCI_A_UART_receive_interrupt);

   while (1)
   {
       //发送将 CO2数据发送到传感器的请求
               EUSCI_A_UART_transmitData (EUSCI_A0_BASE、字节0);
               EUSCI_A_UART_transmitData (EUSCI_A0_BASE、字节1);
               EUSCI_A_UART_transmitData (EUSCI_A0_BASE、字节2);
               对于(k = 0;k<5;k++){
                   EUSCI_A_UART_transmitData (EUSCI_A0_BASE、字节37);//字节3至7为空
               }
               EUSCI_A_UART_transmitData (EUSCI_A0_BASE、字节8);
               //接收来自传感器的数据(9字节)
               while (重新计数<= 8)
               {
                   当前数据= OFS_UCAxRXBUF_L;
                   if (currData!= oldData)
                   {
                       ReccData[RecCount]=当前数据;
                       oldData = currData;
                   }
                   RecCount++;
               }
               RecCount=0;
               delay_ms (15);
   }

____________________________________________________________________________________________

蓝色部分显示了我的问题:每次缓冲区中有一个新值时、都应将其添加到 ReccData[]数组中。 但是、它是空的。 我也是三人

有人能告诉我如何解决这个问题、或者至少能给我一个提示吗? 提前非常感谢! (我也对问题的低层次感到非常抱歉、但我已经搜索了网络和多本手册。)

此致、

Julius。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    对于第一个近似值、您似乎没有给事情足够的时间。 您的计算机比 UART 快得多、因此虽然您应该能够像这样发送两个字节、但我想第二个字节会被占用。 (发送数据不会阻塞)。 接收也是如此。 使用中断要好得多:

    http://www.simplyembedded.org/tutorials/msp430-uart/

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    RXBUF 中总是有"东西"、所以你不能在那里查看是否有一个 Rx 字节到达。 您需要检查 UCA0IFG:UCRXIFG。

    我建议:

    1) 1)删除此行:

     EUSCI_A_UART_enableInterrupt (EUSCI_A0_BASE、 EUSCI_A_UART_receive_interrupt);

    您不使用中断、启用中断将导致 Driverlib 执行错误操作。

    2) 2)替换:

    >                    currData = OFS_UCAxRXBUF_L;

    使用

    >                    currData = EUSCI_A_UART_receiveData (EUSCI_A0_BASE);

    该函数将通过检查 UCRXIFG 为您执行互锁。