TI CC2530組網(wǎng)演練(BasicRF-無線控制燈的亮滅)_第1頁
TI CC2530組網(wǎng)演練(BasicRF-無線控制燈的亮滅)_第2頁
TI CC2530組網(wǎng)演練(BasicRF-無線控制燈的亮滅)_第3頁
TI CC2530組網(wǎng)演練(BasicRF-無線控制燈的亮滅)_第4頁
TI CC2530組網(wǎng)演練(BasicRF-無線控制燈的亮滅)_第5頁
已閱讀5頁,還剩29頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

TICC2530組網(wǎng)演練(BasicRF——無線控制燈的亮滅)本文將從兩個方面著手,一方面分析TI官網(wǎng)下載的CC2530BasicRF源碼中的無線發(fā)送,另一方面根據(jù)自己的板子來修改實現(xiàn)無線發(fā)送控制燈的亮滅。一、CC2530BasicRFBasicRF由TI公司提供,它包含了IEEE802.15.4標(biāo)準(zhǔn)的數(shù)據(jù)包的收發(fā)功能但并沒有使用到協(xié)議棧,它僅僅是讓兩個節(jié)點進(jìn)行簡單的通信,也就是說BasicRF僅僅是包含著IEEE802.15.4標(biāo)準(zhǔn)的一小部分而已。其主要特點有:1、不會自動加入?yún)f(xié)議、也不會自動掃描其他節(jié)點、同時也沒有組網(wǎng)指示燈(LED3)2、沒有協(xié)議棧里面所說的協(xié)調(diào)器、路由器或者終端的區(qū)分,節(jié)點的地位都是相等的3、沒有自動重發(fā)的功能BasicRFlayer為雙向無線通信提供了一個簡單的協(xié)議,通過這個協(xié)議能夠進(jìn)行數(shù)據(jù)的發(fā)送和接收。BasicRF還提供了安全所使用的CCM-64身份驗證和數(shù)據(jù)加密,它的安全性在工程文件里定義SECURITY_CCM了。在Project->Option->C/C++Compiler->Preprocess里面就選擇,本次實驗并不是什么高度機(jī)密,所有在SECURITY_CCM前面帶X了。BasicRF的工作過程:啟動、發(fā)射、接收工程文件分析宏:MCU_IO_DIR_OUTPUT(port,pin);[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?/***********************************************************************

*

MCU_IO_DIR_OUTPUT(port,

pin);將端口port對應(yīng)的pin位設(shè)置為輸出(高電平)

*

##為連接符,如port=0,pin=1,即P0DIR

|=

BM(1);

**********************************************************************/

#define

MCU_IO_DIR_OUTPUT(port,

pin)

MCU_IO_DIR_OUTPUT_PREP(port,

pin)

#define

MCU_IO_DIR_OUTPUT_PREP(port,

pin)

st(

P##port##DIR

|=

BM(pin);

)

#define

st(x)

do

{

x

}

while

(__LINE__

==

-1)

#define

BM(n)

(1

<<

(n))

MCU_IO_DIR_INPUT(port,pin);[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?/***********************************************************************

*

MCU_IO_DIR_INPUT(port,

pin);將端口port對應(yīng)的pin位設(shè)置為輸入(低電平)

**********************************************************************/

#define

MCU_IO_DIR_INPUT(port,

pin)

MCU_IO_DIR_INPUT_PREP(port,

pin)

#define

MCU_IO_DIR_INPUT_PREP(port,

pin)

st(

P##port##DIR

|=

~BM(pin);

)

#define

st(x)

do

{

x

}

while

(__LINE__

==

-1)

#define

BM(n)

(1

<<

(n))

MCU_IO_GET(port,pin);[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?/***********************************************************************

*

MCU_IO_GET(port,

pin);獲取端口port的對應(yīng)位pin的電平值

**********************************************************************/

#define

MCU_IO_GET(port,

pin)

MCU_IO_GET_PREP(port,

pin)

#define

MCU_IO_GET_PREP(port,

pin)

(P##port##

&

BM(pin))

#define

BM(n)

(1

<<

(n))

MCU_IO_TGL(port,pin);[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?/***********************************************************************

*

MCU_IO_TGL(port,

pin);將端口port的對應(yīng)位pin的電平值設(shè)置為相反電平

**********************************************************************/

#define

MCU_IO_TGL(port,

pin)

MCU_IO_TGL_PREP(port,

pin)

#define

MCU_IO_TGL_PREP(port,

pin)

st(

P##port##_##pin##

^=

1;

)

#define

st(x)

do

{

x

}

while

(__LINE__

==

-1)

MCU_IO_SET_LOW(port,pin);[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?/***********************************************************************

*

MCU_IO_SET_LOW(port,

pin);將端口port的對應(yīng)位pin設(shè)置為低電平

**********************************************************************/

#define

MCU_IO_SET_LOW(port,

pin)

MCU_IO_SET_LOW_PREP(port,

pin)

#define

MCU_IO_SET_LOW_PREP(port,

pin)

st(

P##port##_##pin##

=

0;

)

#define

st(x)

do

{

x

}

while

(__LINE__

==

-1)

MCU_IO_SET_HIGH(port,pin);[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?/***********************************************************************

*

MCU_IO_SET_HIGH(port,

pin);將端口port的對應(yīng)位pin設(shè)置為高電平

**********************************************************************/

#define

MCU_IO_SET_HIGH(port,

pin)

MCU_IO_SET_HIGH_PREP(port,

pin)

#define

MCU_IO_SET_HIGH_PREP(port,

pin)

st(

P##port##_##pin##

=

1;

)

#define

st(x)

do

{

x

}

while

(__LINE__

==

-1)

MCU_IO_SET(port,pin,val);[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?/***********************************************************************

*

MCU_IO_SET(port,

pin,

val);將端口port的對應(yīng)位pin的電平值設(shè)置為val

**********************************************************************/

#define

MCU_IO_SET(port,

pin,

val)

MCU_IO_SET_PREP(port,

pin,

val)

#define

MCU_IO_SET_PREP(port,

pin,

val)

st(

P##port##_##pin##

=

val;

)

#define

st(x)

do

{

x

}

while

(__LINE__

==

-1)

MCU_IO_OUTPUT(port,pin,val);[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?/***********************************************************************

*

MCU_IO_OUTPUT(port,

pin,

val);將端口port的對應(yīng)位pin的電平值設(shè)置為val

*

并且將此IO設(shè)置為通用IO,以及設(shè)置為輸出

**********************************************************************/

#define

MCU_IO_OUTPUT(port,

pin,

val)

MCU_IO_OUTPUT_PREP(port,

pin,

val)

#define

MCU_IO_OUTPUT_PREP(port,

pin,

val)

st(

P##port##SEL

&=

~BM(pin);

\

P##port##_##pin##

=

val;

\

P##port##DIR

|=

BM(pin);

)

#define

st(x)

do

{

x

}

while

(__LINE__

==

-1)

MCU_IO_OUTPUT(port,pin,func);[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?/***********************************************************************

*

MCU_IO_INPUT(port,

pin,

func);將端口port的對應(yīng)位pin的設(shè)置為通用IO

*

并將此IO口設(shè)置為func輸入模式:上拉、下拉、默認(rèn)模式(三態(tài))

*

func指的是IO口的輸入模式:MCU_IO_PULLUP、MCU_IO_PULLDOWN、默認(rèn)模式

**********************************************************************/

#define

MCU_IO_INPUT(port,

pin,

func)

MCU_IO_INPUT_PREP(port,

pin,

func)

#define

MCU_IO_INPUT_PREP(port,

pin,

func)

st(

P##port##SEL

&=

~BM(pin);

\

P##port##DIR

&=

~BM(pin);

\

switch

(func)

{

\

case

MCU_IO_PULLUP:

\

P##port##INP

&=

~BM(pin);

\

P2INP

&=

~BM(port

+

5);

\

break;

\

case

MCU_IO_PULLDOWN:

\

P##port##INP

&=

~BM(pin);

\

P2INP

|=

BM(port

+

5);

\

break;

\

default:

\

P##port##INP

|=

BM(pin);

\

break;

}

)

#define

st(x)

do

{

x

}

while

(__LINE__

==

-1)

MCU_IO_PERIPHERAL(port,pin);[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?/***********************************************************************

*

MCU_IO_PERIPHERAL(port,

pin);將端口port的對應(yīng)位pin的設(shè)置為外設(shè)功能

**********************************************************************/

#define

MCU_IO_PERIPHERAL(port,

pin)

MCU_IO_PERIPHERAL_PREP(port,

pin)

#define

MCU_IO_PERIPHERAL_PREP(port,

pin)

st(

P##port##SEL

|=

BM(pin);

)

#define

BM(n)

(1

<<

(n))

light_switch.c——main函數(shù)[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?<pre

name="code"

class="cpp">void

main(void)

{

uint8

appMode

=

LIGHT;

//

Config

basicRF

basicRfConfig.panId

=

PAN_ID;

//網(wǎng)絡(luò)地址,0x2007

basicRfConfig.channel

=

RF_CHANNEL;

//通道,25

//

2.4

GHz

RF

channel

basicRfConfig.ackRequest

=

TRUE;

//是否應(yīng)當(dāng),

1

#ifdef

SECURITY_CCM

basicRfConfig.securityKey

=

key;

#endif

//

Initalise

board

peripherals

/*

*

一些GPIO口初始化,包括以下LEDs和Buttons初始化

*

將LEDs(P0_0、P1_1、P1_4、P0_1)設(shè)置為輸出、Buttons(P0_1)設(shè)置為輸入模式且為三態(tài)輸入模式

*/

halBoardInit();

/*

*

多方向按鍵初始化,不用管

*/

halJoystickInit();

//

Initalise

hal_rf

硬件抽象層rf初始化

if(halRfInit()==FAILED)

{

HAL_ASSERT(FALSE);

}

//

Indicate

that

device

is

powered

將按鍵1設(shè)置為高電平,并將狀態(tài)設(shè)置為1

/*

switch

(id)

{

case

1:

HAL_LED_SET_1();

break;

case

2:

HAL_LED_SET_2();

break;

case

3:

HAL_LED_SET_3();

break;

case

4:

HAL_LED_SET_4();

led4State=1;

break;

default:

break;

}

#define

HAL_LED_SET_1()

MCU_IO_SET_HIGH(HAL_BOARD_IO_LED_1_PORT,

HAL_BOARD_IO_LED_1_PIN)

#define

HAL_LED_SET_2()

MCU_IO_SET_HIGH(HAL_BOARD_IO_LED_2_PORT,

HAL_BOARD_IO_LED_2_PIN)

#define

HAL_LED_SET_3()

MCU_IO_SET_HIGH(HAL_BOARD_IO_LED_3_PORT,

HAL_BOARD_IO_LED_3_PIN)

#define

HAL_LED_SET_4()

MCU_IO_SET_HIGH(HAL_BOARD_IO_LED_4_PORT,

HAL_BOARD_IO_LED_4_PIN)

#define

HAL_BOARD_IO_LED_1_PORT

1

//

Green

#define

HAL_BOARD_IO_LED_1_PIN

0

#define

HAL_BOARD_IO_LED_2_PORT

1

//

Red

#define

HAL_BOARD_IO_LED_2_PIN

1

#define

HAL_BOARD_IO_LED_3_PORT

1

//

Yellow

#define

HAL_BOARD_IO_LED_3_PIN

4

#define

HAL_BOARD_IO_LED_4_PORT

0

//

Orange

#define

HAL_BOARD_IO_LED_4_PIN

1

*/

halLedSet(1);

//

Print

Logo

and

splash

screen

on

LCD

utilPrintLogo("Light

Switch");

//有關(guān)LCD的函數(shù)不管

//

Wait

for

user

to

press

S1

to

enter

menu

while

(halButtonPushed()!=HAL_BUTTON_1);

halMcuWaitMs(350);

halLcdClear();

//lcd清屏,不用管

//

Set

application

role

appMode

=

appSelectMode();

//模式選擇

halLcdClear();

//

Transmitter

application

if(appMode

==

SWITCH)

{

//

No

return

from

here

appSwitch();

}

//

Receiver

application

else

if(appMode

==

LIGHT)

{

//

No

return

from

here

appLight();

}

//

Role

is

undefined.

This

code

should

not

be

reached

HAL_ASSERT(FALSE);

}

hal_board.c——halBoardInit()函數(shù)實現(xiàn)[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?void

halBoardInit(void)

{

//mcu初始化,設(shè)置系統(tǒng)時鐘

halMcuInit();

//

LEDs

#ifdef

SRF05EB_VERSION_1_3

//

SmartRF05EB

rev

1.3

has

only

one

accessible

LED

MCU_IO_DIR_OUTPUT(HAL_BOARD_IO_LED_1_PORT,

HAL_BOARD_IO_LED_1_PIN);

HAL_LED_CLR_1();

#else

/*

*

LEDs(P0_0、P1_1、P1_4、P0_1)設(shè)置為輸出

*/

MCU_IO_DIR_OUTPUT(HAL_BOARD_IO_LED_1_PORT,

HAL_BOARD_IO_LED_1_PIN);

HAL_LED_CLR_1();

MCU_IO_DIR_OUTPUT(HAL_BOARD_IO_LED_2_PORT,

HAL_BOARD_IO_LED_2_PIN);

HAL_LED_CLR_2();

MCU_IO_DIR_OUTPUT(HAL_BOARD_IO_LED_3_PORT,

HAL_BOARD_IO_LED_3_PIN);

HAL_LED_CLR_3();

MCU_IO_DIR_OUTPUT(HAL_BOARD_IO_LED_4_PORT,

HAL_BOARD_IO_LED_4_PIN);

HAL_LED_CLR_4();

#endif

//

Buttons

/*

*

Buttons(P0_1)設(shè)置為輸入模式且為三態(tài)輸入模式

*/

MCU_IO_INPUT(HAL_BOARD_IO_BTN_1_PORT,

HAL_BOARD_IO_BTN_1_PIN,

MCU_IO_TRISTATE);

//

Joystick

push

input

多方向按鍵

三態(tài)輸入模式

MCU_IO_INPUT(HAL_BOARD_IO_JOY_MOVE_PORT,

HAL_BOARD_IO_JOY_MOVE_PIN,

\

MCU_IO_TRISTATE);

//

Analog

input

adc模擬,設(shè)置對應(yīng)引腳為外部功能

MCU_IO_PERIPHERAL(HAL_BOARD_IO_JOYSTICK_ADC_PORT,

HAL_BOARD_IO_JOYSTICK_ADC_PIN);

//lcd初始化

halLcdSpiInit();

halLcdInit();

/*

*

halIntOn:開啟全局中斷-->HAL_INT_ON-->st(

EA

=

1;

)

*/

halIntOn();

}

hal_rf.c——halRfInit()函數(shù)實現(xiàn)[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?uint8

halRfInit(void)

{

//

Enable

auto

ack

and

auto

crc

/*

*

#define

FRMCTRL0

XREG(

0x6189

)

*

#define

XREG(addr)

((unsigned

char

volatile

__xdata

*)

0)[addr]

*

即往寄存器FRMCTRL0(0x6189)寫數(shù)據(jù)

*

#define

AUTO_ACK

0x20

*

#define

AUTO_CRC

0x40

*/

FRMCTRL0

|=

(AUTO_ACK

|

AUTO_CRC);

//

Recommended

RX

settings

/*

*

#define

TXFILTCFG

XREG(

0x61FA

)

*

#define

AGCCTRL1

XREG(

0x61B2

)

*

#define

FSCAL1

XREG(

0x61AE

)

*/

TXFILTCFG

=

0x09;

//調(diào)整AGC目標(biāo)值

AGCCTRL1

=

0x15;

//設(shè)置

TX

抗混疊過濾器以獲得合適的貸款

FSCAL1

=

0x00;

//和默認(rèn)設(shè)置比較,降低VCO泄露大約3dB。推薦默認(rèn)設(shè)置以獲得最佳

EVM

//

Enable

random

generator

->

Not

implemented

yet

//

Enable

CC2591

with

High

Gain

Mode

halPaLnaInit();//在CC2530中此函數(shù)沒有做任何操作

//

Enable

RX

interrupt

使能接收中斷

/*

*

RFIRQM0

|=

BV(6);

*

IEN2

|=

BV(0);

*

#define

BV(n)

(1

<<

(n))

*/

halRfEnableRxInterrupt();

return

SUCCESS;

}

light_switch.c——appSwitch()、appLight()函數(shù)實現(xiàn)[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?static

void

appSwitch()

{

//lcd有關(guān)操作不用管

halLcdWriteLine(HAL_LCD_LINE_1,

"Switch");

halLcdWriteLine(HAL_LCD_LINE_2,

"Joystick

Push");

halLcdWriteLine(HAL_LCD_LINE_3,

"Send

Command");

#ifdef

ASSY_EXP4618_CC2420

//沒有定義

halLcdClearLine(1);

halLcdWriteSymbol(HAL_LCD_SYMBOL_TX,

1);

#endif

pTxData[0]

=

LIGHT_TOGGLE_CMD;

//

#define

LIGHT_TOGGLE_CMD

0

//被傳輸?shù)拈_關(guān)命令

//

Initialize

BasicRF

basicRfConfig.myAddr

=

SWITCH_ADDR;

//#define

SWITCH_ADDR

0x2520

//開關(guān)節(jié)點的地址

if(basicRfInit(&basicRfConfig)==FAILED)

{

HAL_ASSERT(FALSE);

}

//

Keep

Receiver

off

when

not

needed

to

save

power

關(guān)閉接收

basicRfReceiveOff();

//

Main

loop

while

(TRUE)

{

if(

halJoystickPushed()

)

{

//判斷多方向按鍵是否按下

basicRfSendPacket(LIGHT_ADDR,

pTxData,

APP_PAYLOAD_LENGTH);//發(fā)送命令

//

Put

MCU

to

sleep.

It

will

wake

up

on

joystick

interrupt

halIntOff();

halMcuSetLowPowerMode(HAL_MCU_LPM_3);

//

Will

turn

on

global

//

interrupt

enable

halIntOn();

}

}

}

[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?static

void

appLight()

{

halLcdWriteLine(HAL_LCD_LINE_1,

"Light");

halLcdWriteLine(HAL_LCD_LINE_2,

"Ready");

#ifdef

ASSY_EXP4618_CC2420

halLcdClearLine(1);

halLcdWriteSymbol(HAL_LCD_SYMBOL_RX,

1);

#endif

//

Initialize

BasicRF

basicRfConfig.myAddr

=

LIGHT_ADDR;

//#define

LIGHT_ADDR

0xBEEF

//電燈節(jié)點的地址

if(basicRfInit(&basicRfConfig)==FAILED)

{

HAL_ASSERT(FALSE);

}

//使能接收

basicRfReceiveOn();

//

Main

loop

while

(TRUE)

{

while(!basicRfPacketIsReady());//檢查是否收到一個新數(shù)據(jù)包

if(basicRfReceive(pRxData,

APP_PAYLOAD_LENGTH,

NULL)>0)

{

//收到的數(shù)據(jù)復(fù)制到pRxData中

if(pRxData[0]

==

LIGHT_TOGGLE_CMD)

{

halLedToggle(1);

//將其對應(yīng)的LED1設(shè)置相反電平

}

}

}

}

basic_rf.h——basicRfCfg_t結(jié)構(gòu)體定義[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?typedef

struct

{

uint16

myAddr;

//16位短地址(就是節(jié)點地址)

uint16

panId;

//節(jié)點的PAN(個人局域網(wǎng))

ID

uint8

channel;

//RF通道(必須在11-26之間)

uint8

ackRequest;

//目標(biāo)確定就置true

#ifdef

SECURITY_CCM

//是否加密

uint8*

securityKey;

uint8*

securityNonce;

#endif

}

<strong>basicRfCfg_t</strong>;

basic_rf.c——basicRfPacketIsReady()、basicRfReceive()、basicRfSendPacket()函數(shù)實現(xiàn)[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?uint8

basicRfPacketIsReady(void)

{

/*

*

static

basicRfRxInfo_t

rxi=

{

0xFF

};

//

Make

sure

sequence

numbers

are

*

確保數(shù)據(jù)序列號為0xFF

*/

return

rxi.isReady;

}

[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?uint8

basicRfReceive(uint8*

pRxData,

uint8

len,

int16*

pRssi)

{

//

Accessing

shared

variables

->

this

is

a

critical

region

//

Critical

region

start

halIntOff();

memcpy(pRxData,

rxi.pPayload,

min(rxi.length,

len));

if(pRssi

!=

NULL)

{

if(rxi.rssi

<

128){

*pRssi

=

rxi.rssi

-

halRfGetRssiOffset();

}

else{

*pRssi

=

(rxi.rssi

-

256)

-

halRfGetRssiOffset();

}

}

rxi.isReady

=

FALSE;

halIntOn();

//

Critical

region

end

return

min(rxi.length,

len);

}

[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?uint8

basicRfSendPacket(uint16

destAddr,

uint8*

pPayload,

uint8

length)

{

uint8

mpduLength;

uint8

status;

//

Turn

on

receiver

if

its

not

on

if(!txState.receiveOn)

{

halRfReceiveOn();

}

//

Check

packet

length

length

=

min(length,

BASIC_RF_MAX_PAYLOAD_SIZE);

//

Wait

until

the

transceiver

is

idle

halRfWaitTransceiverReady();

//

Turn

off

RX

frame

done

interrupt

to

avoid

interference

on

the

SPI

interface

halRfDisableRxInterrupt();

mpduLength

=

basicRfBuildMpdu(destAddr,

pPayload,

length);

#ifdef

SECURITY_CCM

halRfWriteTxBufSecure(txMpdu,

mpduLength,

length,

BASIC_RF_LEN_AUTH,

BASIC_RF_SECURITY_M);

txState.frameCounter++;

//

Increment

frame

counter

field

#else

halRfWriteTxBuf(txMpdu,

mpduLength);

#endif

//

Turn

on

RX

frame

done

interrupt

for

ACK

reception

halRfEnableRxInterrupt();

//

Send

frame

with

CCA.

return

FAILED

if

not

successful

if(halRfTransmit()

!=

SUCCESS)

{

status

=

FAILED;

}

//

Wait

for

the

acknowledge

to

be

received,

if

any

if

(pConfig->ackRequest)

{

txState.ackReceived

=

FALSE;

//

We'll

enter

RX

automatically,

so

just

wait

until

we

can

be

sure

that

the

ack

reception

should

have

finished

//

The

timeout

consists

of

a

12-symbol

turnaround

time,

the

ack

packet

duration,

and

a

small

margin

halMcuWaitUs((12

*

BASIC_RF_SYMBOL_DURATION)

+

(BASIC_RF_ACK_DURATION)

+

(2

*

BASIC_RF_SYMBOL_DURATION)

+

10);

//

If

an

acknowledgment

has

been

received

(by

RxFrmDoneIsr),

the

ackReceived

flag

should

be

set

status

=

txState.ackReceived

?

SUCCESS

:

FAILED;

}

else

{

status

=

SUCCESS;

}

//

Turn

off

the

receiver

if

it

should

not

continue

to

be

enabled

if

(!txState.receiveOn)

{

halRfReceiveOff();

}

if(status

==

SUCCESS)

{

txState.txSeqNumber++;

}

#ifdef

SECURITY_CCM

halRfIncNonceTx();

//

Increment

nonce

value

#endif

return

status;

}

二、無線控制燈的亮滅實現(xiàn):通過按S1鍵來控制另一個板子上的LED1燈的亮滅1、電路原理圖2、分析既然要實現(xiàn)通過按S1鍵來控制另一個板子上的LED1燈的亮滅,那么首先需要將被控制版上的LED1對應(yīng)的P1_0設(shè)置為輸出模式,且當(dāng)P1_為低電平時LED1等亮,為高電平時LED1等滅。以及將控制板上的S1對應(yīng)的P0_4設(shè)置為輸入模式,當(dāng)檢測到P0_4引腳為低電平表示按鍵S1被按下,反之為高電平時表示按鍵S1沒有被按下。由于CC2530中的無線發(fā)送功能是內(nèi)置的,不是外設(shè),即TI官網(wǎng)下載的CC2530BasicRF中的無線發(fā)送代碼仍然適合我的板子,不需要怎么修改。這樣,將按鍵S1端作為無線發(fā)送的發(fā)送端,而LED1端作為無線發(fā)送的接收端。根據(jù)上面的代碼分析,來實現(xiàn)自己的無線點燈,代碼修改如下:(1)、首先根據(jù)上面的分析,可以知道TI官網(wǎng)的CC2530BasicRF中有4個LED,其分別是P0_0、P1_1、P1_4、P0_1,而我的板子中有個兩個LED燈,分別是LED1(P1_0)、LED2(P1_1)。所有需要修改LED1的引腳定義,修改hal_board.h對應(yīng)LEDs的引腳定義處。修改前:[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?//

LEDs

#define

HAL_BOARD_IO_LED_1_PORT

0

//

Green

#define

HAL_BOARD_IO_LED_1_PIN

0

#define

HAL_BOARD_IO_LED_2_PORT

1

//

Red

#define

HAL_BOARD_IO_LED_2_PIN

1

#define

HAL_BOARD_IO_LED_3_PORT

1

//

Yellow

#define

HAL_BOARD_IO_LED_3_PIN

4

#define

HAL_BOARD_IO_LED_4_PORT

0

//

Orange

#define

HAL_BOARD_IO_LED_4_PIN

1

修改后:[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?//

LEDs

#define

HAL_BOARD_IO_LED_1_PORT

1

//

Green******************LED1

#define

HAL_BOARD_IO_LED_1_PIN

0

#define

HAL_BOARD_IO_LED_2_PORT

1

//

Red********************LED2

#define

HAL_BOARD_IO_LED_2_PIN

1

#define

HAL_BOARD_IO_LED_3_PORT

1

//

Yellow

#define

HAL_BOARD_IO_LED_3_PIN

4

#define

HAL_BOARD_IO_LED_4_PORT

0

//

Orange

#define

HAL_BOARD_IO_LED_4_PIN

1

(2)、首先根據(jù)上面的分析,可以知道TI官網(wǎng)的CC2530BasicRF中有1個按鍵S1,對應(yīng)的引腳為P0_1,而我板子上的按鍵S1引腳為P0_4。所有需要修改LED1的引腳定義,修改hal_board.h對應(yīng)Buttons的引腳定義處。修改前:[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?//

Buttons

#define

HAL_BOARD_IO_BTN_1_PORT

0

//

Button

S1

#define

HAL_BOARD_IO_BTN_1_PIN

1

修改后:[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?//

Buttons

#define

HAL_BOARD_IO_BTN_1_PORT

0

//

Button

S1

#define

HAL_BOARD_IO_BTN_1_PIN

4

(3)、將板子的LED1和LED2燈,設(shè)置為關(guān)閉狀態(tài),修改light_switch.c的main函數(shù),在halLedSet(1)上面添加一行代碼:halLesSet(2);[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?halLedSet(2);

//關(guān)閉LED2

halLedSet(1);

//關(guān)閉LED1

(4)、根據(jù)上面的light_switch.c中的appSwitch()函數(shù)分析,在其函數(shù)內(nèi)死循環(huán)中,它是去判斷多方向按鍵是否按下,而實際需要判斷自己板子的單方向按鍵是否按下。

修改前:[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?while

(TRUE)

{

if(

halJoystickPushed()

)

{

//判斷多方向按鍵是否按下

basicRfSendPacket(LIGHT_ADDR,

pTxData,

APP_PAYLOAD_LENGTH);//發(fā)送命令

//

Put

MCU

to

sleep.

It

will

wake

up

on

joystick

interrupt

halIntOff();

halMcuSetLowPowerMode(HAL_MCU_LPM_3);

//

Will

turn

on

global

//

interrupt

enable

halIntOn();

}

}

修改后:[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?while

(TRUE)

{

//if(

halJoystickPushed()

)

{

//判斷多方向按鍵是否按下

if

(halButtonPushed()){

basicRfSendPacket(LIGHT_ADDR,

pTxData,

APP_PAYLOAD_LENGTH);//發(fā)送命令

//

Put

MCU

to

sleep.

It

will

wake

up

on

joystick

interrupt

halIntOff();

halMcuSetLowPowerMode(HAL_MCU_LPM_3);

//

Will

turn

on

global

//

interrupt

enable

halIntOn();

}

}

(5)、將light_switch.c中的main函數(shù)中一些有關(guān)lcd屏的操作、模式選擇、等待用戶按鍵等代碼注釋掉,注釋如下:[cpp]

\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?#if

0

//

Print

Logo

and

splash

screen

on

LCD

utilPrintLogo("Light

Switch");

//有關(guān)LCD的函數(shù)不管

//

Wait

for

user

to

press

S1

to

enter

menu

while

(halButtonPushed()!=HAL_BUTTON_1);

halMcuWaitMs(350);

halLcdClear();

//lcd清屏,不用管

//

Set

application

role

appMode

=

appSelectMode();

//模式選擇

hal

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論