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.

CC430F5137: How to package the temperature data before transmiting?

Part Number: CC430F5137
Other Parts Discussed in Thread: CC1101

I am a beginner in rf.

First, I get the temperature through the internal temperature sensor. Then, how to package it and transmit it?

Can I directly put the data into the Tx buffer? Or I need to code something?

For example, I had tried the code below, but it seems that the tx buffer only accepts hex data like "0xaa" but not numbers like "1".

#include "RF_Toggle_LED_Demo.h"

#define PACKET_LEN (0x05) // PACKET_LEN <= 61
#define RSSI_IDX (PACKET_LEN) // Index of appended RSSI
#define CRC_LQI_IDX (PACKET_LEN+1) // Index of appended LQI, checksum 校验码 packet之后一位
#define CRC_OK (BIT7) // CRC_OK bit
#define PATABLE_VAL (0x51) // 0 dBm output

extern RF_SETTINGS rfSettings;

unsigned char packetReceived;
unsigned char packetTransmit;

unsigned char RxBuffer[PACKET_LEN+2];
unsigned char RxBufferLength = 0;
const unsigned char TxBuffer[PACKET_LEN]= {};
unsigned char buttonPressed = 0;
unsigned int i = 0;

unsigned char transmitting = 0;
unsigned char receiving = 0;
void adc_start(void);
void adc_int(void);
long temp;
volatile long IntDegC;

void main( void )
{

WDTCTL = WDTPW + WDTHOLD;

ResetRadioCore();
InitRadio();
ReceiveOff();
adc_int();
adc_start();

IntDegC=TxBuffer[1];

Transmit( (unsigned char*)TxBuffer, sizeof TxBuffer);

}

void InitRadio(void)
{
// Set the High-Power Mode Request Enable bit so LPM3 can be entered
// with active radio enabled
PMMCTL0_H = 0xA5;
PMMCTL0_L |= PMMHPMRE_L;
PMMCTL0_H = 0x00;

WriteRfSettings(&rfSettings);

WriteSinglePATable(PATABLE_VAL);
}

void Transmit(unsigned char *buffer, unsigned char length)
{
RF1AIES |= BIT9;
RF1AIFG &= ~BIT9; // Clear pending interrupts
RF1AIE |= BIT9; // Enable TX end-of-packet interrupt

WriteBurstReg(RF_TXFIFOWR, buffer, length);

Strobe( RF_STX ); // Strobe STX
}

#pragma vector=CC1101_VECTOR
__interrupt void CC1101_ISR(void)
{
switch(__even_in_range(RF1AIV,32)) // Prioritizing Radio Core Interrupt
{
case 0: break; // No RF core interrupt pending
case 2: break; // RFIFG0
case 4: break; // RFIFG1
case 6: break; // RFIFG2
case 8: break; // RFIFG3
case 10: break; // RFIFG4
case 12: break; // RFIFG5
case 14: break; // RFIFG6
case 16: break; // RFIFG7
case 18: break; // RFIFG8
case 20: // RFIFG9

RF1AIE &= ~BIT9; // Disable TX end-of-packet interrupt
//P3OUT &= ~BIT6; // Turn off LED after Transmit

// trap
break;
case 22: break; // RFIFG10
case 24: break; // RFIFG11
case 26: break; // RFIFG12
case 28: break; // RFIFG13
case 30: break; // RFIFG14
case 32: break; // RFIFG15
}
__bic_SR_register_on_exit(LPM3_bits);
}

void adc_int()
{
REFCTL0 &= ~REFMSTR;
ADC12CTL0 = ADC12SHT0_8 + ADC12REFON +ADC12ON;
ADC12CTL1 = ADC12SHP;
ADC12MCTL0 = ADC12SREF_1 +ADC12INCH_10;
ADC12IE = 0X001;
__delay_cycles(75);
ADC12CTL0 |= ADC12ENC;
}

void adc_start()
{
ADC12CTL0 |= ADC12SC;
__bis_SR_register(LPM4_bits + GIE);
IntDegC= ((temp-1855)*667)/4096;
}

#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR(void)
{
switch(__even_in_range(ADC12IV,34))
{
case 6:
temp=ADC12MEM0;
__bis_SR_register_on_exit(LPM4_bits);
break;
default: break;
}
}

  • It is up to you how you want to code things. If the only thing you want to transmit is temperature, the payload (TX FIFIO) data can contain only the representation of temperature (the reason I write it like that: Do you just have a integer or do you have a decimal number?)

    Why are you writing it this way?
    IntDegC=TxBuffer[1];

    Doesn't IntDegC contain the temperature you actually want to send?

    0xAA vs '1' as you started the post with is a c question, it depends on the types used etc.
  • Ok. Sorry for my mess coding. Now I describe it again in brief.

    Step1. I get the temperature by ADC, ...... IntDegC= ((temp-1855)*667)/4096; so the IntDegC is a variable which saves the temperature right? And it is an integer, right? For example,  IntDegC=25.

    Step2.  Build a  table:   unsigned char Txbuffer[1];

                 Put temperature into table:  Txbuffer[0]=IntDegC;

                 Transmit it:        Transmit( (unsigned char*)TxBuffer, sizeof TxBuffer);

    Are these steps right?

    I had tried to insert a breakpoint to check the IntDegC but it shows cannot read.

    Thanks

  • The concept looks correct. Where in the code do you try to put the breakpoint to watch IntDegC?

    The expression for IntDegC could return a negative number and it is not given that the results from the expression is an integer. But that is a c question and fundamental c is not covered on this forum.
  • I insert a  breakpoint below the adc_start().    Then add the IntDegC to the expression.

  • Have you been able to debug this further?
  • Since my ultimate goal is to send the temperature data.  I think the temperature measurement is no problem. So, the key is to send the data. For example, temperature=25 which is an integer.  

    The original TxBuffer in this example is {OXAA,0XBB,0XCC,0XDD,0XEE}, I can see them at the receiver through ccs debugger.  However, if I change it to {1,2,3,4,5}, I can't see them.   Is that because it can only send data in hex form?  If it is, how to transform the integer to the hex?

    #include "RF_Toggle_LED_Demo.h"

    #define PACKET_LEN (0x05) // PACKET_LEN <= 61

    #define RSSI_IDX (PACKET_LEN) // Index of appended RSSI

    #define CRC_LQI_IDX (PACKET_LEN+1) // Index of appended LQI, checksum

    #define CRC_OK (BIT7) // CRC_OK bit

    #define PATABLE_VAL (0x51) // 0 dBm output

    extern RF_SETTINGS rfSettings;

    unsigned char packetReceived;

    unsigned char packetTransmit;

    unsigned char RxBuffer[PACKET_LEN+2];

    unsigned char RxBufferLength = 0;

    const unsigned char TxBuffer[PACKET_LEN]= {1,2,3,4,5};

    unsigned char buttonPressed = 0;

    unsigned int i = 0;

    unsigned char transmitting = 0;

    unsigned char receiving = 0;

    void main( void )

    {

    // Stop watchdog timer to prevent time out reset

    WDTCTL = WDTPW + WDTHOLD;

    // Increase PMMCOREV level to 2 for proper radio operation

    SetVCore(2);

    ResetRadioCore();

    InitRadio();

    InitButtonLeds();

    ReceiveOn();

    receiving = 1;

    while (1)

    {

    __bis_SR_register( LPM3_bits + GIE );

    __no_operation();

    if (buttonPressed) // Process a button press->transmit

    {

    P3OUT |= BIT6; // Pulse LED during Transmit

    buttonPressed = 0;

    P1IFG = 0;

    ReceiveOff();

    receiving = 0;

    Transmit( (unsigned char*)TxBuffer, sizeof TxBuffer);

    transmitting = 1;

    P1IE |= BIT7; // Re-enable button press

    }

    else if(!transmitting)

    {

    ReceiveOn();

    receiving = 1;

    }

    }

    }

    void InitButtonLeds(void)

    {

    // Set up the button as interruptible

    P1DIR &= ~BIT7;

    P1REN |= BIT7;

    P1IES &= BIT7;

    P1IFG = 0;

    P1OUT |= BIT7;

    P1IE |= BIT7;

    // Initialize Port J

    PJOUT = 0x00;

    PJDIR = 0xFF;

    // Set up LEDs

    P1OUT &= ~BIT0;

    P1DIR |= BIT0;

    P3OUT &= ~BIT6;

    P3DIR |= BIT6;

    }

    void InitRadio(void)

    {

    // Set the High-Power Mode Request Enable bit so LPM3 can be entered

    // with active radio enabled

    PMMCTL0_H = 0xA5;

    PMMCTL0_L |= PMMHPMRE_L;

    PMMCTL0_H = 0x00;

    WriteRfSettings(&rfSettings);

    WriteSinglePATable(PATABLE_VAL);

    }

    #pragma vector=PORT1_VECTOR

    __interrupt void PORT1_ISR(void)

    {

    switch(__even_in_range(P1IV, 16))

    {

    case 0: break;

    case 2: break; // P1.0 IFG

    case 4: break; // P1.1 IFG

    case 6: break; // P1.2 IFG

    case 8: break; // P1.3 IFG

    case 10: break; // P1.4 IFG

    case 12: break; // P1.5 IFG

    case 14: break; // P1.6 IFG

    case 16: // P1.7 IFG

    P1IE = 0; // Debounce by disabling buttons

    buttonPressed = 1;

    __bic_SR_register_on_exit(LPM3_bits); // Exit active

    break;

    }

    }

    void Transmit(unsigned char *buffer, unsigned char length)

    {

    RF1AIES |= BIT9;

    RF1AIFG &= ~BIT9; // Clear pending interrupts

    RF1AIE |= BIT9; // Enable TX end-of-packet interrupt

    WriteBurstReg(RF_TXFIFOWR, buffer, length);

    Strobe( RF_STX ); // Strobe STX

    }

    void ReceiveOn(void)

    {

    RF1AIES |= BIT9; // Falling edge of RFIFG9

    RF1AIFG &= ~BIT9; // Clear a pending interrupt

    RF1AIE |= BIT9; // Enable the interrupt

    // Radio is in IDLE following a TX, so strobe SRX to enter Receive Mode

    Strobe( RF_SRX );

    }

    void ReceiveOff(void)

    {

    RF1AIE &= ~BIT9; // Disable RX interrupts

    RF1AIFG &= ~BIT9; // Clear pending IFG

    // It is possible that ReceiveOff is called while radio is receiving a packet.

    // Therefore, it is necessary to flush the RX FIFO after issuing IDLE strobe

    // such that the RXFIFO is empty prior to receiving a packet.

    Strobe( RF_SIDLE );

    Strobe( RF_SFRX );

    }

    #pragma vector=CC1101_VECTOR

    __interrupt void CC1101_ISR(void)

    {

    switch(__even_in_range(RF1AIV,32)) // Prioritizing Radio Core Interrupt

    {

    case 0: break; // No RF core interrupt pending

    case 2: break; // RFIFG0

    case 4: break; // RFIFG1

    case 6: break; // RFIFG2

    case 8: break; // RFIFG3

    case 10: break; // RFIFG4

    case 12: break; // RFIFG5

    case 14: break; // RFIFG6

    case 16: break; // RFIFG7

    case 18: break; // RFIFG8

    case 20: // RFIFG9

    if(receiving) // RX end of packet

    {

    // Read the length byte from the FIFO

    RxBufferLength = ReadSingleReg( RXBYTES );

    ReadBurstReg(RF_RXFIFORD, RxBuffer, RxBufferLength);

    // Stop here to see contents of RxBuffer

    __no_operation();

    // Check the CRC results

    if(RxBuffer[CRC_LQI_IDX] & CRC_OK)

    P1OUT ^= BIT0; // Toggle LED1

    }

    else if(transmitting) // TX end of packet

    {

    RF1AIE &= ~BIT9; // Disable TX end-of-packet interrupt

    P3OUT &= ~BIT6; // Turn off LED after Transmit

    transmitting = 0;

    }

    else while(1); // trap

    break;

    case 22: break; // RFIFG10

    case 24: break; // RFIFG11

    case 26: break; // RFIFG12

    case 28: break; // RFIFG13

    case 30: break; // RFIFG14

    case 32: break; // RFIFG15

    }

    __bic_SR_register_on_exit(LPM3_bits);

    }

  • Please select the "insert code..." option when posting code for readability.

    To see if I understand you correctly:

    If you have

    const unsigned char TxBuffer[PACKET_LEN]= {1,2,3,4,5};

    it does not work but if you write:

    const unsigned char TxBuffer[PACKET_LEN]= {0xAA, 0xBB, 0xCC, 0xDD, 0xEE};

    it works?
  • As long as it is hex, it works.
  • Do you have fixed or variable packet length? If the latter the first byte will be the length.
  • It' ok now. Thanks