2157 views|2 replies

3836

Posts

19

Resources
The OP
 

CC2530 ADC collects external voltage [Copy link]

First Look at Zigbee

To add a smoke sensor module to the Zigbee network, you need to use the CC2530 ADC to sample the analog signal output by the sensor. The following is my own program process for using the CC2530 ADC to collect external voltage.

The following is the configuration of the ADC:

6; ADC_ENABLE_CHANNEL(6); //Enable channel 6 as the sampling channel of ADC ADC_SINGLE_CONVERSION(ADC_REF_AVDD|ADC_12_BIT|ADC_INIT_SINGLE_CONVERSION); // This function is order
to initialize ADC of CC2530 ADC_SINGLE_CONVERSION(ADC_REF_AVDD|ADC_12_BIT|ADC_INIT_SINGLE_CONVERSION);
// This function is order to initialize ADC of CC2530 ADC_SINGLE_CONVERSION(ADC_REF_AVDD|ADC_12_BIT|ADC_INIT_SINGLE_CONVERSION); //This function is order to initialize ADC of CC2530 ADC_SINGLE_CONVERSION( ADC_REF_AVDD|ADC_12_BIT |ADC_INIT_SINGLE_CONVERSION); //This function is order to initialize ADC of CC2530 ADC_SINGLE_CONVERSION( ADC_REF_AVDD| ADC_12_BIT|ADC_INIT_SINGLE_CONVERSION) ; // This function is order to initialize ADC of CC2530 ADC_SINGLE_CONVERSION(ADC_REF_AVDD|ADC_12_BIT|ADC_INIT_SINGLE_CONVERSION ); //This function is order to initialize ADC of CC2530 ADC_SINGLE_CONVERSION (ADC_REF_AVDD|ADC_12_BIT|ADC_INIT_SINGLE_CONVERSION ); //This function is order to initialize ADC of CC2530 ADC_AIN6); //Configure ADC parameters, reference voltage is AVDD5 pin voltage, decimation rate is 512 (12-bit resolution) ADC_SAMPLE_SINGLE(); //Start single sampling while(!(ADCCON1&0x80)) ;//Wait for AD conversion to complete // while ( !ADCIF ); /*Get the result and convert it to voltage*/ ADCREGValue = ADCL>>4;//The program sets the precision to 12 bits, take the lower 4 bits ADCREGValue |= ADCH<<4; //High 8 bits ADCValue = (float)(ADCREGValue/(float)2048)*3.3;//There is a question here, originally the precision is 12 bits, the divisor should be 4096, but 2048 is required to get the accurate value } The following is the configuration of UART0:

























#include<iocc2530.h>
#include"uart.h"

void UARTInit(void)
{

PERCFG = 0; //Configure the IO location of UART0 as spare location 1
P0SEL = 0x3c; //P0.2-PO.5 are set as the port of peripheral function
P2DIR &= ~(3<<6);//Set UART0 to the first priority and UART1 to the second priority,
U0CSR |= (1<<7); //select the mode as UART mode
U0GCR |= 0x09;
U0BAUD |= 59; //19200
UTX0IF = 1; //clear the interrupt flag
U0CSR |= (1<<6); //enable receive bit IEN0 |= 0x84; //enable receive bit
IEN1 |= 0x84;
}
/*************************************************************
note: "length" is the length of one line
**********************************************************/
void UARTSend(char *data,int length)
{
int i;
for(i=0;i<length;i++)
{
U0DBUF = *data;
data++;
while(UTX0IF==0); // complete receive
UTX0IF = 0; //clear the flag
}
U0DBUF =0x0A; //carriage return
while(UTX0IF==0); // complete receive
UTX0IF = 0;
}
The following is the main function:

#include<iocc2530.h>
#include"adc.h"
#include"uart.h"
#include"led.h"
#include<stdio.h>
#include <string.h>

void delay(uint n);
void ClockInit(void);


void main(void)
{
char i = 0;
char TempValue[10];
float average ;
char len;
P1_0 = 0;
ClockInit();
UARTInit();
SET_IO_PORT_DIR(1,0,IO_OUT); //Set LED as a flag for ADC sampling
IO_FUNC_PORT_PIN(1, 0, IO_FUNC_GIO);//INIT_LED();
IEN0 =IEN1=IEN2 =0;

while(1)
{
average = 0.0;
for(i=0;i<64;i++)//Take 64 averages
{
ADInit();
average +=ADCValue;
}
average /=64;
LED();
sprintf(TempValue,"%fV\r",(float)average);//Format the value into a string
len = strlen(TempValue);//Length of the string
UARTSend(TempValue,len);//Send data to the serial port
delay(20000);
}

}

/***************************************************************
Initialize clock parameters
************************************************************/
void ClockInit(void)
{
CLKCONCMD = 0x28; //Set the timer count clock to 1M Hz and the system clock to 32 MHz
while(CLKCONSTA & 0x40); //Wait for the crystal to stabilize
}

The serial port displays the result:

At the beginning, the AD value read out was completely wrong. Finally, it was found that there was a problem with the sampling port on the board. After changing P0.6, the effect was much better. It was probably due to the influence of port multiplexing. . After getting the basic driver, I had to start adding the program to the ZIGBEE module to realize the network. .

This post is from Microcontroller MCU

Latest reply

How to use it in the protocol stack?  Details Published on 2020-2-11 13:11
 

1

Posts

0

Resources
2
 
How to use it in the protocol stack?
This post is from Microcontroller MCU

Comments

The general steps for users to implement a simple wireless data communication are as follows: 1. Networking: Call the networking function and network joining function of the protocol stack to implement network establishment and node joining. 2. Sending: The sending node calls the wireless data sending function of the protocol stack to implement wireless data transmission. 3. Receiving: Receive  Details Published on 2020-2-12 17:18
 
 

3836

Posts

19

Resources
3
 
This seat was published on 2020-2-11 13:11 How to use it in the protocol stack

The general steps for users to implement a simple wireless data communication are:
1. Networking: Call the networking function and network joining function of the protocol stack to implement network establishment and node joining.
2. Sending: The sending node calls the wireless data sending function of the protocol stack to implement wireless data sending.
3. Receiving: The receiving node calls the wireless data receiving function of the protocol stack to implement wireless data reception.

This post is from Microcontroller MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list