MSP430F2274 CC2500 两块无线传输模块 回传问题
动作如下:
从计算机端发送,电池模块LED灯亮
接着电池模块回传,计算机端LED灯亮
结果没回传到计算机端, 请大神看看 !
计算机传送端 代码如下:
//---------------------------------------------------------------------------
- // MSP430F2274
- //----------------------------------------------------------------------------
- #include "include.h"
- extern char paTable[];
- extern char paTableLen;
- char txBuffer[64];
- char rxBuffer[64];
- unsigned int i;
- int k =1 ;
- int j;
- int m =1 ;
- void main (void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- TI_CC_SPISetup(); // Initialize SPI port
- TI_CC_PowerupResetCCxxxx(); // Reset CCxxxx
- writeRFSettings(); // Write RF settings to config reg
- TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE
P1DIR &= (TI_CC_SW1); //Input
- P1OUT |= (TI_CC_SW1); //Pull high
- P1REN |= (TI_CC_SW1); //Enable internal Pull up/low
- // --Add P2.6 P2.7 as GPIO
- P2SEL &= (TI_CC_GDO0_PIN+TI_CC_GDO2_PIN);
- // --Add Clear LEDs on start
- TI_CC_LED_PxOUT &= (TI_CC_LED1 + TI_CC_LED2); //Outputs Low as OFF
-
- // Port1 Interrupt
- TI_CC_SW_PxIES = TI_CC_SW1; //Int on falling edge
- TI_CC_SW_PxIFG &= (TI_CC_SW1); //Clr flags
- TI_CC_SW_PxIE = TI_CC_SW1; //Activate enables
- TI_CC_LED_PxDIR = TI_CC_LED1 + TI_CC_LED2; //Outputs
// RF interrupt
- TI_CC_GDO0_PxIES |= TI_CC_GDO0_PIN; // Int on falling edge (end of pkt)
- TI_CC_GDO0_PxIFG &= TI_CC_GDO0_PIN; // Clear flag
- TI_CC_GDO0_PxIE |= TI_CC_GDO0_PIN; // Enable int on end of packet
- TI_CC_SPIStrobe(TI_CCxxx0_SRX); // Initialize CCxxxx in RX mode.
- // When a pkt is received, it will
- while(k<3)
- {
- j = 50000; // Delay
- do (j--);
- while (j != 0);
-
txBuffer[0] = 2; // Packet length
- txBuffer[1] = 0x01; // Packet address
- txBuffer[2] = 'C'; // Gary modified as 'A'(in ASCII)
- RFSendPacket(txBuffer, 3); // Send value over RF
- k++;
- }
- P2IFG &= TI_CC_GDO0_PIN; // After pkt TX, this flag is set.
- _BIS_SR(LPM3_bits + GIE); // Enter LPM3, enable interrupts
- }
- // The ISR assumes the int came from the pin attached to GDO0 and therefore
- // does not check the other seven inputs. Interprets this as a signal from
- // CCxxxx indicating packet received.
- #pragma vector=PORT2_VECTOR
- __interrupt void port2_ISR (void)
- {
- char len=2; // Len of pkt to be RXed (only addr
- // plus data; size byte not incl b/c
- // stripped away within RX function)
- if (RFReceivePacket(rxBuffer,&len)) // Fetch packet from CCxxxx
-
- // TI_CC_LED_PxOUT ^= rxBuffer[1]; // Toggle LEDs according to pkt data
- {
- if (rxBuffer[0]==0x02)
- {
- if (rxBuffer[1]=='C')
- {
- TI_CC_LED_PxOUT &= (TI_CC_LED1); // Clear Red LED
- TI_CC_LED_PxOUT |= (TI_CC_LED2); // Set Green LEDs
-
- }
- else
- {
- TI_CC_LED_PxOUT &= (TI_CC_LED2); // Clear Green LEDs
- TI_CC_LED_PxOUT |= (TI_CC_LED1); // set Red LEDs
-
- }
- }
- }
- P2IFG &= TI_CC_GDO0_PIN; // Clear flag
- }
电池模块接收端 代码如下:
//---------------------------------------------------------------------------
- // MSP430F2274
- //----------------------------------------------------------------------------
- #include "include.h"
- extern char paTable[];
- extern char paTableLen;
- char txBuffer[64];
- char rxBuffer[64];
- unsigned int i;
- int k =1 ;
- int j;
- int m =1 ;
- void main (void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- TI_CC_SPISetup(); // Initialize SPI port
- TI_CC_PowerupResetCCxxxx(); // Reset CCxxxx
- writeRFSettings(); // Write RF settings to config reg
- TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE
- P1DIR &= (TI_CC_SW1); //Input
- P1OUT |= (TI_CC_SW1); //Pull high
- P1REN |= (TI_CC_SW1); //Enable internal Pull up/low
- // --Add P2.6 P2.7 as GPIO
- P2SEL &= (TI_CC_GDO0_PIN+TI_CC_GDO2_PIN);
- // --Add Clear LEDs on start
- TI_CC_LED_PxOUT &= (TI_CC_LED1 + TI_CC_LED2); //Outputs Low as OFF
- // Port1 Interrupt
- TI_CC_SW_PxIES = TI_CC_SW1; //Int on falling edge
- TI_CC_SW_PxIFG &= (TI_CC_SW1); //Clr flags
- TI_CC_SW_PxIE = TI_CC_SW1; //Activate enables
- TI_CC_LED_PxDIR = TI_CC_LED1 + TI_CC_LED2; //Outputs
- // RF interrupt
- TI_CC_GDO0_PxIES |= TI_CC_GDO0_PIN; // Int on falling edge (end of pkt)
- TI_CC_GDO0_PxIFG &= TI_CC_GDO0_PIN; // Clear flag
- TI_CC_GDO0_PxIE |= TI_CC_GDO0_PIN; // Enable int on end of packet
- TI_CC_SPIStrobe(TI_CCxxx0_SRX); // Initialize CCxxxx in RX mode.
- // When a pkt is received, it will
- _BIS_SR(LPM3_bits + GIE); // Enter LPM3, enable interrupts
- }
- // The ISR assumes the int came from the pin attached to GDO0 and therefore
- // does not check the other seven inputs. Interprets this as a signal from
- // CCxxxx indicating packet received.
- #pragma vector=PORT2_VECTOR
- __interrupt void port2_ISR (void)
- {
- char len=2; // Len of pkt to be RXed (only addr
- // plus data; size byte not incl b/c
- // stripped away within RX function)
- if (RFReceivePacket(rxBuffer,&len)) // Fetch packet from CCxxxx
-
- // TI_CC_LED_PxOUT ^= rxBuffer[1]; // Toggle LEDs according to pkt data
- {
- if (rxBuffer[0]==0x01)
- {
- if (rxBuffer[1]=='C')
- {
- TI_CC_LED_PxOUT &= (TI_CC_LED1); // Clear Red LED
- TI_CC_LED_PxOUT |= (TI_CC_LED2); // Set Green LEDs
while(m<3)
- {
- j = 50000; // Delay
- do (j--);
- while (j != 0);
- txBuffer[0] = 2; // Packet length
- txBuffer[1] = 0x02; // Packet address
- txBuffer[2] = 'C'; //Gary modified as 'A'(in ASCII)
- RFSendPacket(txBuffer, 3); // Send value over RF
- m++;
- }
- P2IFG &= TI_CC_GDO0_PIN;
-
- }
- else
- {
- TI_CC_LED_PxOUT &= (TI_CC_LED2); // Clear Green LEDs
- TI_CC_LED_PxOUT |= (TI_CC_LED1); // set Red LEDs
while(m<3)
- {
- j = 50000; // Delay
- do (j--);
- while (j != 0);
- txBuffer[0] = 2; // Packet length
- txBuffer[1] = 0x02; // Packet address
- txBuffer[2] = 'C'; //Gary modified as 'A'(in ASCII)
- RFSendPacket(txBuffer, 3); // Send value over RF
- m++;
- }
- P2IFG &= TI_CC_GDO0_PIN;
-
- }
- }
- }
- P2IFG &= TI_CC_GDO0_PIN; // Clear flag
- }
楼主你做过无线电能传输吗?我现在做无线传输。
楼主你好:
不能通信成功只是个结果,不是问题。影响到这个结果的因素非常多,不仅仅是程序软件。
所以你要先仔细调试,可能问题不止一个。所以经过调试后,将问题问的具体一些(比如,如果是通信不上,那是一点信号都没有、是前导码都没收到?还是数据收到了,校验不过?),这样大家才能更好帮你解决问题。
如果拿个结果,没有人能回答哦。
绿茶前辈 您好:
感谢您的回复 !
真是非常抱歉没注意到细节的部分 描述不够清楚
现在疑问的点在于:
首先 , 计算机传送端的 address 设为0x02 ; 电池模组端的address 设为0x01
计算机传送端代码的 第57行 表示传给0x01(电池模组端) 一个值 'A' (第58行)
然后 第79行 rxBuffer[0]== 0x02 表示自己的 address 为0x02
电池模组端代码的 第73 行表示自己的 address 为0x01
然而因为计算机传送端传送的值是 'A' 因此电池模组端会执行 第92行的 else
接着先亮红灯 再回传给计算机传送端 0x02 (第101行)
电池模组端有亮灯 表示有收到信号并执行回传动作
但 计算机传送端并没有收到回传的值 (也就是 rxBuffer[0] 没有收到信号)
这部分是用 Add Watch 去查看的
在这之前 测试过将两端的 address 都设为 0x01
结果回传成功
但当 address 设定不是 0x01 时 回传就会失败
理论上不应该会这样, address 应该可以任意设置在 0xFF 以内才对
想请问前辈们这有可能是什么原因造成的 ?
( 目前硬体的部分测试没有问题 )
刚开始接触而已