将 C 语言与 TI EZ430-RF2500 开发芯片结合使用

发布于 2024-11-03 08:38:32 字数 902 浏览 2 评论 0原文

所以我想做的是接收一个数据包并将有效负载打印到串行端口。在端口上监听的是一个 python 脚本,它重新组装有效负载并用它做一些事情。

这是代码:

#include "mrfi.h"
int main(void)
{
  BSP_Init();
  MRFI_Init();
  //Initialize the serial port
  P3SEL    |= 0x30;
  UCA0CTL1  = UCSSEL_2;
  UCA0BR0   = 0x41;
  UCA0BR1   = 0x3;
  UCA0MCTL  = UCBRS_2;                     
  UCA0CTL1 &= ~UCSWRST;
  MRFI_WakeUp();
  MRFI_RxOn();
  __bis_SR_register(GIE+LPM4_bits);
}
//This is run when a packet is received
void MRFI_RxCompleteISR()
{
  uint8_t i;
  P1OUT ^= 0x02;
  mrfiPacket_t packet;
  MRFI_Receive(&packet);
  char output[] = {"                   "};
  for (i=9;i<29;i++) {
    output[i-9]='a';
    if (packet.frame[i]=='\r') {
      output[i-9]='\n';
      output[i-8]='\r';
    }
  }
  TXString(output, (sizeof output));
}

我发送了一个包含测试数据的数据包,但什么也没有。有人有任何见解吗?另外,虽然只是为了让你知道我在这样做的时候正在学习 C,所以任何关于设计的指导也会很棒。

谢谢。

So what I am trying to do is receive a packet and print the payload to the serial port. Listening at the port is a python script that reassembles the payload and does some things with it.

Here is the code:

#include "mrfi.h"
int main(void)
{
  BSP_Init();
  MRFI_Init();
  //Initialize the serial port
  P3SEL    |= 0x30;
  UCA0CTL1  = UCSSEL_2;
  UCA0BR0   = 0x41;
  UCA0BR1   = 0x3;
  UCA0MCTL  = UCBRS_2;                     
  UCA0CTL1 &= ~UCSWRST;
  MRFI_WakeUp();
  MRFI_RxOn();
  __bis_SR_register(GIE+LPM4_bits);
}
//This is run when a packet is received
void MRFI_RxCompleteISR()
{
  uint8_t i;
  P1OUT ^= 0x02;
  mrfiPacket_t packet;
  MRFI_Receive(&packet);
  char output[] = {"                   "};
  for (i=9;i<29;i++) {
    output[i-9]='a';
    if (packet.frame[i]=='\r') {
      output[i-9]='\n';
      output[i-8]='\r';
    }
  }
  TXString(output, (sizeof output));
}

I send a packet with test data but nothing. Anybody have any insights? Also while just so you know I am learning C while I do this, so any pointers on design would also be awesome.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七分※倦醒 2024-11-10 08:38:32

我不知道为什么你的代码不起作用,但这里有一些按要求的设计提示。

  • 由于这似乎是一个无主机系统,因此 main() 很可能返回 void。我假设您没有发布所有代码,因为在无主机中, main() 中也应该有一个永恒循环。

  • 从代码中删除所有“幻数”并将其替换为#定义的位掩码或常量。

  • 将中断内的所有代码减少到最少。最佳中断只设置一些标志。

  • 不要对数组/字符串使用未指定的宽度(输出[])。嵌入式系统设计的目的是使事物具有确定性和固定性。

  • 这是编写该循环的另一种方法的示例。由于我不知道这个程序应该做什么,因此将常量名称替换为有意义的名称。

uint8_t 输出[OUTPUT_N];

memset(输出, ' ', SPACES_N);
输出[OUTPUT_N - 1] = '\0';

for(i=0; i < 某事; i++)
{
  输出[i + A_OFFSET] = 'a';

  if(packet.frame[i + FRAME_OFFSET] == '\r')
  {
    输出[i + CR_OFFSET] = '\r';
    输出[i + LF_OFFSET] = '\n';
  }
}

I don't know why your code isn't working, but here are some design hints as requested.

  • Since this appears to be a hostless system, main() should most likely return void. I assume that you didn't post all of your code, as in a hostless there should also be an eternal loop in main().

  • Remove all "magic numbers" from the code and replace them with #defined bitmasks or constants.

  • Reduce all code inside interrupts to a minimum. The optimal interrupt only sets some flags.

  • Don't use unspecified width (output[]) for arrays/strings. Embedded system design is about making things deterministic and fixed.

  • Here is an example of another way to write that loop. As I have no idea what this program is supposed to do, replace the constant names with something that makes sense.

uint8_t output[OUTPUT_N];

memset(output, ' ', SPACES_N);
output[OUTPUT_N - 1] = '\0';

for(i=0; i < SOMETHING; i++)
{
  output[i + A_OFFSET] = 'a';

  if(packet.frame[i + FRAME_OFFSET] == '\r')
  {
    output[i + CR_OFFSET] = '\r';
    output[i + LF_OFFSET] = '\n';
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文