ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
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/***
16 * Demo: XL2400 / WL2400 SOP8 2.4GHz RF, Emulate SPI on GPIO pins
17 *
18 * Pin connection:
19 * P35 => CSN
20 * P34 => DATA
21 * P32 => SCK
22 * VDD1 => 3.3V
23 * XC1,XC2 => 16MHz OSC
24 * GND => GND
25 *
26 * test-board: Minimum System; test-MCU: STC8H1K08,STC8H3K64S2
27 */
28
29#include "fw_hal.h"
30#include "xl2400.h"
31
32// 0:TX, 1:RX
33#define XL2400_MODE 0
34
35__CODE uint8_t TX_ADDRESS[5] = {0x11,0x33,0x33,0x33,0x11};
36__CODE uint8_t RX_ADDRESS[5] = {0x33,0x55,0x33,0x44,0x33};
37
39
40void GPIO_Init(void)
41{
43 // SCLK(P32) CSN(P35)
45}
46
47int main(void)
48{
49 __CODE uint8_t tmp[] = {
50 0x1F, 0x80, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
51 0x21, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x28,
52 0x31, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x38,
53 0x41, 0x12, 0x13, 0x14, 0x15, 0x16, 0x37, 0x48};
54 uint8_t i, j, status;
55
57 GPIO_Init();
58
59 // UART1, baud 115200, baud source Timer1, 1T mode, no interrupt
61 UART1_TxString("UART Initialized\r\n");
62
63 while (XL2400_SPI_Test() == HAL_ERROR)
64 {
65 UART1_TxString(" - check failed\r\n");
66 SYS_Delay(1000);
67 }
68 UART1_TxString(" - check passed\r\n");
69
72
73
74#if XL2400_MODE == 0
79 UART1_TxString("XL2400 TX Initialized\r\n");
80
81 while(1)
82 {
83 //XL2400_PrintStatus();
84 status = XL2400_Tx(tmp, XL2400_PLOAD_WIDTH);
85
86 i++;
87 if (status == 0x20)
88 {
89 j++;
90 }
91 if (i == 0)
92 {
93 UART1_TxHex(j);
94 UART1_TxString("\r\n");
95 j = 0;
96 }
97 // >= 2ms
98 SYS_Delay(3);
99 }
100#else
101 // RX
106 UART1_TxString("XL2400 RX Initialized\r\n");
107
108 while(1)
109 {
111 while (--j)
112 {
113 status = XL2400_Rx();
114 if (status & RX_DR_FLAG)
115 {
116 UART1_TxString(".");
117 }
118 }
119 //XL2400_PrintStatus();
120 //XL2400_Sleep();
121 //SYS_Delay(1);
122 }
123#endif
124}
#define GPIO_P3_SetMode(__PINS__, __MODE__)
Definition: fw_gpio.h:89
@ GPIO_Pin_5
Definition: fw_gpio.h:50
@ GPIO_Pin_2
Definition: fw_gpio.h:47
@ GPIO_Pin_4
Definition: fw_gpio.h:49
@ GPIO_Mode_Output_PP
Definition: fw_gpio.h:24
@ GPIO_Mode_InOut_QBD
Definition: fw_gpio.h:23
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
@ HAL_ERROR
Definition: fw_types.h:77
@ HAL_State_ON
Definition: fw_types.h:71
unsigned char uint8_t
Definition: fw_types.h:18
void UART1_TxString(uint8_t *str)
Definition: fw_uart.c:85
@ UART1_BaudSource_Timer1
Definition: fw_uart.h:33
void UART1_TxHex(uint8_t hex)
Definition: fw_uart.c:79
void UART1_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
Definition: fw_uart.c:56
__CODE uint8_t TX_ADDRESS[5]
Definition: main.c:35
int main(void)
Definition: main.c:45
void GPIO_Init(void)
Definition: main.c:39
__CODE uint8_t RX_ADDRESS[5]
Definition: main.c:36
uint8_t XL2400_PrintStatus(void)
Definition: xl2400.c:357
void XL2400_SetTxMode(void)
Definition: xl2400.c:266
void XL2400_SetRxAddress(uint8_t *address)
Definition: xl2400.c:203
uint8_t XL2400_Rx(void)
Definition: xl2400.c:306
void XL2400_SetTxAddress(uint8_t *address)
Definition: xl2400.c:197
void XL2400_SetPower(uint8_t power)
Definition: xl2400.c:208
void XL2400_WakeUp(void)
Definition: xl2400.c:226
void XL2400_Init(void)
Definition: xl2400.c:141
void XL2400_SetChannel(uint8_t channel)
Definition: xl2400.c:181
void XL2400_SetRxMode(void)
Definition: xl2400.c:275
uint8_t XL2400_Tx(uint8_t *ucPayload, uint8_t length)
Definition: xl2400.c:285
uint8_t XL2400_SPI_Test(void)
Definition: xl2400.c:128
#define XL2400_PLOAD_WIDTH
Definition: xl2400.h:25
#define RX_DR_FLAG
Definition: xl2400.h:111
#define XL2400_RF_0DB
Definition: xl2400.h:102
uint8_t __XDATA i