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
17 *
18 * Pin connection:
19 * P35(SS, Ignored) => CSN
20 * P34(MOSI) => DATA
21 * P32(SPCLK) => 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 1
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};
37extern uint8_t *xbuf_data;
38
40
41void SPI_Init(void)
42{
43 // SPI frequency
45 // Clock is low when idle
47 // Data transfer is driven by lower SS pin
49 // MSB first
51 // Define the output pins
53 // Ignore SS pin, use MSTR to swith between master/slave mode
55 // Master mode
57 // Start SPI
59}
60
61void GPIO_Init(void)
62{
63 // Configure GPIO pins before SPI and device
64 // MISO(P33) MOSI(P34)
66 // SCLK(P32) CSN(P35) CE(P37)
68}
69
70int main(void)
71{
72 __CODE uint8_t tmp[] = {
73 0x1F, 0x80, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
74 0x21, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x28,
75 0x31, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x38,
76 0x41, 0x12, 0x13, 0x14, 0x15, 0x16, 0x37, 0x48};
77 uint8_t i, j, status;
78
80 GPIO_Init();
81
82 // UART1, baud 115200, baud source Timer1, 1T mode, no interrupt
84 UART1_TxString("UART Initialized\r\n");
85
86 SPI_Init();
87 UART1_TxString("SPI Initialized\r\n");
88
89 while (XL2400_SPI_Test() == HAL_ERROR)
90 {
91 UART1_TxString(" - check failed\r\n");
92 SYS_Delay(1000);
93 }
94 UART1_TxString(" - check passed\r\n");
95
98
99 if (XL2400_MODE == 0)
100 {
101 // TX
106 UART1_TxString("XL2400 TX Initialized\r\n");
107
108 while(1)
109 {
110 //XL2400_PrintStatus();
112 SYS_Delay(100);
113 }
114 }
115 else
116 {
117 // RX
121 UART1_TxString("XL2400 RX Initialized\r\n");
122
123 while(1)
124 {
127 while (--j)
128 {
129 status = XL2400_Rx();
130 if (status & RX_DR_FLAG)
131 {
132 UART1_TxString(" <\r\n");
133 }
134 }
135 //XL2400_PrintStatus();
136 XL2400_Sleep();
137 SYS_Delay(10);
138 }
139 }
140}
#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_Pin_7
Definition: fw_gpio.h:52
@ GPIO_Mode_Output_PP
Definition: fw_gpio.h:24
@ GPIO_Mode_InOut_QBD
Definition: fw_gpio.h:23
#define SPI_SetClockPrescaler(__PRE_SCALER__)
Definition: fw_spi.h:88
#define SPI_SetPort(__ALTER_PORT__)
Definition: fw_spi.h:92
#define SPI_SetDataOrder(__ORDER__)
Definition: fw_spi.h:70
@ SPI_ClockPreScaler_16
Definition: fw_spi.h:47
#define SPI_SetEnabled(__STATE__)
Definition: fw_spi.h:69
#define SPI_SetClockPolarity(__STATE__)
Definition: fw_spi.h:78
#define SPI_SetClockPhase(__PHASE__)
Definition: fw_spi.h:84
@ SPI_ClockPhase_LeadingEdge
Definition: fw_spi.h:53
#define SPI_IgnoreSlaveSelect(__STATE__)
Definition: fw_spi.h:68
#define SPI_SetMasterMode(__STATE__)
Definition: fw_spi.h:71
@ SPI_AlterPort_P35_P34_P33_P32
Definition: fw_spi.h:39
@ SPI_DataOrder_MSB
Definition: fw_spi.h:59
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_OFF
Definition: fw_types.h:70
@ 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_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
Definition: fw_uart.c:56
uint8_t * xbuf_data
Definition: ci24r1.c:18
__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
void XL2400_Sleep(void)
Definition: xl2400.c:215
#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
void SPI_Init(void)
Definition: main.c:36
#define XL2400_MODE
Definition: main.c:33