mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-02-04 22:58:10 +00:00
DSM2 bind improvement?
This commit is contained in:
parent
b2579538fa
commit
195f918543
@ -103,7 +103,7 @@ uint8_t A7105_Reset()
|
|||||||
uint8_t result;
|
uint8_t result;
|
||||||
|
|
||||||
A7105_WriteReg(0x00, 0x00);
|
A7105_WriteReg(0x00, 0x00);
|
||||||
delayMicroseconds(1000);
|
delayMilliseconds(1);
|
||||||
A7105_SetTxRxMode(TXRX_OFF); //Set both GPIO as output and low
|
A7105_SetTxRxMode(TXRX_OFF); //Set both GPIO as output and low
|
||||||
result=A7105_ReadReg(0x10) == 0x9E; //check if is reset.
|
result=A7105_ReadReg(0x10) == 0x9E; //check if is reset.
|
||||||
A7105_Strobe(A7105_STANDBY);
|
A7105_Strobe(A7105_STANDBY);
|
||||||
|
@ -90,7 +90,7 @@ uint16_t ASSAN_callback()
|
|||||||
for(uint8_t i=0;i<4;i++)
|
for(uint8_t i=0;i<4;i++)
|
||||||
packet[16+i]=packet[23-i];
|
packet[16+i]=packet[23-i];
|
||||||
packet_count=0;
|
packet_count=0;
|
||||||
delay(260);
|
delayMilliseconds(260);
|
||||||
return 10000; // Wait 270ms in total...
|
return 10000; // Wait 270ms in total...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ uint16_t ASSAN_callback()
|
|||||||
if(packet_count==20)
|
if(packet_count==20)
|
||||||
{
|
{
|
||||||
phase++;
|
phase++;
|
||||||
delay(2165);
|
delayMilliseconds(2165);
|
||||||
}
|
}
|
||||||
return 22520;
|
return 22520;
|
||||||
// Normal operation
|
// Normal operation
|
||||||
@ -134,7 +134,7 @@ uint16_t ASSAN_callback()
|
|||||||
|
|
||||||
static void __attribute__((unused)) ASSAN_initialize_txid()
|
static void __attribute__((unused)) ASSAN_initialize_txid()
|
||||||
{
|
{
|
||||||
/* //Renaud TXID with Freq=36 and alternate freq 67 or 68 or 69 or 70 or 71 or 73 or 74 or 75 or 78 and may be more...
|
/* //Renaud TXID with Freq=36 and alternate Freq 67 or 68 or 69 or 70 or 71 or 73 or 74 or 75 or 78 and may be more...
|
||||||
packet[23]=0x22;
|
packet[23]=0x22;
|
||||||
packet[22]=0x37;
|
packet[22]=0x37;
|
||||||
packet[21]=0xFA;
|
packet[21]=0xFA;
|
||||||
|
@ -117,7 +117,7 @@ void CC2500_SetTxRxMode(uint8_t mode)
|
|||||||
uint8_t CC2500_Reset()
|
uint8_t CC2500_Reset()
|
||||||
{
|
{
|
||||||
CC2500_Strobe(CC2500_SRES);
|
CC2500_Strobe(CC2500_SRES);
|
||||||
delay(1);
|
delayMilliseconds(1);
|
||||||
CC2500_SetTxRxMode(TXRX_OFF);
|
CC2500_SetTxRxMode(TXRX_OFF);
|
||||||
return CC2500_ReadReg(CC2500_0E_FREQ1) == 0xC4;//check if reset
|
return CC2500_ReadReg(CC2500_0E_FREQ1) == 0xC4;//check if reset
|
||||||
}
|
}
|
||||||
|
@ -58,13 +58,15 @@ uint8_t CYRF_ReadRegister(uint8_t address)
|
|||||||
|
|
||||||
uint8_t CYRF_Reset()
|
uint8_t CYRF_Reset()
|
||||||
{
|
{
|
||||||
|
#ifdef CYRF_RST_HI
|
||||||
CYRF_RST_HI; //Hardware reset
|
CYRF_RST_HI; //Hardware reset
|
||||||
delayMicroseconds(100);
|
delayMicroseconds(100);
|
||||||
CYRF_RST_LO;
|
CYRF_RST_LO;
|
||||||
delayMicroseconds(100);
|
delayMicroseconds(100);
|
||||||
/* CYRF_WriteRegister(CYRF_1D_MODE_OVERRIDE, 0x01); //Software reset
|
#endif
|
||||||
|
CYRF_WriteRegister(CYRF_1D_MODE_OVERRIDE, 0x01); //Software reset
|
||||||
delayMicroseconds(200);
|
delayMicroseconds(200);
|
||||||
*/ CYRF_WriteRegister(CYRF_0C_XTAL_CTRL, 0xC0); //Enable XOUT as GPIO
|
CYRF_WriteRegister(CYRF_0C_XTAL_CTRL, 0xC0); //Enable XOUT as GPIO
|
||||||
CYRF_WriteRegister(CYRF_0D_IO_CFG, 0x04); //Enable PACTL as GPIO
|
CYRF_WriteRegister(CYRF_0D_IO_CFG, 0x04); //Enable PACTL as GPIO
|
||||||
CYRF_SetTxRxMode(TXRX_OFF);
|
CYRF_SetTxRxMode(TXRX_OFF);
|
||||||
//Verify the CYRF chip is responding
|
//Verify the CYRF chip is responding
|
||||||
@ -231,7 +233,7 @@ void CYRF_FindBestChannels(uint8_t *channels, uint8_t len, uint8_t minspace, uin
|
|||||||
CYRF_ConfigCRCSeed(0x0000);
|
CYRF_ConfigCRCSeed(0x0000);
|
||||||
CYRF_SetTxRxMode(RX_EN);
|
CYRF_SetTxRxMode(RX_EN);
|
||||||
//Wait for pre-amp to switch from send to receive
|
//Wait for pre-amp to switch from send to receive
|
||||||
delayMicroseconds(1000);
|
delayMilliseconds(1);
|
||||||
for(i = 0; i < NUM_FREQ; i++)
|
for(i = 0; i < NUM_FREQ; i++)
|
||||||
{
|
{
|
||||||
CYRF_ConfigRFChannel(i);
|
CYRF_ConfigRFChannel(i);
|
||||||
|
@ -213,10 +213,8 @@ static void __attribute__((unused)) build_data_packet(uint8_t upper)//
|
|||||||
for (i = 0; i < 7; i++)
|
for (i = 0; i < 7; i++)
|
||||||
{
|
{
|
||||||
uint8_t idx = ch_map[upper * 7 + i];//1,5,2,3,0,4
|
uint8_t idx = ch_map[upper * 7 + i];//1,5,2,3,0,4
|
||||||
uint16_t value;
|
uint16_t value = 0xffff;;
|
||||||
if (idx == 0xff)
|
if (idx != 0xff)
|
||||||
value = 0xffff;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (binding)
|
if (binding)
|
||||||
{ // Failsafe position during binding
|
{ // Failsafe position during binding
|
||||||
|
@ -385,9 +385,9 @@ Model_fixed_id=0;
|
|||||||
eeprom_write_block((const void*)0,(void*)40,4);
|
eeprom_write_block((const void*)0,(void*)40,4);
|
||||||
while(1){
|
while(1){
|
||||||
LED_ON;
|
LED_ON;
|
||||||
delay(100);
|
delayMilliseconds(100);
|
||||||
LED_OFF;
|
LED_OFF;
|
||||||
delay(100);
|
delayMilliseconds(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -200,7 +200,7 @@ unsigned long micros()
|
|||||||
return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
|
return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
|
||||||
}
|
}
|
||||||
|
|
||||||
void delay(unsigned long ms)
|
void delayMilliseconds(unsigned long ms)
|
||||||
{
|
{
|
||||||
uint16_t start = (uint16_t)micros();
|
uint16_t start = (uint16_t)micros();
|
||||||
|
|
||||||
@ -419,7 +419,7 @@ int analogRead(uint8_t pin)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// without a delay, we seem to read from the wrong channel
|
// without a delay, we seem to read from the wrong channel
|
||||||
//delay(1);
|
//delayMilliseconds(1);
|
||||||
|
|
||||||
#if defined(ADCSRA) && defined(ADCL)
|
#if defined(ADCSRA) && defined(ADCL)
|
||||||
// start the conversion
|
// start the conversion
|
||||||
|
@ -199,7 +199,7 @@ void setup()
|
|||||||
memcpy((void *)PPM_data,Servo_data, sizeof(Servo_data));
|
memcpy((void *)PPM_data,Servo_data, sizeof(Servo_data));
|
||||||
|
|
||||||
//Wait for every component to start
|
//Wait for every component to start
|
||||||
delay(100);
|
delayMilliseconds(100);
|
||||||
|
|
||||||
// Read status of bind button
|
// Read status of bind button
|
||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
@ -595,8 +595,9 @@ static void protocol_init()
|
|||||||
|
|
||||||
if(next_callback>32000)
|
if(next_callback>32000)
|
||||||
{ // next_callback should not be more than 32767 so we will wait here...
|
{ // next_callback should not be more than 32767 so we will wait here...
|
||||||
delayMicroseconds(next_callback-2000);
|
uint16_t temp=next_callback>>10-2;
|
||||||
next_callback=2000;
|
delayMilliseconds(temp);
|
||||||
|
next_callback-=temp<<10; // between 2-3ms left at this stage
|
||||||
}
|
}
|
||||||
cli(); // disable global int
|
cli(); // disable global int
|
||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
@ -765,7 +766,6 @@ static void Mprotocol_serial_init()
|
|||||||
USARTC0.CTRLC = 0x2B ;
|
USARTC0.CTRLC = 0x2B ;
|
||||||
USARTC0.DATA ;
|
USARTC0.DATA ;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <util/setbaud.h>
|
#include <util/setbaud.h>
|
||||||
UBRR0H = UBRRH_VALUE;
|
UBRR0H = UBRRH_VALUE;
|
||||||
UBRR0L = UBRRL_VALUE;
|
UBRR0L = UBRRL_VALUE;
|
||||||
@ -844,8 +844,10 @@ void SPI_Write(uint8_t command)
|
|||||||
else
|
else
|
||||||
SDI_off;
|
SDI_off;
|
||||||
SCK_on;
|
SCK_on;
|
||||||
|
NOP();
|
||||||
command = command << 1;
|
command = command << 1;
|
||||||
SCK_off;
|
SCK_off;
|
||||||
|
NOP();
|
||||||
}
|
}
|
||||||
while(--n) ;
|
while(--n) ;
|
||||||
SDI_on;
|
SDI_on;
|
||||||
@ -853,8 +855,7 @@ void SPI_Write(uint8_t command)
|
|||||||
|
|
||||||
uint8_t SPI_Read(void)
|
uint8_t SPI_Read(void)
|
||||||
{
|
{
|
||||||
uint8_t result;
|
uint8_t result=0,i;
|
||||||
uint8_t i;
|
|
||||||
for(i=0;i<8;i++)
|
for(i=0;i<8;i++)
|
||||||
{
|
{
|
||||||
result=result<<1;
|
result=result<<1;
|
||||||
@ -863,6 +864,7 @@ uint8_t SPI_Read(void)
|
|||||||
SCK_on;
|
SCK_on;
|
||||||
NOP();
|
NOP();
|
||||||
SCK_off;
|
SCK_off;
|
||||||
|
NOP();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -939,7 +941,7 @@ uint32_t millis()
|
|||||||
return TotalMillis ;
|
return TotalMillis ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void delay(unsigned long ms)
|
void delayMilliseconds(unsigned long ms)
|
||||||
{
|
{
|
||||||
uint16_t start = (uint16_t)micros();
|
uint16_t start = (uint16_t)micros();
|
||||||
uint16_t lms = ms ;
|
uint16_t lms = ms ;
|
||||||
@ -952,29 +954,15 @@ void delay(unsigned long ms)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */
|
/* Important notes:
|
||||||
|
- Max value is 16000µs
|
||||||
|
- delay is not accurate due to interrupts happening */
|
||||||
void delayMicroseconds(unsigned int us)
|
void delayMicroseconds(unsigned int us)
|
||||||
{
|
{
|
||||||
// calling avrlib's delay_us() function with low values (e.g. 1 or
|
|
||||||
// 2 microseconds) gives delays longer than desired.
|
|
||||||
//delay_us(us);
|
|
||||||
|
|
||||||
// for the 16 MHz clock on most Arduino boards
|
|
||||||
|
|
||||||
// for a one-microsecond delay, simply return. the overhead
|
|
||||||
// of the function call yields a delay of approximately 1 1/8 us.
|
|
||||||
if (--us == 0)
|
if (--us == 0)
|
||||||
return;
|
return;
|
||||||
|
us <<= 2; // * 4
|
||||||
// the following loop takes a quarter of a microsecond (4 cycles)
|
us -= 2; // - 2
|
||||||
// per iteration, so execute it four times for each microsecond of
|
|
||||||
// delay requested.
|
|
||||||
us <<= 2;
|
|
||||||
|
|
||||||
// account for the time taken in the preceeding commands.
|
|
||||||
us -= 2;
|
|
||||||
|
|
||||||
// busy wait
|
|
||||||
__asm__ __volatile__ (
|
__asm__ __volatile__ (
|
||||||
"1: sbiw %0,1" "\n\t" // 2 cycles
|
"1: sbiw %0,1" "\n\t" // 2 cycles
|
||||||
"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
|
"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
|
||||||
@ -983,8 +971,7 @@ void delayMicroseconds(unsigned int us)
|
|||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
// this needs to be called before setup() or some functions won't
|
// this needs to be called before setup() or some functions won't work there
|
||||||
// work there
|
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user