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