开发者

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.

Here is the code:

#include "mrfi.h"
int main(vo开发者_如何学Pythonid)
{
  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.


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';
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜