Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to master #311

Closed
wants to merge 140 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
fe5f762
add Sleep class
jp112sdl Mar 4, 2022
d0968e4
remove dependency from external lib
jp112sdl Mar 4, 2022
68e292b
add RTC support
jp112sdl Mar 4, 2022
93d8e67
add rp2040 as supported model
jp112sdl Mar 5, 2022
2dcfa15
add simple sleep() method
jp112sdl Mar 5, 2022
5f83f7f
only add a timer is there is not already one added
jp112sdl Mar 5, 2022
3d0b110
timer does not have to be disabled while sleep
jp112sdl Mar 5, 2022
67e6b0e
hint for RPI_PICO_TimerInterrupt Lib removed
jp112sdl Mar 6, 2022
6ee7999
revert changes
jp112sdl Mar 17, 2022
7b402ba
set SPI_MODE0 only if SPI.h is included (in sketch)
jp112sdl Mar 17, 2022
6a1c2b5
Merge pull request #296 from jp112sdl/dev_rp2040
pa-pa May 2, 2022
4efdf89
use SoftSPI
jp112sdl May 28, 2022
d05be4e
add support for USE_HW_SERIAL
jp112sdl May 28, 2022
c3297da
add soft reset method
jp112sdl May 28, 2022
7e57a89
ad RTCTimer for SysClock and RTCClock
jp112sdl May 28, 2022
93fcf37
wip
jp112sdl May 28, 2022
f593f96
add internal and external battery measurement
jp112sdl May 28, 2022
b00a090
use separate interrupt handling for efm32
jp112sdl May 28, 2022
276598c
add internal eeprom emulation
jp112sdl May 28, 2022
d40c9da
fix compiler warnings
jp112sdl May 28, 2022
9e8586e
add M24M01 i2c eeprom support
jp112sdl May 28, 2022
742510c
fix chip id array order
jp112sdl Jun 1, 2022
1f5c9fb
allocate 3 pages for eeprom
jp112sdl Jun 1, 2022
e3f415b
fix for missing SPI_BITORDER_MSBFIRST
jp112sdl Jun 8, 2022
e5638bf
revoke fix
jp112sdl Jun 8, 2022
00abc51
fix for changes in Adafruit_GFX.h ad4b6b4
jp112sdl Jun 8, 2022
d977b83
add a little delay before reset to make sure all 'flash eeprom' work …
jp112sdl Jun 15, 2022
ee4f547
reworked AlarmClock
jp112sdl Jun 15, 2022
6e04a90
reworked power save
jp112sdl Jun 15, 2022
e2a7436
reworked eeprom emulation
jp112sdl Jun 15, 2022
2851c81
fix EFM32 specific routines
jp112sdl Jun 15, 2022
ba5ded9
m24mXX methods are only for EFM32
jp112sdl Jun 15, 2022
fbcbe4c
fix compiler errors with new Adafruit libs
jp112sdl Jun 15, 2022
562fa78
add EFM32 support in library information
jp112sdl Jun 28, 2022
692fab6
usw HW SPI
jp112sdl Jun 28, 2022
d9913cb
separate radio module classes for CC1101 and Si4431
jp112sdl Jul 6, 2022
effecca
fix pin
jp112sdl Jul 6, 2022
db56c32
writeReg wrapper
jp112sdl Jul 6, 2022
9b28248
make writeReg inline
jp112sdl Jul 6, 2022
be9c55c
remove compiler warnings
jp112sdl Jul 6, 2022
34376f2
add separate radio classes
jp112sdl Jul 6, 2022
7884666
update TODO, renamed GDO0 to IRQ, renamed debug messages
jp112sdl Jul 6, 2022
b4bd483
show compiler error, WOR not implemented
jp112sdl Jul 6, 2022
1da00ac
clear IRQ register before sleep
jp112sdl Jul 6, 2022
849ac86
disable some debug messages
jp112sdl Jul 6, 2022
36ae268
no compiler error on WOR
jp112sdl Jul 6, 2022
0875c95
avoid immediate EM4 to
jp112sdl Jul 8, 2022
1d8c286
add SPI_MULTIBYTE_TRANSFER
jp112sdl Jul 8, 2022
a5faa21
ensure waiting at least 100µs
jp112sdl Jul 8, 2022
22c6e2b
add writeBurst wrapper method
jp112sdl Jul 8, 2022
0eb1572
remove rev.eng. debugging stuff
jp112sdl Jul 8, 2022
26f79b7
force MISO pin to INPUT when idle
jp112sdl Jul 8, 2022
06869b4
revert to old delay values
jp112sdl Jul 8, 2022
2868124
Merge pull request #300 from jp112sdl/master
pa-pa Jul 11, 2022
115b174
entering EM4 makes trouble ^^
jp112sdl Jul 11, 2022
b7c950b
wait for SI4431_IRQ2_CHIP_READY in reset() method
jp112sdl Jul 11, 2022
f503aeb
remove sabotage flag when sabotage messages are disabled and send inf…
jp112sdl Jul 12, 2022
4945868
add an enable() method to completely dis-/enable the (Dual)StatusLed
jp112sdl Jul 12, 2022
e359505
fix compiler error
jp112sdl Jul 12, 2022
6d3935e
disable led when an info message is sent
jp112sdl Jul 13, 2022
921534b
add return
jp112sdl Jul 13, 2022
9617e32
fix wrong hal call
jp112sdl Jul 13, 2022
3848db3
moved unsetIdle
jp112sdl Jul 13, 2022
c3e297d
fix sleep
jp112sdl Jul 13, 2022
bfcb5bd
clear pending and disable SysTickIRQn before entering EM2
jp112sdl Jul 15, 2022
378eb3b
re-add accidently moved cyclic info message
jp112sdl Jul 15, 2022
5d96010
do not re-declare STRINGIZE if already defined
jp112sdl Jul 15, 2022
4d24bac
moved from RTCDRV to sl_sleeptimer due to deprecated warning
jp112sdl Jul 15, 2022
841ce69
some flitz workaround from stan23
jp112sdl Jul 16, 2022
2afe8d8
set correct flitz fix
jp112sdl Jul 16, 2022
faa324c
RFM69 implementation
Nico9n Jul 17, 2022
7caa24a
stay in EM2 when battery is critical
jp112sdl Jul 23, 2022
bce4df9
let the device check, if the eventsender sent a message. to restart c…
jp112sdl Jul 23, 2022
ea0a5e6
make buffer const
jp112sdl Aug 3, 2022
1042197
disable GDO0/nIRQ interrupt when sending
jp112sdl Aug 3, 2022
5fd308c
initialize registers for SI4431 Rev V2 (see AN415)
jp112sdl Aug 3, 2022
cd78819
use additional local wrapper for spi functions
jp112sdl Aug 3, 2022
48c25f9
add burst
jp112sdl Aug 3, 2022
973cb7d
fix spi init call
jp112sdl Aug 5, 2022
97a5129
fix typo
jp112sdl Aug 5, 2022
29dbdde
add parameter to force sending an additional message to master
jp112sdl Aug 5, 2022
91d6064
fix TwoStateChannel init order
jp112sdl Aug 5, 2022
15db889
force sending message to master
jp112sdl Aug 5, 2022
3c18c23
send on first run, too
jp112sdl Aug 5, 2022
9180b43
robust sleep/wakeup handling
stan23 Aug 8, 2022
33526e6
no magic numbers
stan23 Aug 8, 2022
d383073
cleanup
stan23 Aug 8, 2022
a52df28
Merge branch 'pa-pa:master' into dev_efm32
jp112sdl Aug 9, 2022
943851a
configFreq cleanup
stan23 Aug 11, 2022
b27b839
compile efm32
jp112sdl Aug 11, 2022
9e21693
...
jp112sdl Aug 11, 2022
38fe879
...
jp112sdl Aug 11, 2022
28fbaf4
...
jp112sdl Aug 11, 2022
51b2d45
...
jp112sdl Aug 11, 2022
2a1b9c7
...
jp112sdl Aug 11, 2022
88fba19
...
jp112sdl Aug 11, 2022
fae6cd7
...
jp112sdl Aug 11, 2022
2fa2c4e
Merge pull request #1 from jp112sdl/dev_efm32_ghaction
jp112sdl Aug 11, 2022
83f55fd
Update library.properties
pa-pa Sep 15, 2022
e316b33
add pseudo methods
jp112sdl Sep 21, 2022
419035d
remove separate efm32 section
jp112sdl Sep 21, 2022
1953edf
moved WiringPinMode for EFM32
jp112sdl Sep 21, 2022
8ab5ede
Update AskSinPP.h
pa-pa Sep 21, 2022
d935679
Update library.properties
pa-pa Sep 21, 2022
9416e99
Merge branch 'master' of https://github.com/pa-pa/AskSinPP into dev_e…
jp112sdl Sep 21, 2022
841e62b
Merge pull request #302 from jp112sdl/dev_efm32
jp112sdl Sep 21, 2022
8a0ae84
RHS_x4 added
Sep 22, 2022
ca7927b
save some bytes
Sep 22, 2022
c92629a
cmd with burn-out detection
Sep 22, 2022
f764f7c
switch to sht21
Sep 22, 2022
a1d9aa0
Update AskSinPP.h
jp112sdl Oct 11, 2022
b20601f
Consolidated AES functions into one file
trilu2000 Oct 19, 2022
4820108
Fix typo in README
henrywiechert Nov 4, 2022
8a1f3a2
Merge pull request #303 from henrywiechert/patch-1
jp112sdl Nov 6, 2022
0b0962e
das war irgendwie abhanden gekommen
jp112sdl Nov 23, 2022
e9b00c7
add waitSerial to EFM32
jp112sdl Nov 24, 2022
ed10bb1
Merge pull request #304 from jp112sdl/master
jp112sdl Nov 24, 2022
101903d
fix perl error
Dec 14, 2022
5bc817e
fix perl error
Dec 14, 2022
a34cf8d
Aufteilung der Radioklasse aus asksinpp übernommen
Nico9n Dec 25, 2022
38ff05e
Merge branch 'master' into RFM69
Nico9n Dec 25, 2022
36b2cf0
Alte Datei entfernt.
Nico9n Dec 25, 2022
d83730b
Kommentar angepasst.
Nico9n Dec 25, 2022
e0dd2cb
Debugausgaben auskommentiert.
Nico9n Dec 25, 2022
1a77671
Interrupt Fix STM32
Nico9n Dec 27, 2022
4c4b8d2
Merge pull request #305 from Nico9n/master
pa-pa Dec 28, 2022
86a7ef7
formating
Dec 28, 2022
1ecbccb
fix for undefined constants
jp112sdl Jan 3, 2023
565792f
use crc for address/serial calculation on an EFM32
jp112sdl Jan 3, 2023
bef0f31
size of EFM32 Unique ID is 64bit (8 Byte)
jp112sdl Jan 3, 2023
0a5403a
update id calculation for esp32 and rp2040
jp112sdl Jan 8, 2023
67ad7bc
Merge pull request #306 from jp112sdl/master
pa-pa Jan 9, 2023
ab4be53
fix board
jp112sdl Jan 18, 2023
a33d482
test
jp112sdl Jan 18, 2023
f496caa
Merge pull request #308 from jp112sdl/master
jp112sdl Jan 18, 2023
751715a
add ci test for asksinsniffer
jp112sdl Feb 12, 2023
4ec1cb9
Merge pull request #309 from jp112sdl/master
jp112sdl Feb 12, 2023
264d6a2
fix of delay blink function
trilu2000 Mar 4, 2023
1678573
Merge branch 'master' of https://github.com/pa-pa/AskSinPP
trilu2000 Mar 4, 2023
e45d744
Update Radio.h
trilu2000 Mar 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
stan23 committed Aug 8, 2022
commit d3830736e7317e50c10572707e4897fbf007769a
2 changes: 1 addition & 1 deletion BatterySensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ExternalVCCEFM32 : public InternalVCC {
init.timebase = ADC_TimebaseCalc(0);
init.prescale = ADC_PrescaleCalc(7000000, 0);
ADC_Init(ADC0, &init);
}
}

void start () {
ADC_InitSingle_TypeDef sInit = ADC_INITSINGLE_DEFAULT;
Expand Down
122 changes: 39 additions & 83 deletions Radio-Si4431.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@

/*
TODO
- improve IRQ handling: nIRQ does not only show "packet received", depending on configuration
- implement low power handling (not continuous RX)
- implement WoR (if possible with Si4431)

DONE
- rename GDO0 to IRQ
- HM-Sec-SCO uses 1 MHz SPI clock, HB-Sec-SCo uses 110 kHz SPI clock (softSPI?)
- manually check CRC of received packet
- merge with CC1101 implementation!

*/


Expand Down Expand Up @@ -110,9 +102,6 @@ namespace as {
#define SI4431_REG_RECEIVED_HEADER_0 0x4A
#define SI4431_REG_RECEIVED_PACKET_LENGTH 0x4B
#define SI4431_REG_ADC8_CONTROL 0x4F
#define SI4431_REG_CCTO 0x58 //Si4432 Revision V2 | ChargepumpCurrentTrimmingOverride
#define SI4431_REG_DCT 0x59 //Si4432 Revision V2 | Divider Current Trimming
#define SI4431_REG_VCT 0x5A //Si4432 Revision V2 | VCO Current Trimming register
#define SI4431_REG_CHANNEL_FILTER_COEFF 0x60
#define SI4431_REG_XOSC_CONTROL_TEST 0x62
#define SI4431_REG_AGC_OVERRIDE_1 0x69
Expand Down Expand Up @@ -166,15 +155,15 @@ namespace as {
#define SI4431_OFC1_TXON 0b00001000 // 3 3 TX_ON Tx on in manual transmit mode
#define SI4431_OFC1_RXON 0b00000100 // 2 2 RX_ON Rx on in manual receive mode
#define SI4431_OFC1_PLLON 0b00000010 // 1 1 PLL_ON PLL on (tune mode)
#define SI4431_OFC1_XTALON 0b00000001 // 0 0 XTAL_ON on (ready mode)
#define SI4431_OFC1_NONE 0 // NO_BIT_SET on (ready mode)
#define SI4431_OFC1_XTALON 0b00000001 // 0 0 XTAL_ON on (ready mode)
#define SI4431_OFC1_NONE 0 // no bit set

// SI4431_REG_OP_FUNC_CONTROL_2
#define SI4431_OFC2_RXMPK 0b00010000 // 4 4 RX_MULTIPACKET_ON
#define SI4431_OFC2_AUTOTX 0b00001000 // 3 3 AUTO_TX_ON
#define SI4431_OFC2_ENLDM 0b00000100 // 2 2 LOW_DUTY_CYCLE_ON
#define SI4431_OFC2_FFCLRRX 0b00000010 // 1 1 RX_FIFO_RESET
#define SI4431_OFC2_FFCLRTX 0b00000001 // 0 0 TX_FIFO_RESET
#define SI4431_OFC2_FFCLRRX 0b00000010 // 1 1 RX_FIFO_RESET
#define SI4431_OFC2_FFCLRTX 0b00000001 // 0 0 TX_FIFO_RESET
#define SI4431_OFC2_NONE 0 // no bit set


Expand Down Expand Up @@ -210,7 +199,7 @@ class Si4431 {
//DPRINTLN("Si4431 enter powerdown");

#ifdef USE_WOR
//#error WOR is not implemented
DPRINTLN("ERROR: WOR is not implemented for Si4431!");
#else
// enter power down state
(void)readReg(SI4431_REG_INTERRUPT_STATUS_1);
Expand Down Expand Up @@ -256,7 +245,7 @@ class Si4431 {
// TODO: add timeout

for(uint8_t i = 0; i < 200; i++) {
if( readReg(SI4431_REG_INTERRUPT_STATUS_2) & SI4431_IRQ2_CHIP_READY) {
if (readReg(SI4431_REG_INTERRUPT_STATUS_2) & SI4431_IRQ2_CHIP_READY) {
break;
}
_delay_us(100);
Expand All @@ -282,7 +271,7 @@ class Si4431 {
digitalWrite(PWRPIN, LOW);
_delay_ms(2);
}
spi.init(); // init the hardware to get access to the RF modul
spi.init();

reset();

Expand All @@ -294,7 +283,7 @@ class Si4431 {
SI4431_REG_XOSC_LOAD_CAPACITANCE, 0x6B, // 0x7F
// stock HM-Sec-SCo
//SI4431_REG_GPIO0_CONFIG, 0x1F, // 0x00 GPIO tied to GND
// stan23
// stan23 debugging
//SI4431_REG_GPIO0_CONFIG, 0x40, // 0x00 GPIO0 = POR
//SI4431_REG_GPIO0_CONFIG, 0x0A, // 0x00 GPIO0 = IO
//SI4431_REG_GPIO0_CONFIG, 0x12, // 0x00 GPIO0 = TX state
Expand All @@ -308,26 +297,17 @@ class Si4431 {
SI4431_REG_FREQUENCY_BAND_SELECT, 0x73, // 0x75 900..920 MHz band
SI4431_REG_NOM_CARRIER_FREQUENCY_1, 0x67, // 0xBB
SI4431_REG_NOM_CARRIER_FREQUENCY_0, 0xC0, // 0x80
// stock HM-Sec-SCo
SI4431_REG_HEADER_CONTROL_2, 0x0E, // 0x22 no header, sync word 3+2+1+0
SI4431_REG_SYNC_WORD_3, 0xE9, // 0x2D
SI4431_REG_SYNC_WORD_2, 0xCA, // 0xD2
SI4431_REG_SYNC_WORD_1, 0xE9, // 0x00
SI4431_REG_SYNC_WORD_0, 0xCA, // 0x00
SI4431_REG_TX_POWER, 0x1F, // 0x18 max output power
SI4431_REG_RX_FIFO_CONTROL, 0x03, // 0x37 IRQ at >3 byte in RX FIFO
// stock HM-Sec-SCo
//SI4431_REG_TX_FIFO_CONTROL_2, 0x1F, // 0x40 IRQ at <32 byte in TX FIFO
// stan23
SI4431_REG_TX_FIFO_CONTROL_2, 0x07, // 0x40 IRQ at <8 byte in TX FIFO
/* address 0x59 does not exist 0x40 */
SI4431_REG_TX_DATA_RATE_1, 0x51, // 0x0A 10 kbps
SI4431_REG_TX_DATA_RATE_0, 0xEC, // 0x3D
// stock HM-Sec-SCo
SI4431_REG_MODULATION_MODE_CONTROL_1, 0x2C, // 0x0C low data rate
SI4431_REG_VCT, 0x7F,
SI4431_REG_CCTO, 0x80,
SI4431_REG_DCT, 0x40,
SI4431_REG_FREQUENCY_DEVIATION, 0x1E, // 0x20
SI4431_REG_MODULATION_MODE_CONTROL_2, 0x22, // 0x00 FIFO mode, FSK
SI4431_REG_IF_FILTER_BANDWIDTH, 0x1E, // 0x01 620.7 kHz
Expand All @@ -343,13 +323,9 @@ class Si4431 {
SI4431_REG_CLOCK_REC_GEARSHIFT_OVERRIDE, 0x03, // 0x03
SI4431_REG_AGC_OVERRIDE_1, 0x60, // 0x20


// manually added by stan23
//SI4431_REG_DATA_ACCESS_CONTROL, 0x8A, // 0x8D no CRC as it does not fit to CC1101
SI4431_REG_DATA_ACCESS_CONTROL, 0x0A, // 0x8D no RxPkt, no CRC as it does not fit to CC1101
// manually added
SI4431_REG_DATA_ACCESS_CONTROL, 0x80, // 0x8D no TxPkt, no CRC as it does not fit to CC1101
SI4431_REG_HEADER_CONTROL_1, 0x00, // 0x0C no header check

SI4431_REG_OP_FUNC_CONTROL_1, 0x01, /* why again? -> keep XTAL running */
};

bool initOK = true;
Expand Down Expand Up @@ -394,10 +370,10 @@ class Si4431 {
}

void flushRx () {
// DPRINTLN("Si4431 flushRx");
//DPRINTLN("Si4431 flushRx");
// set and clear bit FIFO Clear RX
writeReg(SI4431_REG_OP_FUNC_CONTROL_2, SI4431_OFC2_FFCLRRX);
writeReg(SI4431_REG_OP_FUNC_CONTROL_2, 0);
writeReg(SI4431_REG_OP_FUNC_CONTROL_2, SI4431_OFC2_NONE);
}

bool detectBurst () {
Expand All @@ -420,7 +396,6 @@ class Si4431 {
#define CRC16_POLY 0x8005

uint16_t calcCrcWorker(uint8_t crcData, uint16_t crcReg) {
// DPRINT(" crcWorker in:");DHEX(crcData);DPRINT(" crc:");DHEX(crcReg);DPRINTLN("");
for (uint8_t i = 0; i < 8; i++) {
if (((crcReg & 0x8000) >> 8) ^ (crcData & 0x80))
crcReg = (crcReg << 1) ^ CRC16_POLY;
Expand All @@ -443,7 +418,7 @@ class Si4431 {


void whitenBuffer(uint8_t *buf, uint8_t len, uint8_t offset=0) {
uint8_t pn9[] = {
const uint8_t pn9[] = {
0xFF, 0xE1, 0x1D, 0x9A, 0xED, 0x85, 0x33, 0x24, 0xEA, 0x7A,
0xD2, 0x39, 0x70, 0x97, 0x57, 0x0A, 0x54, 0x7D, 0x2D, 0xD8,
0x6D, 0x0D, 0xBA, 0x8F, 0x67, 0x59, 0xC7, 0xA2, 0xBF, 0x34,
Expand All @@ -464,6 +439,7 @@ class Si4431 {
}

uint8_t sndData(uint8_t *buf, uint8_t size, __attribute__ ((unused)) uint8_t burst) {
// sndData() is called while nIRQ is disabled in Radio.h, so the GPIO can be safely polled for status changes
//DPRINTLN("Si4431 sndData -----------------------------------");

//DPRINT(" buf: ");DHEX(buf, size);DPRINTLN("");
Expand All @@ -477,8 +453,6 @@ class Si4431 {
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA};
static const uint8_t syncword[4] = {0xE9, 0xCA, 0xE9, 0xCA};

// TODO: disable the IRQ so that nIRQ can be used for polling
//HWRADIO::disable();

crc = calculateCrc(buf, size);
//DPRINT(" calculated CRC: ");DHEX(crc);DPRINTLN("");
Expand All @@ -503,8 +477,6 @@ class Si4431 {
(void)readReg(SI4431_REG_INTERRUPT_STATUS_1);
(void)readReg(SI4431_REG_INTERRUPT_STATUS_2);

// only RX packet handling
writeReg(SI4431_REG_DATA_ACCESS_CONTROL, 0x80);
// TODO: is the transmit size necessary if packet mode is not used?
writeReg(SI4431_REG_TRANSMIT_PACKET_LENGTH, size + 1);

Expand All @@ -517,8 +489,8 @@ class Si4431 {
writeReg(SI4431_REG_INTERRUPT_ENABLE_1, SI4431_IRQ1_TX_FIFO_ALMOST_EMPTY);

//fill the FIFO with 64bytes of burstPacket
writeBurst(SI4431_REG_FIFO_ACCESS, preambleLong, 32);
writeBurst(SI4431_REG_FIFO_ACCESS, preambleLong, 32);
writeBurst(SI4431_REG_FIFO_ACCESS, preambleLong, sizeof(preambleLong));
writeBurst(SI4431_REG_FIFO_ACCESS, preambleLong, sizeof(preambleLong));

//set TX on
writeReg(SI4431_REG_OP_FUNC_CONTROL_1, SI4431_OFC1_XTALON | SI4431_OFC1_TXON);
Expand All @@ -529,7 +501,7 @@ class Si4431 {
for (uint8_t t = 0; t < 12; t++) {
(void)readReg(SI4431_REG_INTERRUPT_STATUS_1);
(void)readReg(SI4431_REG_INTERRUPT_STATUS_2);
writeBurst(SI4431_REG_FIFO_ACCESS, preambleLong, 32);
writeBurst(SI4431_REG_FIFO_ACCESS, preambleLong, sizeof(preambleLong));
for(uint16_t i = 0; i < 3000; i++) { if( digitalRead(IRQPIN) == LOW ) { break; } _delay_us(10); }
}
}
Expand All @@ -552,13 +524,12 @@ class Si4431 {
writeReg(SI4431_REG_OP_FUNC_CONTROL_1, SI4431_OFC1_RXON | SI4431_OFC1_XTALON);
//set nIRQ to trigger RX received
writeReg(SI4431_REG_INTERRUPT_ENABLE_1, SI4431_IRQ1_VALID_PACKET_RECEIVED);
(void)readReg(SI4431_REG_DEVICE_STATUS);
return true;
}


uint8_t rcvData(uint8_t *buf, uint8_t size) {
// DPRINTLN("Si4431 rcvData -----------------------------------");
//DPRINTLN("Si4431 rcvData -----------------------------------");

// disable receiver
writeReg(SI4431_REG_OP_FUNC_CONTROL_1, SI4431_OFC1_XTALON);
Expand All @@ -568,49 +539,34 @@ class Si4431 {

uint8_t packetBytes = 0;
uint8_t rxBytes = 0;
uint8_t fifoBytes = 0;
if (readReg(SI4431_REG_HEADER_CONTROL_2) & 0x08) {
fifoBytes = readReg(SI4431_REG_TRANSMIT_PACKET_LENGTH);
} else {
fifoBytes = readReg(SI4431_REG_RECEIVED_PACKET_LENGTH);
}
// DPRINT(" RX FIFO: ");DHEXLN(fifoBytes);
// overflow detected - flush the FIFO
// TODO: overflow is signaled by IRQ
if( fifoBytes > 0 ) {
// read packet length and whiten it
packetBytes = readReg(SI4431_REG_FIFO_ACCESS) ^ 0xFF;
// DPRINT(" FIFO len: ");DHEX(fifoBytes);DPRINT(" packetBytes: ");DHEX(packetBytes);DPRINT(" (");DHEX((uint8_t)(packetBytes^0xFF));DPRINTLN(")");
// check that packet fits into the buffer
if (packetBytes <= size) {
// read packetSize bytes + 2 for CRC
readBurst(buf, SI4431_REG_FIFO_ACCESS, packetBytes + 2);
// DPRINT(" buffer: ");DHEX(buf, packetBytes);DPRINT(" CRC: ");DHEX(&buf[packetBytes], 2);DPRINTLN("");
// len is already whitened, so use offset of 1
whitenBuffer(buf, packetBytes + 2, 1);
// DPRINT(" bufWhi: ");DHEX(buf, packetBytes);DPRINT(" CRC: ");DHEX(&buf[packetBytes], 2);DPRINTLN("");
uint16_t crcCalc = calculateCrc(buf, packetBytes);
// DPRINT(" calculated CRC: ");DHEXLN(crcCalc);
if (crcCalc == (buf[packetBytes] << 8 | buf[packetBytes+1])) {
rxBytes = packetBytes;
} else {
DPRINTLN(" CRC failed!");
//DHEXLN((uint16_t)(buf[packetBytes] << 8 | buf[packetBytes+1]));
}
calculateRSSI(readReg(SI4431_REG_RSSI));
}
else {
DPRINT(F("Packet too big: "));DDECLN(packetBytes);

// TODO: handle RX FIFO overflow, signaled by IRQ registers
// read packet length and whiten it
packetBytes = readReg(SI4431_REG_FIFO_ACCESS) ^ 0xFF;
// check that packet fits into the buffer
if (packetBytes <= size) {
// read packetSize bytes + 2 for CRC
readBurst(buf, SI4431_REG_FIFO_ACCESS, packetBytes + 2);
// len is already whitened, so use offset of 1
whitenBuffer(buf, packetBytes + 2, 1);
uint16_t crcCalc = calculateCrc(buf, packetBytes);
if (crcCalc == (buf[packetBytes] << 8 | buf[packetBytes+1])) {
rxBytes = packetBytes;
} else {
DPRINTLN(" CRC failed!");
}
calculateRSSI(readReg(SI4431_REG_RSSI));
}
else {
DPRINT(F("Packet too big: "));DDECLN(packetBytes);
}

// clear interrupts
(void)readReg(SI4431_REG_INTERRUPT_STATUS_1);
(void)readReg(SI4431_REG_INTERRUPT_STATUS_2);


// DPRINT("-> ");
// DHEXLN(buf+1,rxBytes);
//DPRINT("-> ");
//DHEXLN(buf+1,rxBytes);
flushRx();

// enable Rx
Expand Down