diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index fe26da4..b3278a7 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 1 -#define VERSION_PATCH_LEVEL 67 +#define VERSION_PATCH_LEVEL 68 //****************** // Protocols diff --git a/Multiprotocol/NRF24l01_SPI.ino b/Multiprotocol/NRF24l01_SPI.ino index df0e31b..cdf81fb 100644 --- a/Multiprotocol/NRF24l01_SPI.ino +++ b/Multiprotocol/NRF24l01_SPI.ino @@ -529,7 +529,7 @@ boolean XN297_ReadPayload(uint8_t* msg, uint8_t len) } uint8_t XN297_ReadEnhancedPayload(uint8_t* msg, uint8_t len) -{ //!!! Don't forget do a +2 and if using CRC add +2 on any of the used NRF24L01_11_RX_PW_Px !!! +{ //!!! Don't forget do a +2 and if using CRC add +4 on any of the used NRF24L01_11_RX_PW_Px !!! uint8_t buffer[32]; uint8_t pcf_size; // pcf payload size if (xn297_crc) diff --git a/Multiprotocol/OMP_cc2500.ino b/Multiprotocol/OMP_cc2500.ino index 00ba86b..f0fc82c 100644 --- a/Multiprotocol/OMP_cc2500.ino +++ b/Multiprotocol/OMP_cc2500.ino @@ -121,9 +121,10 @@ static void __attribute__((unused)) OMP_init() //Config NRF option=0; // Select the NRF XN297L_Init(); - NRF24L01_SetTxRxMode(TXRX_OFF); // Turn it off for now + XN297_Configure(_BV(NRF24L01_00_EN_CRC)); XN297_SetRXAddr(rx_tx_addr, 5); // Set the RX address - NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, OMP_PAYLOAD_SIZE + 2); // packet length +2 bytes of CRC + NRF24L01_SetTxRxMode(TXRX_OFF); // Turn it off for now + NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, OMP_PAYLOAD_SIZE + 4); // packet length +4 bytes of PCF+CRC #endif } @@ -141,6 +142,19 @@ static void __attribute__((unused)) OMP_initialize_txid() #endif } +static void __attribute__((unused)) OMP_Send_Telemetry(uint8_t v) +{ + v_lipo1=v; + telemetry_counter++; //LQI + telemetry_link=1; + if(telemetry_lost) + { + telemetry_lost = 0; + packet_count = 100; + telemetry_counter = 100; + } +} + enum { OMP_BIND = 0x00, OMP_PREPDATA = 0x01, @@ -178,32 +192,49 @@ uint16_t OMP_callback() { if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR)) { // a packet has been received - if(XN297_ReadEnhancedPayload(packet_in, 16) == 16) + if(XN297_ReadEnhancedPayload(packet_in, OMP_PAYLOAD_SIZE) == OMP_PAYLOAD_SIZE) { // packet with good CRC and length #ifdef OMP_TELEM_DEBUG - for(uint8_t i=0;i<16;i++) + debug("OK :"); + for(uint8_t i=0;i255) - v_lipo1=255; - else - v_lipo1=v; - telemetry_link=1; - if(telemetry_lost) - { - telemetry_lost = 0; - packet_count = 100; - telemetry_counter = 100; + if(v>255) v=255; + v_lipo2=v; + OMP_Send_Telemetry(v); + } + else + { // As soon as the motor spins the telem packets are becoming really bad and the CRC throws most of them in error as it should but... + #ifdef OMP_TELEM_DEBUG + debug("NOK:"); + for(uint8_t i=0;i180) + { //voltage is less than 13V and more than 9V (3V/element) + if(v>255) v=255; + uint16_t v1=v-v_lipo2; + if(v1&0x8000) v1=-v1; + if(v1<20) // the batt voltage is within 1V from a good reading... + { + OMP_Send_Telemetry(v); // ok to send + #ifdef OMP_TELEM_DEBUG + debug(" OK"); + #endif + } + } } + else + telemetry_counter++; //LQI } #ifdef OMP_TELEM_DEBUG - else - debug("Bad RX"); - debugln(""); + debugln(""); #endif } NRF24L01_SetTxRxMode(TXRX_OFF); @@ -235,6 +266,7 @@ uint16_t OMP_callback() break; } } + NRF_CE_on; PE1_on;PE2_off; // NRF24L01 antenna RF3 phase = OMP_DATA; return OMP_PACKET_PERIOD-OMP_WRITE_TIME;