This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

simpliciti 写入数据到发送时间过长, 求助

Other Parts Discussed in Thread: SIMPLICITI

我用msp-expcc430rf4 开发板, 发现从将数据到通过smpl_send(); 发送,用示波器测得时长200ms。 请问有什么方法可以大大减少这段时间? 还是说可以不用simpliciti,直接用mrfi_radio.c里的函数来发射?

  • 这个时间过长了,同一时刻是否有其他任务?
  • 貌似没有。 协议是simpliciti。 在建立连接之后 就进入while(1)循环,按一下键发送一次。 在进入transmit();前有许多验证,打包数据的步骤,不知道是不是这个原因?

    发送是在主程序的调用了smpl_send,我将原例程注释掉了一些代码, 在while(1)中只留下 msg[0]=1; smpl_send();

    另外,我尝试过修改data rate到500kbps, 从smart rf导出 MDMCFG4(2D),MDMCFG3(3B) 。 也试过修改MCSM0 的值来改变校准的模式。 但是修改后就无法通信。 

    static void linkTo() //linking
    {
    uint8_t msg[1]; //create a group to save message
    //int temperature;
    uint8_t misses, done;

    /* Keep trying to link... */ //??
    while (SMPL_SUCCESS != SMPL_Link(&sLinkID1))
    {
    SPIN_ABOUT_A_SECOND;
    }

    /* sleep until button press... */
    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0);

    RTCPS1CTL |= RT1PSIE;

    while (1)
    {
    /* Send a message when either button pressed */
    __bis_SR_register(LPM3_bits + GIE);
    // __no_operation();

    //if (buttonsPressed & 0x80) // writing message
    //{
    //msg[0] = MESSAGE_BUTTON_PRESSED; //0xff
    //msg[1] = MESSAGE_BUTTON_PRESSED;
    //msg[2] = MESSAGE_BUTTON_PRESSED;
    //msg[3] = MESSAGE_BUTTON_PRESSED;
    //buttonsPressed = 0; //set it back to 0
    //}
    //else // half a second heart beat
    //{
    //HalAdcStartRead(); //quit lmp3 after done
    //__bis_SR_register(LPM0_bits + GIE);
    // HalAdcConvertTempVcc();
    msg[0] = 1;
    //msg[1] = HalAdcGetVcc();
    //temperature = HalAdcGetTempDegF();
    //msg[2] = *( (unsigned char*)(&temperature) ) ;
    //msg[3] = *((unsigned char*)(&temperature)+1) ;
    // }
    //sTid++;
    //msg[4] = (unsigned char) (sTid>>8);
    //msg[5] = (unsigned char) (sTid & 0xFF);

    /* get radio ready...awakens in idle state */
    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);

    /* Set TID and designate which LED to toggle */
    //done = 0;
    //while (!done)
    // {
    //for (misses=0; misses < MISSES_IN_A_ROW; ++misses)
    if (SMPL_SUCCESS == SMPL_Send(sLinkID1, msg, sizeof(msg))); //send message
    // break;
    // if (misses == MISSES_IN_A_ROW)
    // {
    /* This can only happen if we are supporting Frequency Agility and we
    * appear not to have received an acknowledge. Do a scan.
    */
    //ioctlScanChan_t scan;
    //freqEntry_t freq[NWK_FREQ_TBL_SIZE];

    //scan.freq = freq;
    // SMPL_Ioctl(IOCTL_OBJ_FREQ, IOCTL_ACT_SCAN, &scan);
    /* If we now know the channel (number == 1) change to it. In any case
    * try it all again. If we changed channels we should get an ack now.
    */
    // if (1 == scan.numChan)
    // {
    // SMPL_Ioctl(IOCTL_OBJ_FREQ, IOCTL_ACT_SET, freq);
    //}
    //}
    // else
    //{
    /* Got the ack. We're done. */
    //done = 1;
    //}
    }

    /* radio back to sleep */
    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0); //special void, manage the i/o

    }
    //}



  • #include "bsp.h"
    #include "mrfi.h"
    #include "nwk_types.h"
    #include "nwk_api.h"
    #include "bsp_leds.h"
    #include "bsp_buttons.h"


    #include "hal_leds.h"
    #include "hal_buttons.h"
    #include "hal_adc.h"

    #define MESSAGE_BUTTON_PRESSED 0xFF
    #define MESSAGE_HEART_BEAT 0xEE


    #define USER_EXPERIENCE_FIRMWARE_MODE 0x00
    #define USER_EXPERIENCE_PRODUCTION_TEST_MODE 0xFF


    /*-----------------------------------------------------------------------------
    *
    *
    * Packet construct:
    * Byte 0: Message Type [HeartBeat or ButtonPressed]
    * Byte 1: Content Vcc MESSAGE_BUTTON_PRESSED
    * Byte 2: Content Temp_MSB MESSAGE_BUTTON_PRESSED
    * Byte 3: Content Temp_LSB MESSAGE_BUTTON_PRESSED
    * Byte 4: PacketID MSB
    * Byte 5: PacketID LSB
    *

    *---------------------------------------------------------------------------- */

    unsigned char FIRMWARE_MODE = 0xFF;

    extern volatile unsigned char buttonsPressed;
    static void linkTo(void);



    static uint16_t sTid = 0;

    /* Callback handler */
    static uint8_t sCB(linkID_t);

    static volatile uint8_t sPeerFrameSem = 0;
    static linkID_t sLinkID1 = 0;

    #define SPIN_ABOUT_A_SECOND NWK_DELAY(1000)
    #define SPIN_ABOUT_A_QUARTER_SECOND NWK_DELAY(250)

    /* How many times to try a Tx and miss an acknowledge before doing a scan */
    #define MISSES_IN_A_ROW 2

    void MspExp430F5137RxUserExperience (void)
    {
    addr_t lAddr; //adress

    BSP_Init(); //initialize
    //

    //HalAdcInit();
    //HalAdcSetQuitFromISR( 1 );
    //SetupRtc();
    //P1DIR |= BIT0;
    P1DIR=0XFF;
    P1OUT=0;
    P2DIR=0XFF;
    P2OUT=0;
    P3DIR=0XFF;
    P3OUT=0;
    PJDIR=0XFF;
    PJOUT=0;

    P1REN |= BIT7;
    P1OUT |= BIT7;
    P1DIR &= ~(BIT7);
    P1IES |= BIT7;//
    P1IE |= BIT7 ;

    P1IFG &= ~BIT7;
    _EINT();

    // Create a unique address based off the device's wafer ID &
    // X/Y coordinates

    lAddr.addr[0] = (*(uint8_t *)0x01A0E) ^ (*(uint8_t *)0x01A0A);
    lAddr.addr[1] = (*(uint8_t *)0x01A0F) ^ (*(uint8_t *)0x01A0B);
    lAddr.addr[2] = (*(uint8_t *)0x01A10) ^ (*(uint8_t *)0x01A0C);
    lAddr.addr[3] = (*(uint8_t *)0x01A11) ^ (*(uint8_t *)0x01A0D);

    SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr); //generate an address



    /* Keep trying to join (a side effect of successful initialization) until
    * successful. Toggle LEDS to indicate that joining has not occurred.
    */
    while (SMPL_SUCCESS != SMPL_Init(sCB))//join //wait until smpl_init reture smpl_success,
    //can this change to interrupt way???
    {

    SPIN_ABOUT_A_SECOND;
    }

    /* LEDs on solid to indicate successful join. */


    /* Unconditional link to AP which is listening due to successful join. */
    linkTo();

    while (1) ;
    }



    static void linkTo() //linking
    {
    uint8_t msg[1]; //create a group to save message
    //int temperature;
    uint8_t misses, done;

    /* Keep trying to link... */ //??
    while (SMPL_SUCCESS != SMPL_Link(&sLinkID1))
    {
    SPIN_ABOUT_A_SECOND;
    }



    /* sleep until button press... */
    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0);

    RTCPS1CTL |= RT1PSIE;

    while (1)
    {
    /* Send a message when either button pressed */
    __bis_SR_register(LPM3_bits + GIE);
    // __no_operation();

    //if (buttonsPressed & 0x80) // writing message
    //{
    //msg[0] = MESSAGE_BUTTON_PRESSED; //0xff
    //msg[1] = MESSAGE_BUTTON_PRESSED;
    //msg[2] = MESSAGE_BUTTON_PRESSED;
    //msg[3] = MESSAGE_BUTTON_PRESSED;
    //buttonsPressed = 0; //set it back to 0
    //}
    //else // half a second heart beat
    //{
    //HalAdcStartRead(); //quit lmp3 after done
    //__bis_SR_register(LPM0_bits + GIE);
    // HalAdcConvertTempVcc();
    msg[0] = 1;
    //msg[1] = HalAdcGetVcc();
    //temperature = HalAdcGetTempDegF();
    //msg[2] = *( (unsigned char*)(&temperature) ) ;
    //msg[3] = *((unsigned char*)(&temperature)+1) ;
    // }
    //sTid++;
    //msg[4] = (unsigned char) (sTid>>8);
    //msg[5] = (unsigned char) (sTid & 0xFF);

    /* get radio ready...awakens in idle state */
    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);

    /* Set TID and designate which LED to toggle */
    //done = 0;
    //while (!done)
    // {
    //for (misses=0; misses < MISSES_IN_A_ROW; ++misses)
    if (SMPL_SUCCESS == SMPL_Send(sLinkID1, msg, sizeof(msg))); //send message
    // break;
    // if (misses == MISSES_IN_A_ROW)
    // {
    /* This can only happen if we are supporting Frequency Agility and we
    * appear not to have received an acknowledge. Do a scan.
    */
    //ioctlScanChan_t scan;
    //freqEntry_t freq[NWK_FREQ_TBL_SIZE];

    //scan.freq = freq;
    // SMPL_Ioctl(IOCTL_OBJ_FREQ, IOCTL_ACT_SCAN, &scan);
    /* If we now know the channel (number == 1) change to it. In any case
    * try it all again. If we changed channels we should get an ack now.
    */
    // if (1 == scan.numChan)
    // {
    // SMPL_Ioctl(IOCTL_OBJ_FREQ, IOCTL_ACT_SET, freq);
    //}
    //}
    // else
    //{
    /* Got the ack. We're done. */
    //done = 1;
    //}
    }

    /* radio back to sleep */
    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0); //special void, manage the i/o

    }
    //}


    static uint8_t sCB(linkID_t lid)
    {
    if (lid == sLinkID1)
    {
    sPeerFrameSem++;
    return 0;
    }

    return 1;
    }



    /**********************************************************************//**
    * @brief Initializes the RTC module for interval mode
    *
    *
    *
    * @param none
    *
    * @return none
    *
    * void SetupRtc(void)
    {
    RTCCTL01 = RTCMODE + RTCBCD + RTCHOLD + RTCTEV_1;



    RTCCTL01 &= ~RTCHOLD;

    RTCPS1CTL = RT1IP_7; // Interrupt freq: .5Hz
    // RTCPS1CTL = RT1IP_6; // Interrupt freq: 1Hz
    // RTCPS1CTL = RT1IP_5; // Interrupt freq: 2Hz
    //RTCPS1CTL = RT1IP_4; // Interrupt freq: 4Hz



    //RTCPS0CTL = RT0IP_7; // Interrupt freq: 128hz

    //RTCCTL0 |= RTCTEVIE; // Enable interrupt
    }

    #pragma vector=RTC_VECTOR
    __interrupt void RTC_ISR(void)
    {
    switch (RTCIV)
    {
    default:
    __bic_SR_register_on_exit(LPM3_bits);
    }
    }
    *************************************************************************/
    #pragma vector=RTC_VECTOR
    __interrupt void RTC_ISR(void)
    {
    P1OUT ^=BIT0;

    }

    #pragma vector = PORT1_VECTOR
    __interrupt void PORT_1(void) {
    __delay_cycles(1000);
    if((P1IN & BIT7) == 0){
    __bic_SR_register_on_exit(LPM3_bits);
    }
    P1IFG &= ~BIT7;
    }