main.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /***
  15. * Demo: Ci24R1 SOP8 2.4GHz RF
  16. *
  17. * Pin connection:
  18. * P35(SS, Ignored) => CSN
  19. * P34(MOSI) => DATA
  20. * P32(SPCLK) => SCK
  21. * VDD1 => 3.3V
  22. * XC1,XC2 => 16MHz OSC
  23. * GND => GND
  24. *
  25. * test-board: Minimum System; test-MCU: STC8H1K08,STC8H3K64S2
  26. */
  27. #include "fw_hal.h"
  28. #include "ci24r1.h"
  29. // 0:TX, 1:RX
  30. #define CI24R1_MODE 1
  31. __CODE uint8_t TX_ADDRESS[5]={0x34,0x43,0x10,0x10,0x01};
  32. __CODE uint8_t RX_ADDRESS[5]={0x01,0x43,0x10,0x10,0x34};
  33. extern uint8_t *xbuf_data;
  34. void GPIO_Init(void)
  35. {
  36. // SCLK(P32) CSN(P35)
  37. GPIO_P3_SetMode(GPIO_Pin_2|GPIO_Pin_5, GPIO_Mode_Output_PP);
  38. }
  39. int main(void)
  40. {
  41. __CODE uint8_t tmp[] = {
  42. 0x1F, 0x80, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
  43. 0x21, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x28,
  44. 0x31, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x38,
  45. 0x41, 0x12, 0x13, 0x14, 0x15, 0x16, 0x37, 0x48};
  46. uint8_t i, j, status;
  47. SYS_SetClock();
  48. GPIO_Init();
  49. // UART1, baud 115200, baud source Timer1, 1T mode, no interrupt
  50. UART1_Config8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
  51. UART1_TxString("UART Initialized\r\n");
  52. while (CI24R1_SPI_Test() == HAL_ERROR)
  53. {
  54. UART1_TxString(" - check failed\r\n");
  55. SYS_Delay(1000);
  56. }
  57. UART1_TxString(" - check passed\r\n");
  58. CI24R1_Init();
  59. if (CI24R1_MODE == 0)
  60. {
  61. // TX
  62. CI24R1_SetChannel(60);
  63. CI24R1_SetTxMode();
  64. CI24R1_SetTxAddress(TX_ADDRESS);
  65. CI24R1_SetRxAddress(RX_ADDRESS);
  66. UART1_TxString("CI24R1 TX Initialized\r\n");
  67. while(1)
  68. {
  69. CI24R1_PrintStatus();
  70. CI24R1_Tx(tmp, CI24R1_PLOAD_WIDTH);
  71. SYS_Delay(500);
  72. }
  73. }
  74. else
  75. {
  76. // RX
  77. CI24R1_SetChannel(60);
  78. CI24R1_SetRxMode();
  79. CI24R1_SetTxAddress(RX_ADDRESS);
  80. CI24R1_SetRxAddress(TX_ADDRESS);
  81. UART1_TxString("CI24R1 RX Initialized\r\n");
  82. while(1)
  83. {
  84. CI24R1_PrintStatus();
  85. CI24R1_Rx();
  86. UART1_TxString("\r\n");
  87. SYS_Delay(10);
  88. }
  89. }
  90. }