[求助] MSP430F2274 CC2500 两块无线传输模块 回传问题

yu83717   2015-7-20 10:17 楼主
使用的是IAR 动作如下: 从计算机端发送,电池模块LED灯亮 接着电池模块回传,计算机端LED灯亮 结果没回传到计算机端, 请大神看看 ! 计算机传送端 代码如下:
  1. //---------------------------------------------------------------------------

  2. // MSP430F2274
  3. //----------------------------------------------------------------------------
  4. #include "include.h"
  5. extern char paTable[];
  6. extern char paTableLen;
  7. char txBuffer[64];
  8. char rxBuffer[64];
  9. unsigned int i;
  10. int k =1 ;
  11. int j;
  12. int m =1 ;
  13. void main (void)
  14. {
  15. WDTCTL = WDTPW + WDTHOLD; // Stop WDT
  16. TI_CC_SPISetup(); // Initialize SPI port
  17. TI_CC_PowerupResetCCxxxx(); // Reset CCxxxx
  18. writeRFSettings(); // Write RF settings to config reg
  19. TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE
  20. P1DIR &= ~(TI_CC_SW1); //Input

  21. P1OUT |= (TI_CC_SW1); //Pull high
  22. P1REN |= (TI_CC_SW1); //Enable internal Pull up/low
  23. // --Add P2.6 P2.7 as GPIO
  24. P2SEL &= ~(TI_CC_GDO0_PIN+TI_CC_GDO2_PIN);
  25. // --Add Clear LEDs on start
  26. TI_CC_LED_PxOUT &= ~(TI_CC_LED1 + TI_CC_LED2); //Outputs Low as OFF
  27. // Port1 Interrupt
  28. TI_CC_SW_PxIES = TI_CC_SW1; //Int on falling edge
  29. TI_CC_SW_PxIFG &= ~(TI_CC_SW1); //Clr flags
  30. TI_CC_SW_PxIE = TI_CC_SW1; //Activate enables
  31. TI_CC_LED_PxDIR = TI_CC_LED1 + TI_CC_LED2; //Outputs
  32. // RF interrupt

  33. TI_CC_GDO0_PxIES |= TI_CC_GDO0_PIN; // Int on falling edge (end of pkt)
  34. TI_CC_GDO0_PxIFG &= ~TI_CC_GDO0_PIN; // Clear flag
  35. TI_CC_GDO0_PxIE |= TI_CC_GDO0_PIN; // Enable int on end of packet
  36. TI_CC_SPIStrobe(TI_CCxxx0_SRX); // Initialize CCxxxx in RX mode.
  37. // When a pkt is received, it will

  38. while(k<3)
  39. {
  40. j = 50000; // Delay
  41. do (j--);
  42. while (j != 0);
  43. txBuffer[0] = 2; // Packet length

  44. txBuffer[1] = 0x01; // Packet address
  45. txBuffer[2] = 'C'; // Gary modified as 'A'(in ASCII)
  46. RFSendPacket(txBuffer, 3); // Send value over RF
  47. k++;
  48. }
  49. P2IFG &= ~TI_CC_GDO0_PIN; // After pkt TX, this flag is set.
  50. _BIS_SR(LPM3_bits + GIE); // Enter LPM3, enable interrupts
  51. }
  52. // The ISR assumes the int came from the pin attached to GDO0 and therefore
  53. // does not check the other seven inputs. Interprets this as a signal from
  54. // CCxxxx indicating packet received.
  55. #pragma vector=PORT2_VECTOR
  56. __interrupt void port2_ISR (void)
  57. {
  58. char len=2; // Len of pkt to be RXed (only addr
  59. // plus data; size byte not incl b/c
  60. // stripped away within RX function)
  61. if (RFReceivePacket(rxBuffer,&len)) // Fetch packet from CCxxxx
  62. // TI_CC_LED_PxOUT ^= rxBuffer[1]; // Toggle LEDs according to pkt data
  63. {
  64. if (rxBuffer[0]==0x02)
  65. {
  66. if (rxBuffer[1]=='C')
  67. {
  68. TI_CC_LED_PxOUT &= ~(TI_CC_LED1); // Clear Red LED
  69. TI_CC_LED_PxOUT |= (TI_CC_LED2); // Set Green LEDs
  70. }
  71. else
  72. {
  73. TI_CC_LED_PxOUT &= ~(TI_CC_LED2); // Clear Green LEDs
  74. TI_CC_LED_PxOUT |= (TI_CC_LED1); // set Red LEDs
  75. }
  76. }
  77. }
  78. P2IFG &= ~TI_CC_GDO0_PIN; // Clear flag
  79. }
电池模块接收端 代码如下:
  1. //---------------------------------------------------------------------------

  2. // MSP430F2274
  3. //----------------------------------------------------------------------------
  4. #include "include.h"
  5. extern char paTable[];
  6. extern char paTableLen;
  7. char txBuffer[64];
  8. char rxBuffer[64];
  9. unsigned int i;
  10. int k =1 ;
  11. int j;
  12. int m =1 ;
  13. void main (void)
  14. {
  15. WDTCTL = WDTPW + WDTHOLD; // Stop WDT
  16. TI_CC_SPISetup(); // Initialize SPI port
  17. TI_CC_PowerupResetCCxxxx(); // Reset CCxxxx
  18. writeRFSettings(); // Write RF settings to config reg
  19. TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE
  20. P1DIR &= ~(TI_CC_SW1); //Input
  21. P1OUT |= (TI_CC_SW1); //Pull high
  22. P1REN |= (TI_CC_SW1); //Enable internal Pull up/low
  23. // --Add P2.6 P2.7 as GPIO
  24. P2SEL &= ~(TI_CC_GDO0_PIN+TI_CC_GDO2_PIN);
  25. // --Add Clear LEDs on start
  26. TI_CC_LED_PxOUT &= ~(TI_CC_LED1 + TI_CC_LED2); //Outputs Low as OFF
  27. // Port1 Interrupt
  28. TI_CC_SW_PxIES = TI_CC_SW1; //Int on falling edge
  29. TI_CC_SW_PxIFG &= ~(TI_CC_SW1); //Clr flags
  30. TI_CC_SW_PxIE = TI_CC_SW1; //Activate enables
  31. TI_CC_LED_PxDIR = TI_CC_LED1 + TI_CC_LED2; //Outputs
  32. // RF interrupt
  33. TI_CC_GDO0_PxIES |= TI_CC_GDO0_PIN; // Int on falling edge (end of pkt)
  34. TI_CC_GDO0_PxIFG &= ~TI_CC_GDO0_PIN; // Clear flag
  35. TI_CC_GDO0_PxIE |= TI_CC_GDO0_PIN; // Enable int on end of packet
  36. TI_CC_SPIStrobe(TI_CCxxx0_SRX); // Initialize CCxxxx in RX mode.
  37. // When a pkt is received, it will
  38. _BIS_SR(LPM3_bits + GIE); // Enter LPM3, enable interrupts
  39. }
  40. // The ISR assumes the int came from the pin attached to GDO0 and therefore
  41. // does not check the other seven inputs. Interprets this as a signal from
  42. // CCxxxx indicating packet received.
  43. #pragma vector=PORT2_VECTOR
  44. __interrupt void port2_ISR (void)
  45. {
  46. char len=2; // Len of pkt to be RXed (only addr
  47. // plus data; size byte not incl b/c
  48. // stripped away within RX function)
  49. if (RFReceivePacket(rxBuffer,&len)) // Fetch packet from CCxxxx
  50. // TI_CC_LED_PxOUT ^= rxBuffer[1]; // Toggle LEDs according to pkt data
  51. {
  52. if (rxBuffer[0]==0x01)
  53. {
  54. if (rxBuffer[1]=='C')
  55. {
  56. TI_CC_LED_PxOUT &= ~(TI_CC_LED1); // Clear Red LED
  57. TI_CC_LED_PxOUT |= (TI_CC_LED2); // Set Green LEDs

    while(m<3)

  58. {
  59. j = 50000; // Delay
  60. do (j--);
  61. while (j != 0);
  62. txBuffer[0] = 2; // Packet length
  63. txBuffer[1] = 0x02; // Packet address
  64. txBuffer[2] = 'C'; //Gary modified as 'A'(in ASCII)
  65. RFSendPacket(txBuffer, 3); // Send value over RF
  66. m++;
  67. }
  68. P2IFG &= ~TI_CC_GDO0_PIN;
  69. }
  70. else
  71. {
  72. TI_CC_LED_PxOUT &= ~(TI_CC_LED2); // Clear Green LEDs
  73. TI_CC_LED_PxOUT |= (TI_CC_LED1); // set Red LEDs

    while(m<3)

  74. {
  75. j = 50000; // Delay
  76. do (j--);
  77. while (j != 0);
  78. txBuffer[0] = 2; // Packet length
  79. txBuffer[1] = 0x02; // Packet address
  80. txBuffer[2] = 'C'; //Gary modified as 'A'(in ASCII)
  81. RFSendPacket(txBuffer, 3); // Send value over RF
  82. m++;
  83. }
  84. P2IFG &= ~TI_CC_GDO0_PIN;
  85. }
  86. }
  87. }
  88. P2IFG &= ~TI_CC_GDO0_PIN; // Clear flag
  89. }
  • 11749982_970863649602355_25879662_o.jpg

回复评论 (4)

楼主你做过无线电能传输吗?我现在做无线传输。
点赞  2015-7-23 09:28
楼主你好:

不能通信成功只是个结果,不是问题。影响到这个结果的因素非常多,不仅仅是程序软件。

所以你要先仔细调试,可能问题不止一个。所以经过调试后,将问题问的具体一些(比如,如果是通信不上,那是一点信号都没有、是前导码都没收到?还是数据收到了,校验不过?),这样大家才能更好帮你解决问题。

如果拿个结果,没有人能回答哦。



点赞  2015-7-23 09:43
引用: 绿茶 发表于 2015-7-23 09:43
楼主你好:

不能通信成功只是个结果,不是问题。影响到这个结果的因素非常多,不仅仅是程序软件。

所 ...

绿茶前辈 您好:

感谢您的回复 !
真是非常抱歉没注意到细节的部分  描述不够清楚
现在疑问的点在于:

首先 , 计算机传送端的 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 以内才对

想请问前辈们这有可能是什么原因造成的 ?

( 目前硬体的部分测试没有问题 )
点赞  2015-7-23 11:48
引用: x8389983 发表于 2015-7-23 09:28
楼主你做过无线电能传输吗?我现在做无线传输。

刚开始接触而已
点赞  2015-7-23 13:50
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复