ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
nrf24l01_stc8h1k.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
29#include "nrf24l01.h"
30#include <stdio.h>
31
33extern uint8_t __IDATA xbuf[NRF24_PLOAD_WIDTH + 1];
34
35void SPI_Init(void)
36{
37 // SPI frequency
39 // Clock is low when idle
41 // Data transfer is driven by lower SS pin
43 // MSB first
45 // Define the output pins
47 // Ignore SS pin, use MSTR to swith between master/slave mode
49 // Master mode
51 // Start SPI
53}
54
55void GPIO_Init(void)
56{
57 // Configure GPIO pins before SPI and device
58 // MISO(P33) MOSI(P34)
60 // SCLK(P32) CSN(P35) CE(P37)
62 // IRQ(P36)
64}
65
67{
70}
71
73{
75}
76
77void main(void)
78{
79 uint8_t __CODE tmp[] = {
80 0x1F, 0x80, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
81 0x21, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x28,
82 0x31, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x38,
83 0x41, 0x12, 0x13, 0x14, 0x15, 0x16, 0x37, 0x48};
84 uint8_t succ = 0, err = 0;
85
87
88 GPIO_Init();
89 // UART1, baud 115200, baud source Timer1, 1T mode, no interrupt
91 UART1_TxString("UART Initialized\r\n");
92
93 SPI_Init();
94 UART1_TxString("SPI Initialized\r\n");
95
96 while (NRF24L01_Check() == 1)
97 {
98 UART1_TxString("Check failed\r\n");
99 SYS_Delay(1000);
100 }
101 UART1_TxString("NRF24L01 Checked\r\n");
102
103 switch (CURRENT_SCEN)
104 {
105 case NRF24_SCEN_TX:
107 UART1_TxString("NRF24L01 Initialized\r\n");
108 while (1)
109 {
110 if (NRF24L01_WriteFast(tmp) == 0)
111 {
113 err++;
114 }
115 else
116 {
117 succ++;
118 }
119 if (err >= 255 || succ >= 255)
120 {
121 UART1_TxHex(err);
122 UART1_TxHex(succ);
123 UART1_TxChar('.');
124 err = 0;
125 succ = 0;
126 }
127 SYS_Delay(50);
128 }
129 break;
130
131 case NRF24_SCEN_RX:
133 INT_Init();
134 while (1);
135 break;
136
139 INT_Init();
140 while (1)
141 {
142 NRF24L01_Tx(tmp);
143 SYS_Delay(1000);
144 }
145 break;
146
147 default:
148 UART1_TxString("Unknown scen\r\n");
149 break;
150 }
151}
#define EXTI_Int2_SetIntState(__STATE__)
Definition: fw_exti.h:140
#define EXTI_Global_SetIntState(__STATE__)
Definition: fw_exti.h:115
#define EXTI_VectInt2
Definition: fw_exti.h:47
#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_6
Definition: fw_gpio.h:51
@ GPIO_Pin_7
Definition: fw_gpio.h:52
@ GPIO_Mode_Input_HIP
Definition: fw_gpio.h:25
@ 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_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_TxChar(char dat)
Definition: fw_uart.c:72
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
uint8_t NRF24L01_WriteFast(const void *pBuf)
Definition: nrf24l01.c:149
void NRF24L01_Init(NRF24_MODE mode)
Definition: nrf24l01.c:181
void NRF24L01_ResetTX(void)
Definition: nrf24l01.c:161
uint8_t NRF24L01_Check(void)
Definition: nrf24l01.c:168
void NRF24L01_Tx(uint8_t *pBuf)
Definition: nrf24l01.c:131
void NRF24L01_HandelIrqFlag(void)
Definition: nrf24l01.c:111
NRF24_SCEN
Definition: nrf24l01.h:111
@ NRF24_SCEN_HALF_DUPLEX
Definition: nrf24l01.h:114
@ NRF24_SCEN_TX
Definition: nrf24l01.h:113
@ NRF24_SCEN_RX
Definition: nrf24l01.h:112
@ NRF24_MODE_TX
Definition: nrf24l01.h:107
@ NRF24_MODE_RX
Definition: nrf24l01.h:106
#define NRF24_PLOAD_WIDTH
Definition: nrf24l01.h:101
void SPI_Init(void)
INTERRUPT(Int2_Routine, EXTI_VectInt2)
uint8_t __IDATA xbuf[NRF24_PLOAD_WIDTH+1]
Definition: ci24r1.c:17
void main(void)
void INT_Init()
void GPIO_Init(void)
const NRF24_SCEN CURRENT_SCEN