ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
ci24r1.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#include "ci24r1.h"
16
19
21{
22 uint8_t i = 0;
25 for (i = 0; i < 8; i++)
26 {
28 if (value & 0x80)
29 {
31 }
32 else
33 {
35 }
37 value = value << 1;
38 }
40}
41
43{
44 uint8_t i = 0, RxData;
45
48 for (i = 0; i < 8; i++)
49 {
50 RxData = RxData << 1;
52 if (CI24R1_DATA_READ())
53 {
54 RxData |= 0x01;
55 }
56 else
57 {
58 RxData &= 0xfe;
59 }
61 }
63 return RxData;
64}
65
67{
72}
73
75{
76 uint8_t reg_val;
79 reg_val = CI24R1_ReadByte();
81 return reg_val;
82}
83
85{
89}
90
91void CI24R1_WriteFromBuf(uint8_t reg, const uint8_t *pBuf, uint8_t len)
92{
93 uint8_t ctr;
96 for (ctr = 0; ctr < len; ctr++)
97 {
98 CI24R1_WriteByte(*pBuf++);
99 }
101}
102
104{
105 uint8_t ctr;
107 CI24R1_WriteByte(reg);
108 for (ctr = 0; ctr < len; ctr++)
109 {
110 pBuf[ctr] = CI24R1_ReadByte();
111 }
113
114}
115
117{
120 value &= 0xFE;
122}
123
125{
128 value |= 0x01;
130}
131
133{
139 for (i = 0; i < 5; i++) {
140 UART1_TxHex(*(xbuf + i));
141 if (*(xbuf + i) != *ptr++) return HAL_ERROR;
142 }
143 return HAL_OK;
144}
145
147{
150}
151
153{
155}
156
158{
159 if (channel > 125) channel = 125;
161}
162
163void CI24R1_Init(void)
164{
166#if (CI24R1_PLOAD_WIDTH == 0)
167 // Enable dynamic payload length on pipe 0 and pipe 1
170#else
171 // Fixed payload length
174 // Length of pipe 0
176 // Length of pipe 1
178#endif
180 // Enable auto ack all pipes
182 // Enable all pipes
184 // Address width, 0x1:3bytes, 0x02:4bytes, 0x3:5bytes
186 // Resend 500us and 3 times. interval: 250us * ([0, 15] + 1), retries: [0, 15]
188 // RF Data Rate 250K 11db
191}
192
193uint8_t CI24R1_Tx(uint8_t *ucPayload, uint8_t length)
194{
195 uint8_t status;
196#if (CI24R1_PLOAD_WIDTH == 0)
198#else
200#endif
204 while (CI24R1_DATA_READ());
207 status = CI24R1_ReadStatus();
208 if (status & CI24R1_FLAG_MAX_RT)
209 {
211 }
212 // Clear status flags
214 return status;
215}
216
218{
219 uint8_t i, status, rxplWidth;
223 while(CI24R1_DATA_READ());
226 status = CI24R1_ReadStatus();
227 UART1_TxChar('>');
228 UART1_TxHex(status);
229 if (status & CI24R1_FLAG_RX_READY)
230 {
231#if CI24R1_PLOAD_WIDTH == 0
233#else
234 rxplWidth = CI24R1_PLOAD_WIDTH;
235#endif
236 // Read RX to buffer
238 // Clear status flags
240 UART1_TxChar('>');
241 for (i = 0; i < rxplWidth; i++)
242 {
243 UART1_TxHex(*(xbuf_data + i));
244 }
245 }
246 return status;
247}
248
250{
252}
253
255{
256 uint8_t val;
257
259 val &= 0x3F;
260 val |= (af & 0x03) << 6;
262
264 val &= 0x3F;
265 val |= (af & 0x0C) << 4;
267}
268
270{
271 uint8_t i, status;
272
273 UART1_TxString("[Config]");
275
276 UART1_TxString(" [EN_AA]");
278
279 UART1_TxString(" [EN_RxAddr]");
281
282 UART1_TxString(" [AddrWidth]");
284
285 UART1_TxString(" [Retry]");
287
288 UART1_TxString("\r\n[RF_Channel]");
290
291 UART1_TxString(" [RF_Setup]");
293
294 UART1_TxString(" [Observe_Tx]");
296
297 UART1_TxString(" [RSSI]");
299
300 UART1_TxString("\r\n[TxAddr] ");
302 for (i = 0; i < 5; i++) {
303 UART1_TxHex(*(xbuf_data + i));
304 }
305
306 UART1_TxString("\r\n[RxAddrP0]");
308 for (i = 0; i < 5; i++) {
309 UART1_TxHex(*(xbuf_data + i));
310 }
311 UART1_TxString(" [RxAddrP1]");
313 for (i = 0; i < 5; i++) {
314 UART1_TxHex(*(xbuf_data + i));
315 }
316 UART1_TxString(" [RxAddrP2]");
318 UART1_TxString(" [RxAddrP3]");
320 UART1_TxString(" [RxAddrP4]");
322 UART1_TxString(" [RxAddrP5]");
324
325 UART1_TxString("\r\n[0F_CRC]");
328
329 UART1_TxString(" [0F_OSC_C]");
332
333 UART1_TxString(" [0F_BT]");
336
337 UART1_TxString(" [0F_BT_CRC_L/M/H]");
344
345 UART1_TxString("\r\n[RX_PW_P0]");
347 UART1_TxString(" [RX_PW_P1]");
349 UART1_TxString(" [RX_PW_P2]");
351 UART1_TxString(" [RX_PW_P3]");
353 UART1_TxString(" [RX_PW_P4]");
355 UART1_TxString(" [RX_PW_P5]");
357
358 UART1_TxString("\r\n[FIFO_Status]");
360
361 UART1_TxString(" [DynPloadWidth]");
363
364 UART1_TxString(" [Feature]");
366
367 status = CI24R1_ReadStatus();
368 UART1_TxString("\r\n[Status]");
369 UART1_TxHex(status);
370 UART1_TxString("\r\n\r\n");
371 return status;
372}
value
Definition: DS18B20_ATY.c:216
uint8_t * xbuf_data
Definition: ci24r1.c:18
uint8_t CI24R1_ReadStatus(void)
Definition: ci24r1.c:249
void CI24R1_WriteFromBuf(uint8_t reg, const uint8_t *pBuf, uint8_t len)
Definition: ci24r1.c:91
void CI24R1_SetTxAddress(uint8_t *address)
Definition: ci24r1.c:146
uint8_t CI24R1_ReadReg(uint8_t reg)
Definition: ci24r1.c:74
void CI24R1_Switch1F_AF(uint8_t af)
Definition: ci24r1.c:254
uint8_t CI24R1_ReadByte(void)
Definition: ci24r1.c:42
__IDATA uint8_t cbuf[2]
Definition: ci24r1.c:17
void CI24R1_SetChannel(uint8_t channel)
Definition: ci24r1.c:157
void CI24R1_SetTxMode(void)
Definition: ci24r1.c:116
void CI24R1_WriteByte(uint8_t value)
Definition: ci24r1.c:20
void CI24R1_WriteReg(uint8_t reg, uint8_t value)
Definition: ci24r1.c:66
uint8_t CI24R1_Tx(uint8_t *ucPayload, uint8_t length)
Definition: ci24r1.c:193
void CI24R1_SetRxAddress(uint8_t *address)
Definition: ci24r1.c:152
void CI24R1_SetRxMode(void)
Definition: ci24r1.c:124
void CI24R1_WriteCmd(uint8_t cmd)
Definition: ci24r1.c:84
uint8_t CI24R1_Rx(void)
Definition: ci24r1.c:217
__IDATA uint8_t xbuf[CI24R1_PLOAD_MAX_WIDTH+1]
Definition: ci24r1.c:17
void CI24R1_Init(void)
Definition: ci24r1.c:163
void CI24R1_ReadToBuf(uint8_t reg, uint8_t *pBuf, uint8_t len)
Definition: ci24r1.c:103
uint8_t CI24R1_SPI_Test(void)
Definition: ci24r1.c:132
uint8_t CI24R1_PrintStatus(void)
Definition: ci24r1.c:269
#define CI24R1_REG_RX_PW_P1
Definition: ci24r1.h:85
#define CI24R1_DATA_IN()
Definition: ci24r1.h:28
#define CI24R1_CMD_SELIRQ
Definition: ci24r1.h:60
#define CI24R1_NSS_LOW()
Definition: ci24r1.h:36
#define CI24R1_EN_RXADDR_BT
Definition: ci24r1.h:99
#define CI24R1_REG_DYNPD
Definition: ci24r1.h:91
#define CI24R1_CMD_R_REGISTER
Definition: ci24r1.h:46
#define CI24R1_PLOAD_WIDTH
Definition: ci24r1.h:21
#define CI24R1_REG_RSSI
Definition: ci24r1.h:72
#define CI24R1_RF_SETUP_11DB
Definition: ci24r1.h:104
#define CI24R1_REG_RX_PW_P5
Definition: ci24r1.h:89
#define CI24R1_REG_FIFO_STATUS
Definition: ci24r1.h:90
#define CI24R1_REG_TX_ADDR
Definition: ci24r1.h:83
#define CI24R1_DATA_OUT()
Definition: ci24r1.h:27
#define CI24R1_EN_RXADDR_BT_CRC_M
Definition: ci24r1.h:101
#define CI24R1_REG_FEATURE
Definition: ci24r1.h:92
#define CI24R1_EN_RXADDR_BT_CRC_H
Definition: ci24r1.h:102
#define CI24R1_REG_RX_PW_P4
Definition: ci24r1.h:88
#define CI24R1_CE_HIGH()
Definition: ci24r1.h:40
#define CI24R1_REG_RX_ADDR_P2
Definition: ci24r1.h:75
#define CI24R1_REG_RX_ADDR_P1
Definition: ci24r1.h:74
#define CI24R1_FLAG_RX_READY
Definition: ci24r1.h:118
#define CI24R1_CMD_NOP
Definition: ci24r1.h:56
#define CI24R1_REG_RX_ADDR_P3
Definition: ci24r1.h:76
#define CI24R1_TEST_ADDR
Definition: ci24r1.h:123
#define CI24R1_DATA_READ()
Definition: ci24r1.h:31
#define CI24R1_PLOAD_MAX_WIDTH
Definition: ci24r1.h:122
#define CI24R1_REG_RX_PW_P2
Definition: ci24r1.h:86
#define CI24R1_CLK_HIGH()
Definition: ci24r1.h:34
#define CI24R1_CMD_FLUSH_RX
Definition: ci24r1.h:51
#define CI24R1_REG_SETUP_AW
Definition: ci24r1.h:66
#define CI24R1_REG_OBSERVE_TX
Definition: ci24r1.h:71
#define CI24R1_EN_RXADDR_OSC_C
Definition: ci24r1.h:98
#define CI24R1_CMD_SELSPI
Definition: ci24r1.h:59
#define CI24R1_REG_RF_CH
Definition: ci24r1.h:68
#define CI24R1_REG_EN_AA
Definition: ci24r1.h:64
#define CI24R1_REG_SETUP_RETR
Definition: ci24r1.h:67
#define CI24R1_RF_SETUP_1M
Definition: ci24r1.h:114
#define CI24R1_REG_RF_SETUP
Definition: ci24r1.h:69
#define CI24R1_CMD_R_RX_PL_WID
Definition: ci24r1.h:53
#define CI24R1_EN_RXADDR_CRC
Definition: ci24r1.h:97
#define CI24R1_CMD_W_TX_PAYLOAD
Definition: ci24r1.h:49
#define CI24R1_CMD_FLUSH_TX
Definition: ci24r1.h:50
#define CI24R1_DATA_HIGH()
Definition: ci24r1.h:30
#define CI24R1_REG_RX_PW_P0
Definition: ci24r1.h:84
#define CI24R1_NSS_HIGH()
Definition: ci24r1.h:37
#define CI24R1_FLAG_MAX_RT
Definition: ci24r1.h:120
#define CI24R1_REG_RX_ADDR_P4
Definition: ci24r1.h:77
#define CI24R1_REG_RX_ADDR_P0
Definition: ci24r1.h:73
#define CI24R1_DATA_LOW()
Definition: ci24r1.h:29
#define CI24R1_REG_EN_RXADDR
Definition: ci24r1.h:65
#define CI24R1_EN_RXADDR_BT_CRC_L
Definition: ci24r1.h:100
#define CI24R1_CE_LOW()
Definition: ci24r1.h:39
#define CI24R1_CMD_R_RX_PAYLOAD
Definition: ci24r1.h:48
#define CI24R1_REG_STATUS
Definition: ci24r1.h:70
#define CI24R1_CMD_W_REGISTER
Definition: ci24r1.h:47
#define CI24R1_REG_CONFIG
Definition: ci24r1.h:63
#define CI24R1_REG_RX_PW_P3
Definition: ci24r1.h:87
#define CI24R1_CLK_LOW()
Definition: ci24r1.h:33
#define CI24R1_REG_RX_ADDR_P5AF
Definition: ci24r1.h:78
@ HAL_ERROR
Definition: fw_types.h:77
@ HAL_OK
Definition: fw_types.h:76
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
void UART1_TxHex(uint8_t hex)
Definition: fw_uart.c:79
uint8_t val[MAX7219_BLOCKS]
uint8_t __XDATA i