[英]Using C with the TI EZ430-RF2500 dev chips
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. 在端口侦听的是一个python脚本,该脚本重新组合了有效负载并对其进行了一些处理。
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. 同样,虽然您知道我在学习C的同时就在学习C,所以有关设计的任何建议也都很棒。
Thanks. 谢谢。
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. 由于这似乎是一个无主机系统,因此main()最有可能返回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(). 我假设您没有发布所有代码,因为在无主机环境中,main()中也应该有一个永恒的循环。
Remove all "magic numbers" from the code and replace them with #defined bitmasks or constants. 从代码中删除所有“魔术数字”,并用#defined位掩码或常量替换。
Reduce all code inside interrupts to a minimum. 将中断内的所有代码减至最少。 The optimal interrupt only sets some flags. 最佳中断仅设置一些标志。
Don't use unspecified width (output[]) for arrays/strings. 不要对数组/字符串使用未指定的宽度(output [])。 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'; } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.