diff --git a/Multiprotocol/A7105_SPI.ino b/Multiprotocol/A7105_SPI.ino index e3b59d1..1698725 100644 --- a/Multiprotocol/A7105_SPI.ino +++ b/Multiprotocol/A7105_SPI.ino @@ -196,19 +196,8 @@ const uint8_t PROGMEM FLYSKY_A7105_regs[] = { 0x13, 0xc3, 0x00, 0xff, 0x00, 0x00, 0x3b, 0x00, 0x17, 0x47, 0x80, 0x03, 0x01, 0x45, 0x18, 0x00, 0x01, 0x0f, 0xff }; - #define ID_NORMAL 0x55201041 #define ID_PLUS 0xAA201041 - -/* -static const uint8_t a7105Regs[] = { - -1, 0x42, 0x00, 0x14, 0x00, -1 , -1 , 0x00, 0x00, 0x00, 0x00, 0x01, 0x21, 0x05, 0x00, 0x50, - 0x9e, 0x4b, 0x00, 0x02, 0x16, 0x2b, 0x12, 0x00, 0x62, 0x80, 0x80, 0x00, 0x0a, 0x32, 0xc3, 0x0f, - 0x13, 0xc3, 0x00, -1, 0x00, 0x00, 0x3b, 0x00, 0x17, 0x47, 0x80, 0x03, 0x01, 0x45, 0x18, 0x00, - 0x01, 0x0f, -1, -}; -*/ - void A7105_Init(uint8_t protocol) { void *A7105_Regs; diff --git a/Multiprotocol/Hubsan_a7105.ino b/Multiprotocol/Hubsan_a7105.ino index d13bdb7..760cb4e 100644 --- a/Multiprotocol/Hubsan_a7105.ino +++ b/Multiprotocol/Hubsan_a7105.ino @@ -181,14 +181,15 @@ static void __attribute__((unused)) hubsan_build_packet() } #if defined(TELEMETRY) -/*static uint8_t hubsan_check_integrity() +static uint8_t __attribute__((unused)) hubsan_check_integrity() { - int sum = 0; + if( (packet[0]&0xFE) != 0xE0 ) + return 0; + uint8_t sum = 0; for(uint8_t i = 0; i < 15; i++) sum += packet[i]; - return packet[15] == ((256 - (sum % 256)) & 0xFF); + return ( packet[15] == (uint8_t)(-sum) ); } -*/ #endif uint16_t ReadHubsan() @@ -295,7 +296,8 @@ uint16_t ReadHubsan() } else { #if defined(TELEMETRY) - if( rfMode == A7105_TX) {// switch to rx mode 3ms after packet sent + if( rfMode == A7105_TX) + {// switch to rx mode 3ms after packet sent for( i=0; i<10; i++) { if( !(A7105_ReadReg(A7105_00_MODE) & 0x01)) {// wait for tx completion @@ -306,15 +308,23 @@ uint16_t ReadHubsan() } } } - if( rfMode == A7105_RX) { // check for telemetry frame - for( i=0; i<10; i++) { - if( !(A7105_ReadReg(A7105_00_MODE) & 0x01)) { // data received + if( rfMode == A7105_RX) + { // check for telemetry frame + for( i=0; i<10; i++) + { + if( !(A7105_ReadReg(A7105_00_MODE) & 0x01)) + { // data received A7105_ReadData(); - if( !(A7105_ReadReg(A7105_00_MODE) & 0x01)){ // data received - v_lipo=packet[13];// hubsan lipo voltage 8bits the real value is h_lipo/10(0x2A=42-4.2V) + if( hubsan_check_integrity() ) + { + v_lipo=packet[13];// hubsan lipo voltage 8bits the real value is h_lipo/10(0x2A=42 -> 4.2V) telemetry_link=1; } A7105_Strobe(A7105_RX); + // Read TX RSSI + RSSI_dBm=256-(A7105_ReadReg(A7105_1D_RSSI_THOLD)*8)/5; // value from A7105 is between 8 for maximum signal strength to 160 or less + if(RSSI_dBm<0) RSSI_dBm=0; + else if(RSSI_dBm>255) RSSI_dBm=255; break; } } @@ -344,7 +354,6 @@ uint16_t initHubsan() { packet_count=0; id_data=ID_NORMAL; #if defined(TELEMETRY) - v_lipo=0; telemetry_link=0; #endif return 10000; diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 469fbdd..d9a8430 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -100,7 +100,6 @@ uint8_t pktt[MAX_PKT];//telemetry receiving packets int16_t RSSI_dBm; //const uint8_t RSSI_offset=72;//69 71.72 values db uint8_t telemetry_link=0; - #include "telemetry.h" #endif // Callback @@ -623,11 +622,11 @@ uint16_t limit_channel_100(uint8_t ch) #if defined(TELEMETRY) void Serial_write(uint8_t data) { - uint8_t t=tx_head; - if(++t>=TXBUFFER_SIZE) - t=0; - tx_buff[t]=data; - tx_head=t; + cli(); // disable global int + if(++tx_head>=TXBUFFER_SIZE) + tx_head=0; + tx_buff[tx_head]=data; + sei(); // enable global int UCSR0B |= (1<-20 then tps = getTime() + 250 end + end sw = tpsact end diff --git a/Multiprotocol/multiprotocol.h b/Multiprotocol/multiprotocol.h index ab72a2f..793645e 100644 --- a/Multiprotocol/multiprotocol.h +++ b/Multiprotocol/multiprotocol.h @@ -13,6 +13,14 @@ along with Multiprotocol. If not, see . */ +// Check selected board type +#ifndef ARDUINO_AVR_PRO + #error You must select the board type "Arduino Pro or Pro Mini" +#endif +#if F_CPU != 16000000L || not defined(__AVR_ATmega328P__) + #error You must select the processor type "ATmega328(5V, 16MHz)" +#endif + //****************** // Protocols //****************** diff --git a/sync.ffs_db b/sync.ffs_db index 59c8138..f8a7ae0 100644 Binary files a/sync.ffs_db and b/sync.ffs_db differ diff --git a/telemetryFRSKY.fzz b/telemetryFRSKY.fzz index 7f3aed1..0a6f49a 100644 Binary files a/telemetryFRSKY.fzz and b/telemetryFRSKY.fzz differ diff --git a/telemetryFRSKY.jpg b/telemetryFRSKY.jpg index 2ce22d2..5876793 100644 Binary files a/telemetryFRSKY.jpg and b/telemetryFRSKY.jpg differ