使用ez430 RF2500建立RX / TX通信,以显示是否按下按钮

时间:2014-05-04 00:30:21

标签: embedded msp430 iar

我是一名机械工程师,拥有MatLab和Arduino的大部分编码经验。我正在使用EZ430-RF2500板为我的顶点项目建立更低电流的通信。我正在使用IAR Embedded Workbench IDE 7.0

代码的一般目标是让发射器板以大约1Hz发送周期性数据包,当且仅当按下板载按钮(Pin1.2)时。然后,如果接收器板正在接收数据包,则它将打开LED(Pout1.1),但如果在一定时间内没有接收到大于1s(例如3秒)的数据包,它将关闭。接收器和发射器都具有相同的编码,但使用不同的端口。

这段代码非常类似于教程中的TX / RX谈话示例(enter link description here)我成功了但是我无法让我的代码正常运行。

如果您有兴趣,可以参考。该项目的目的是开发一种汽车座椅传感器,以防止婴儿被车辆遗忘。因此,当接收器位于监护人钥匙链上时,发射器将被放置在座位上。

我已尝试使用此代码的不同版本的混合结果。如果有一些明显的错误,我很抱歉,我对这个编译器和电路板很新。我一直在使用的代码如下。

    // If one button (p1.2) is pushed, the other boards red LED (p1.0) 
//Set Ports1.2 as input, set ports 1.0,1.1 (on board LEDS) as outputs

//GOAL: Set port 2.0 as input from Arduino, set port 2.1,2.2 as output for LED and Alarm
//Keep functionality of push button and turn on red LED(p1.0) for testing
//GOAL: Read port 2.0
//GOAL: If port 2.0 is HIGH, send packet
//GOAL: If packet is received, set Pout2.1,Pout2.2 as HIGH to activate LED/buzzer (for now)
//GOAL: Eventually add RSSI to determine if activate alarm. 




#include "mrfi.h"
#include "radios/family1/mrfi_spi.h"
int main(void)
{
  BSP_Init();           //*** Sets p1.0,1.1 as outputs, sets p1.2 as input, init MCLK at 8MHz, disables watchdog
  P1REN |= 0x04;        //*** 0100 Enables pull resistors (Needed for inputs)
  P1IE  |= 0x04;            //*** 0100 Enables interupts

//Eventual GOAL:
//  P2DIR |= 0x06;      //*** 0110 Pout2.1,Pout2.2 as outputs, all other inputs (Pin2.0)
//  P2REN |= 0x01;      //*** 0001 Enables pull resistor for Pin2.0   
//  P2OUT |= 0x03;      //*** 0001 Sets Pout2.1,Pout2.2 as Low, Enables Pull resistor for Pin2.0
        //*** May need to move P2OUT into another void

  MRFI_Init();
  MRFI_WakeUp();
  MRFI_RxOn();
  __bis_SR_register(GIE+LPM4_bits);
}
void MRFI_RxCompleteISR()   //*** If receives packet, turn on when packet is received, turn off if no packet is received after x seconds
                //*** GOAL: If packet is received, turn LED on, if packet is not received for certain time, turn LED off
{               //*** Eneventually would need to add RSSI to determine if alarm should sound


   int i;
   int j;
    P1OUT |= 0x02;
   for (i=0;i<10000;i++) {
 for (j=0;j<10;i++) {
      __no_operation();

  }
      __no_operation();

  }
   P1OUT ^= 0x02;
}  





#pragma vector=PORT1_VECTOR
__interrupt void Port_1 (void)

{               //*** On-Board actions
P1IFG &= 0x04;      //***  
P1OUT |= 0x00;  
  while (1) 
  {
if (P1IN == 0x04) {
  int i;
  mrfiPacket_t packet;                  //*** Initiate packet
  packet.frame[0]=8+20;
  MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED);      //*** Send Packet
  P1OUT ^= 0x01;                    //*** Toggle Pout1.0 (RED LED) for Debugging
    for (i=0;i<30000;i++) 
    {               //*** Wait for next cycle
      __no_operation();
    }
   }
  } 
}

0 个答案:

没有答案