将 C 语言与 TI EZ430-RF2500 开发芯片结合使用
所以我想做的是接收一个数据包并将有效负载打印到串行端口。在端口上监听的是一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道为什么你的代码不起作用,但这里有一些按要求的设计提示。
由于这似乎是一个无主机系统,因此 main() 很可能返回 void。我假设您没有发布所有代码,因为在无主机中, main() 中也应该有一个永恒循环。
从代码中删除所有“幻数”并将其替换为#定义的位掩码或常量。
将中断内的所有代码减少到最少。最佳中断只设置一些标志。
不要对数组/字符串使用未指定的宽度(输出[])。嵌入式系统设计的目的是使事物具有确定性和固定性。
这是编写该循环的另一种方法的示例。由于我不知道这个程序应该做什么,因此将常量名称替换为有意义的名称。
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.