Other Parts Discussed in Thread: CC110L
I am trying to transmit and receive the sensor data using CC110L.
When ADC value < X, then transmit 'a'
And when ADC value > X, Then transmit 'b'
On the receiver side i read received data and if that data is 'a' then do something and if that data is 'b' then do something.
But problem is that after sometime receiver reads value like '0', '. '(dot), 'V',etc. And stops receiving data. Then nothing happens.
Here is my code:
Tx Side:-
unsigned long ADCValues[5];
float Result;
struct sControl
{
unsigned char cmd;
};
struct sControl txdata = { 0 };
void AdcIntHandler(void)
{
while(!ADCIntStatus(ADC0_BASE, 0, false))
{
}
ADCIntClear(ADC0_BASE, 0);
ADCSequenceDataGet(ADC0_BASE, 0, ADCValues);
}
void setup()
{
Radio.begin(0x01, CHANNEL_1, POWER_MAX);
SysCtlClockSet(SYSCTL_SYSDIV_10|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlDelay(3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 );
ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH9);
ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END);
ADCIntRegister(ADC0_BASE, 0, AdcIntHandler);
ADCIntEnable(ADC0_BASE, 0);
ADCSequenceEnable(ADC0_BASE, 0);
ADCIntClear(ADC0_BASE, 0);
ADCProcessorTrigger(ADC0_BASE, 0);
}
void loop()
{
Result = (ADCValues[0]*3.34)/4095;
// First Finger
if(Result < 1.69)
{
txdata.cmd = 'a';
}
else if(Result > 1.69)
{
txdata.cmd = 'b';
}
Radio.transmit(ADDRESS_BROADCAST, (unsigned char*)&txdata, sizeof(txdata));
delay(50);
ADCProcessorTrigger(ADC0_BASE, 0);
}
Rx Side:-
unsigned long duty = 135;
struct sControl
{
unsigned char cmd;
};
struct sControl rxdata = { 0 };
void PWMInIt(unsigned long period,unsigned long duty)
{
//Configure PWM Clock divide system clock by 64
SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
// Enable the peripherals used by this program.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); //The Tiva Launchpad has two modules (0 and 1).
//Configure PB6 Pins as PWM
GPIOPinConfigure(GPIO_PD0_M1PWM0);
GPIOPinConfigure(GPIO_PD1_M1PWM1);
GPIOPinConfigure(GPIO_PF1_M1PWM5);
GPIOPinConfigure(GPIO_PF2_M1PWM6);
GPIOPinConfigure(GPIO_PF3_M1PWM7);
GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
//Set the Period (expressed in clock ticks)
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, period);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, period);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, period);
//Set PWM duty
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0,duty);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1,duty);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5,duty);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6,duty);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7,duty);
// Enable the PWM generator
PWMGenEnable(PWM1_BASE, PWM_GEN_0);
PWMGenEnable(PWM1_BASE, PWM_GEN_2);
PWMGenEnable(PWM1_BASE, PWM_GEN_3);
// Turn on the Output pins
PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);
PWMOutputState(PWM1_BASE, PWM_OUT_1_BIT, true);
PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true);
PWMOutputState(PWM1_BASE, PWM_OUT_6_BIT, true);
PWMOutputState(PWM1_BASE, PWM_OUT_7_BIT, true);
}
void setup()
{
Radio.begin(0x01, CHANNEL_1, POWER_MAX);
SysCtlClockSet(SYSCTL_SYSDIV_10|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
PWMInIt(5000,135);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0,duty);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1,duty);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5,duty);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6,duty);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7,duty);
}
void loop()
{
if (Radio.receiverOn((unsigned char*)&rxdata, sizeof(rxdata), 10) > 0)
{
if (rxdata.cmd == 'a')
{
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1,duty);
delay(20);
}
else if (rxdata.cmd == 'b')
{
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1,duty+500);
delay(20);
}
}
}