msp430控制si4432正常发送信息成功的程序-bai_第1页
msp430控制si4432正常发送信息成功的程序-bai_第2页
msp430控制si4432正常发送信息成功的程序-bai_第3页
msp430控制si4432正常发送信息成功的程序-bai_第4页
msp430控制si4432正常发送信息成功的程序-bai_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、/*说明*TX TXT 发送端 msp430F5438适用 msp430F149不适用不是最优程序,但是实践证明可以用,原创,请勿转载*主函数*/#include <msp430x54x.h>#include "SPI_function.h"#include "SPI_function.C"typedef unsigned char uchar;typedef unsigned int uint;#define keyin (P1IN & 0xF0)/ void delay(void);void SpiWriteRegister(uc

2、har reg, uchar value);uint tmp;uchar NIRQ;unsigned char ItStatus1,ItStatus2,ItStatusyy,ItStatusyy2,ItStatusyy3;/*主函数*/void main( void ) NIRQ=P2IN & BIT7; />>>>>>>>>>下面是5438芯片的管教配置程序,以及简单初始化>>>>>>>>>>>>>>>>>>>&

3、gt;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> WDTCTL = WDTPW + WDTHOLD; /关闭看门狗 /P2配置程序, P2.2 2.3 2.4 是GPIO0,1,2 /P2.6是nSEL /P2.7是nIRQ, 是4432有事件时候发送给5438的,是输入,不是输出,开始默认值为 0 /开始的时候 0-6 都置高 P2SEL=0

4、x00; P2OUT |=BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6;/ P2IN &= BIT7; P2DIR =BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6; /P4配置程序,P4全部是指示灯 /p4.0 4.1 4.2 4.3配置为按键指示 /p4.4 4.5 4.6 4.7配置为SPI指示 P4SEL=0x00; P4OUT=0xF0; P4DIR=0xFF; _delay_cycles(15000); P4OUT=0xFF; /亮一下,然后全部熄灭 /P10.7 P10.6是上面

5、的两个指示灯,暂用来指示初始化状态 P10SEL &= BIT7 + BIT6; P10OUT |= BIT7 + BIT6; P10DIR |= BIT7 + BIT6; /P3配置程序 /P3.0是SDN,只是在启动的时候用来给si4432下电一次 /PP3.1:SIMO P3.2: SOMI P3.3: CLK 其余的P3管教暂时不用 P3SEL |= BIT1 + BIT2 + BIT3; P3SEL &= BIT0; P3OUT &= BIT0; P3DIR |= BIT0; P3OUT |= BIT0; /仅仅用来硬件上下电复位一次 _delay_cycle

6、s(1500000); P3OUT &= BIT0; /SDN为底的时候为正常工作状态 /P1按键配置程序 P1SEL &= BIT4 + BIT5 + BIT6 + BIT7 ;/ P1IN |= BIT4 + BIT5 + BIT6 + BIT7 ; P1DIR &= BIT4 + BIT5 + BIT6 + BIT7 ;/<<<<<<<<上面是5438芯片的管教配置程序,以及简单初始化<<<<<<<<<<<<<<<<<

7、;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /->下面是SPI的初始化配置程序- /P10.7点亮表示SPI配置程序开始 P10OUT &= BIT7; /下面为UCB0的配置全过程,来之于那个成功的例子程序 UCB0CTL1 |= UCSWRST; UCB0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB; /主机,同步,空闲状态下是高电平

8、,UCMSB表示高位首先发送 UCB0CTL1 |= UCSSEL_2; / SMCLK UCB0BR0 = 0xFF; / 时钟被分频的系数 UCB0BR1 = 0; /时钟2次分频系数 UCB0CTL1 &= UCSWRST; /从复位模式下运行 / UCB0IE |= UCRXIE; /使能中断 _delay_cycles(150000); /P10.7熄灭表示SPI配置程序结束 P10OUT &= BIT7; /<-SPI初始化配置程序结束 over- /read interrupt status registers to clear the interrupt

9、flags and release NIRQ pinItStatus1 = SpiReadRegister(0x03);/read the Interrupt Status1 registerItStatus2 = SpiReadRegister(0x04);/read the Interrupt Status2 register/SW reset SpiWriteRegister(0x07, 0x80); /write 0x80 to the Operating & Function Control1 register /wait for POR interrupt from the

10、 radio (while the nIRQ pin is high)while ( NIRQ = 1); /read interrupt status registers to clear the interrupt flags and release NIRQ pinItStatus1 = SpiReadRegister(0x03);/read the Interrupt Status1 registerItStatus2 = SpiReadRegister(0x04);/read the Interrupt Status2 register/wait for chip ready int

11、errupt from the radio (while the nIRQ pin is high) /while ( NIRQ = 1); /read interrupt status registers to clear the interrupt flags and release NIRQ pinItStatus1 = SpiReadRegister(0x03);/read the Interrupt Status1 registerItStatus2 = SpiReadRegister(0x04);/read the Interrupt Status2 register/*set t

12、he physical parameters*/set the center frequency to 915 MHzSpiWriteRegister(0x75, 0x75);/write 0x75 to the Frequency Band Select register SpiWriteRegister(0x76, 0xBB);/write 0xBB to the Nominal Carrier Frequency1 registerSpiWriteRegister(0x77, 0x80); /write 0x80 to the Nominal Carrier Frequency0 reg

13、ister/set the desired TX data rate (9.6kbps)SpiWriteRegister(0x6E, 0x4E);/write 0x4E to the TXDataRate 1 registerSpiWriteRegister(0x6F, 0xA5);/write 0xA5 to the TXDataRate 0 registerSpiWriteRegister(0x70, 0x2C);/write 0x2C to the Modulation Mode Control 1 registerSpiWriteRegister(0x58, 0x80);/write

14、0x80 to the 0x58 register/set the desired TX deviatioin (+-45 kHz)SpiWriteRegister(0x72, 0x48);/write 0x48 to the Frequency Deviation register /set the TX power to MAXSpiWriteRegister(0x6D, 0x1F);/write 0x1F to the TX Power register /*set the packet structure and the modulation type*/set the preambl

15、e length to 10bytes if the antenna diversity is used and set to 5bytes if not #ifdef ANTENNA_DIVERSITY SpiWriteRegister(0x34, 0x14);/write 0x14 to the Preamble Length register #else SpiWriteRegister(0x34, 0x0A);/write 0x0A to the Preamble Length register #endif/Disable header bytes; set variable pac

16、ket length (the length of the payload is defined by the/received packet length field of the packet); set the synch word to two bytes longSpiWriteRegister(0x33, 0x02);/write 0x02 to the Header Control2 register /Set the sync word pattern to 0x2DD4SpiWriteRegister(0x36, 0x2D);/write 0x2D to the Sync W

17、ord 3 registerSpiWriteRegister(0x37, 0xD4);/write 0xD4 to the Sync Word 2 register/enable the TX packet handler and CRC-16 (IBM) checkSpiWriteRegister(0x30, 0x0D);/write 0x0D to the Data Access Control register SpiReadRegister(0x30); /测试用,可删除 /enable FIFO mode and GFSK modulationSpiWriteRegister(0x7

18、1, 0x63);/write 0x63 to the Modulation Mode Control 2 register SpiReadRegister(0x71); /测试用,可删除 #ifdef ANTENNA_DIVERSITY/enable the antenna diversity modeSpiWriteRegister(0x08, 0x80); /write 0x80 to the Operating Function Control 2 register #endif /*set the GPIO's according the testcard type*/ #i

19、fdef ANTENNA_DIVERSITY SpiWriteRegister(0x0C, 0x17); /write 0x17 to the GPIO1 Configuration(set the Antenna 1 Switch used for antenna diversity ) SpiWriteRegister(0x0D, 0x18); /write 0x18 to the GPIO2 Configuration(set the Antenna 2 Switch used for antenna diversity ) #endif /* #ifdef ONE_SMA_WITH_R

20、F_SWITCH */ SpiWriteRegister(0x0C, 0x12); /write 0x12 to the GPIO1 Configuration(set the TX state) _delay_cycles(15000); ItStatusyy3 = SpiReadRegister(0x0C); /测试用,可删除 SpiWriteRegister(0x0D, 0x15); /write 0x15 to the GPIO2 Configuration(set the RX state) ItStatusyy2 = SpiReadRegister(0x0D); /测试用,可删除

21、/* #endif */ /*set the non-default Si443x registers*/set Crystal Oscillator Load Capacitance registerSpiWriteRegister(0x09, 0xD7); /write 0xD7 to the CrystalOscillatorLoadCapacitance register _delay_cycles(150000); ItStatusyy = SpiReadRegister(0x09); /测试用,可删除 while (ItStatusyy != 0xD7); /<-芯片初始化结

22、束 _delay_cycles(1000000); while(1) / _delay_cycles(100000); P4OUT &= BIT7 ;/*SET THE CONTENT OF THE PACKET*/set the length of the payload to 8bytesSpiWriteRegister(0x3E, 8); /write 8 to the Transmit Packet Length register/fill the payload into the transmit FIFOSpiWriteRegister(0x7F, 0x42); /writ

23、e 0x42 ('B') to the FIFO Access registerSpiWriteRegister(0x7F, 0x55); /write 0x55 ('U') to the FIFO Access registerSpiWriteRegister(0x7F, 0x54); /write 0x54 ('T') to the FIFO Access registerSpiWriteRegister(0x7F, 0x54); /write 0x54 ('T') to the FIFO Access registerSpi

24、WriteRegister(0x7F, 0x4F); /write 0x4F ('O') to the FIFO Access registerSpiWriteRegister(0x7F, 0x4E); /write 0x4E ('N') to the FIFO Access registerSpiWriteRegister(0x7F, 0x33); /write 0x31 ('3') to the FIFO Access registerSpiWriteRegister(0x7F, 0x0D); /write 0x0D (CR) to the

25、FIFO Access register/Disable all other interrupts and enable the packet sent interrupt only./This will be used for indicating the successfull packet transmission for the MCUSpiWriteRegister(0x05, 0x04); /write 0x04 to the Interrupt Enable 1 registerSpiWriteRegister(0x06, 0x00); /write 0x00 to the In

26、terrupt Enable 2 register/Read interrupt status regsiters. It clear all pending interrupts and the nIRQ pin goes back to high.ItStatus1 = SpiReadRegister(0x03); /read the Interrupt Status1 registerItStatus2 = SpiReadRegister(0x04); /read the Interrupt Status2 register /*enable transmitter*/The radio

27、 forms the packet and send it automatically.SpiWriteRegister(0x07, 0x09); /write 0x09 to the Operating Function Control 1 register /*wait for the packet sent interrupt*/The MCU just needs to wait for the 'ipksent' interrupt.while(NIRQ = 1); /read interrupt status registers to release the int

28、errupt flagsItStatus1 = SpiReadRegister(0x03); /read the Interrupt Status1 registerItStatus2 = SpiReadRegister(0x04); /read the Interrupt Status2 register/wait a bit for showing the LED a bit longer_delay_cycles(10000);/turn off the LED /LED1 = 0; P4OUT |= BIT7 ; _delay_cycles(100000); / if(P1IN !=

29、0xF0) /如果有键被按下 _delay_cycles(100); if(keyin = 0xE0) /再次检测按键状态 while (P1IN = 0xE0); /等待键盘被松开/Wait for releasing the push button /while( PB1 = 0 );/turn on the LED to show the packet transmission /LED1 = 1; P4OUT &= BIT0 ; /*SET THE CONTENT OF THE PACKET*/set the length of the payload to 8bytesSpi

30、WriteRegister(0x3E, 8);/write 8 to the Transmit Packet Length register/fill the payload into the transmit FIFOSpiWriteRegister(0x7F, 0x42); /write 0x42 ('B') to the FIFO Access registerSpiWriteRegister(0x7F, 0x55); /write 0x55 ('U') to the FIFO Access registerSpiWriteRegister(0x7F, 0

31、x54); /write 0x54 ('T') to the FIFO Access registerSpiWriteRegister(0x7F, 0x54); /write 0x54 ('T') to the FIFO Access registerSpiWriteRegister(0x7F, 0x4F); /write 0x4F ('O') to the FIFO Access registerSpiWriteRegister(0x7F, 0x4E); /write 0x4E ('N') to the FIFO Access

32、registerSpiWriteRegister(0x7F, 0x31); /write 0x31 ('1') to the FIFO Access registerSpiWriteRegister(0x7F, 0x0D); /write 0x0D (CR) to the FIFO Access register/Disable all other interrupts and enable the packet sent interrupt only./This will be used for indicating the successfull packet transm

33、ission for the MCUSpiWriteRegister(0x05, 0x04); /write 0x04 to the Interrupt Enable 1 registerSpiWriteRegister(0x06, 0x00); /write 0x00 to the Interrupt Enable 2 register/Read interrupt status regsiters. It clear all pending interrupts and the nIRQ pin goes back to high.ItStatus1 = SpiReadRegister(0

34、x03); /read the Interrupt Status1 registerItStatus2 = SpiReadRegister(0x04); /read the Interrupt Status2 register /*enable transmitter*/The radio forms the packet and send it automatically.SpiWriteRegister(0x07, 0x09); /write 0x09 to the Operating Function Control 1 register /*wait for the packet se

35、nt interrupt*/The MCU just needs to wait for the 'ipksent' interrupt.while(NIRQ = 1); /read interrupt status registers to release the interrupt flagsItStatus1 = SpiReadRegister(0x03); /read the Interrupt Status1 registerItStatus2 = SpiReadRegister(0x04); /read the Interrupt Status2 register/

36、wait a bit for showing the LED a bit longer_delay_cycles(10000);/turn off the LED /LED1 = 0; P4OUT |= BIT0 ; /<-对于key1的程序添加结束 if(keyin = 0xD0) /再次检测按键状态 while (P1IN = 0xD0); /等待键盘被松开/Wait for releasing the push button /while( PB1 = 0 );/turn on the LED to show the packet transmission /LED1 = 1; P

37、4OUT &= BIT1 ;/*SET THE CONTENT OF THE PACKET*/set the length of the payload to 8bytesSpiWriteRegister(0x3E, 8); /write 8 to the Transmit Packet Length register/fill the payload into the transmit FIFOSpiWriteRegister(0x7F, 0x42); /write 0x42 ('B') to the FIFO Access registerSpiWriteRegis

38、ter(0x7F, 0x55); /write 0x55 ('U') to the FIFO Access registerSpiWriteRegister(0x7F, 0x54); /write 0x54 ('T') to the FIFO Access registerSpiWriteRegister(0x7F, 0x54); /write 0x54 ('T') to the FIFO Access registerSpiWriteRegister(0x7F, 0x4F); /write 0x4F ('O') to the F

39、IFO Access registerSpiWriteRegister(0x7F, 0x4E); /write 0x4E ('N') to the FIFO Access registerSpiWriteRegister(0x7F, 0x32); /write 0x31 ('2') to the FIFO Access registerSpiWriteRegister(0x7F, 0x0D); /write 0x0D (CR) to the FIFO Access register/Disable all other interrupts and enable

40、the packet sent interrupt only./This will be used for indicating the successfull packet transmission for the MCUSpiWriteRegister(0x05, 0x04); /write 0x04 to the Interrupt Enable 1 registerSpiWriteRegister(0x06, 0x00); /write 0x00 to the Interrupt Enable 2 register/Read interrupt status regsiters. It

41、 clear all pending interrupts and the nIRQ pin goes back to high.ItStatus1 = SpiReadRegister(0x03); /read the Interrupt Status1 registerItStatus2 = SpiReadRegister(0x04); /read the Interrupt Status2 register /*enable transmitter*/The radio forms the packet and send it automatically.SpiWriteRegister(

42、0x07, 0x09); /write 0x09 to the Operating Function Control 1 register /*wait for the packet sent interrupt*/The MCU just needs to wait for the 'ipksent' interrupt.while(NIRQ = 1); /read interrupt status registers to release the interrupt flagsItStatus1 = SpiReadRegister(0x03); /read the Inte

43、rrupt Status1 registerItStatus2 = SpiReadRegister(0x04); /read the Interrupt Status2 register/wait a bit for showing the LED a bit longer_delay_cycles(10000);/turn off the LED /LED1 = 0; P4OUT |= BIT1 ; /<-对于key2的程序添加结束 if(keyin = 0xB0) /再次检测按键状态/Wait for releasing the push button while (P1IN = 0

44、xB0); /等待键盘被松开 /while( PB1 = 0 );/turn on the LED to show the packet transmission /LED1 = 1; P4OUT &= BIT2 ;/*SET THE CONTENT OF THE PACKET*/set the length of the payload to 8bytesSpiWriteRegister(0x3E, 8); /write 8 to the Transmit Packet Length register/fill the payload into the transmit FIFOSp

45、iWriteRegister(0x7F, 0x42); /write 0x42 ('B') to the FIFO Access registerSpiWriteRegister(0x7F, 0x55); /write 0x55 ('U') to the FIFO Access registerSpiWriteRegister(0x7F, 0x54); /write 0x54 ('T') to the FIFO Access registerSpiWriteRegister(0x7F, 0x54); /write 0x54 ('T') to the FIFO Access registerSpiWriteRegister(0x7F, 0x4F); /

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论