Mini-Z, Kyosho Mini-Z Racer, MR-03, MR-02, MA-010, Forums, News, Pictures, Parts, and Shop - Mini-ZRacer.com
Forums, Mini-Z, MiniZ, Kyosho Mini-Z, Kyosho MiniZ, Kyosho Mini-Z Racer
Mini-Z Hop-Ups, Mini-Z Parts, MiniZ Hop-Ups, MiniZ Parts, Kyosho Mini-Z Hop-Ups, Kyosho Mini-Z Parts, Kyosho MiniZ Hop-Ups, Kyosho MiniZ Parts, Kyosho Mini-Z Racer Hop-Ups, Racer Kyosho Mini-Z Parts
Prev Previous Post   Next Post Next
Old 2020.11.13, 01:01 PM   #1
CrazyRussian
Registered User
 
CrazyRussian's Avatar
 
Join Date: Nov 2020
Location: Moscow
Posts: 9
Self made FHS TX module, PPM, 2 USD cost

Hello,

I made diy FHS tx module with Arduino Mini Pro 3.3V and A7105 board for cost of 2-3 USD.

Link to original tread.

Soldering plan.

Video, how I put it to Radiolink RC3S radio.

Code for Arduino:
PHP Code:

// **********************************************************
// ******************   Flysky Tx Code   ********************
//               by midelic on RCgroups.com 
//            Thanks to PhracturedBlue,ThierryRC
//            Hasi for his arduino PPM decoder 
//     Thanks to Philip Cowzer(Sadsack)for testing this version  
// ************************************************************
//Hardware any M8/M168/M328 setup(arduino promini,duemilanove...aso)
// !!! take care when flashing the AVR, the A7105 RF chip supports 3.6V max !!!
// !!!  use a 3.3V programmer or disconnect the RF module when flashing.    !!!
//DIY "FlySky" RF module  http://www.rcgroups.com/forums/showthread.php?t=1921870


#define SERIAL_BAUD_RATE 115200 //
//#define DEBUG

static const uint8_t A7105_regs[] = {
    
0xff0x420x000x140x000xff0xff ,0x000x000x000x000x010x210x050x000x50,
    
0x9e0x4b0x000x020x160x2b0x120x000x620x800x800x000x0a0x320xc30x0f,
    
0x130xc30x000xff0x000x000x3b0x000x170x470x800x030x010x450x180x00,
    
0x010x0f0xff,
};
static const 
uint8_t tx_channels[16][16] = {
  {
0x0a0x5a0x140x640x1e0x6e0x280x780x320x820x3c0x8c0x460x960x500xa0},
  {
0xa00x500x960x460x8c0x3c0x820x320x780x280x6e0x1e0x640x140x5a0x0a},
  {
0x0a0x5a0x500xa00x140x640x460x960x1e0x6e0x3c0x8c0x280x780x320x82},
  {
0x820x320x780x280x8c0x3c0x6e0x1e0x960x460x640x140xa00x500x5a0x0a},
  {
0x280x780x0a0x5a0x500xa00x140x640x1e0x6e0x3c0x8c0x320x820x460x96},
  {
0x960x460x820x320x8c0x3c0x6e0x1e0x640x140xa00x500x5a0x0a0x780x28},
  {
0x500xa00x280x780x0a0x5a0x1e0x6e0x3c0x8c0x320x820x460x960x140x64},
  {
0x640x140x960x460x820x320x8c0x3c0x6e0x1e0x5a0x0a0x780x280xa00x50},
  {
0x500xa00x460x960x3c0x8c0x280x780x0a0x5a0x320x820x1e0x6e0x140x64},
  {
0x640x140x6e0x1e0x820x320x5a0x0a0x780x280x8c0x3c0x960x460xa00x50},
  {
0x460x960x3c0x8c0x500xa00x280x780x0a0x5a0x1e0x6e0x320x820x140x64},
  {
0x640x140x820x320x6e0x1e0x5a0x0a0x780x280xa00x500x8c0x3c0x960x46},
  {
0x460x960x0a0x5a0x3c0x8c0x140x640x500xa00x280x780x1e0x6e0x320x82},
  {
0x820x320x6e0x1e0x780x280xa00x500x640x140x8c0x3c0x5a0x0a0x960x46},
  {
0x460x960x0a0x5a0x500xa00x3c0x8c0x280x780x1e0x6e0x320x820x140x64},
  {
0x640x140x820x320x6e0x1e0x780x280x8c0x3c0xa00x500x5a0x0a0x960x46},
};

 
//Spi Comm.pins with A7105/PPM
  #define PPM_pin 3//PPM in 
  #define SDI_pin 5 //SDIO-D5 
  #define SCLK_pin 4 //SCK-D4
  #define CS_pin 2//CS-D2
  //---------------------------------  
  #define  CS_on PORTD |= 0x04 //D2
  #define  CS_off PORTD &= 0xFB //D2
  //
  #define  SCK_on PORTD |= 0x10//D4
  #define  SCK_off PORTD &= 0xEF//D4
  #define  SDI_on PORTD |= 0x20 //D5
  #define  SDI_off PORTD &= 0xDF //D5
  //
  #define  SDI_1 (PIND & 0x20) == 0x20 //D5
  #define  SDI_0 (PIND & 0x20) == 0x00 //D5
  //
  #define RED_LED_pin 13//promini LED
  #define Red_LED_ON  PORTB |= _BV(5);//promini status LED on B5
  #define Red_LED_OFF  PORTB &= ~_BV(5);
  #define NOP() __asm__ __volatile__("nop")
  
//########## Variables #################
static uint32_t id;//tx id, don't confuse it with A7105 id
static uint8_t chanrow;
static 
uint8_t chancol;
static 
uint8_t chanoffset;
static 
uint8_t channel;
static 
byte counter=255;
static 
uint8_t aid[4];//for debug only
static uint8_t packet[21];
volatile uint16_t Servo_data[10] = {1500,1500,1000,1500,1500,1500,1500,1500};//8 channels

void setup() {
  
pinMode(RED_LED_pinOUTPUT); 
  
//RF module pins
  
pinMode(PPM_pinINPUT);//PPM input
  
pinMode(SDI_pinOUTPUT);//SDI   SDIO 
  
pinMode(SCLK_pinOUTPUT);//SCLK SCL 
  
pinMode(CS_pinOUTPUT);//CS output
  
CS_on;//start CS high
  
SDI_on;//start SDIO high
  
SCK_off;//start sck low
 //PPm setup 
attachInterrupt(PPM_pin 2read_ppmCHANGE);
TCCR1A 0;
TCCR1B 0;
TCCR1B |= (<< CS11); 
 
// 
  
  #if defined(DEBUG)
  
Serial.begin(SERIAL_BAUD_RATE);//for debugging
  #endif
  
uint8_t i;
  
uint8_t if_calibration1;
  
uint8_t vco_calibration0;
  
uint8_t vco_calibration1;
 
  
//for debug 
  
delay(10);//wait 10ms for A7105 wakeup
  
_spi_write_adress(0x00,0x00);
  
A7105_WriteID(0x5475c52A);//0x2Ac57554
 #if defined(DEBUG)
  
A7105_ReadID();//for debug only
  
Serial.print(aid[0],HEX);
  
Serial.print(aid[1],HEX);
  
Serial.print(aid[2],HEX);
  
Serial.print(aid[3],HEX);
 
#endif 
  
for (00x33i++){
        if(
A7105_regs[i] != 0xff)
            
_spi_write_adress(iA7105_regs[i]);

}
_spi_strobe(0xA0);//stand-by
_spi_write_adress(0x02,0x01);
while(
1){
if_calibration1=_spi_read_adress(0x02);
if(
if_calibration1==0){
break;
}
}
_spi_read_adress(0x22);
_spi_write_adress(0x24,0x13);
_spi_write_adress(0x25,0x09);
_spi_write_adress(0x28,0x1F);//set power to 1db maximum
_spi_strobe(0xA0);//
//id=0x30000006;//fixed TX ID(Thierry ID)
//id=0x92040020;
randomSeed((uint32_t)analogRead(A0) << 10 analogRead(A4));
id random(0xfefefefe) + ((uint32_t)random(0xfefefefe) << 16);
#if defined(DEBUG)
Serial.print(" ");
Serial.print(id,HEX);
Serial.print(" ");
#endif

bind_Flysky();
Red_LED_ON;
chanrow=id 16;
chanoffset=(id 0xff) / 16;
chancol=0;
}

//servodata timing range for flysky.
////-100% =~ 0x03e8//=1000us(min)
//+100% =~ 0x07ca//=1994us(max)
//Center = 0x5d9//=1497us(center)
//channel order AIL;ELE;THR;RUD;AUX1;AUX2;AUX3;AUX4

//############ MAIN LOOP ##############
void loop() {
unsigned long pause;
pause=micros();
_spi_strobe(0xE0);
Write_Packet(0x55);//
channel=tx_channels[chanrow][chancol]-chanoffset;
_spi_write_adress(0x0F,channel);
_spi_strobe(0xD0);
chancol = (chancol 1) % 16;
while(
micros()-pause<1460);
}


void read_ppm() {
  static 
unsigned int pulse;
  static 
unsigned long counterPPM;
  static 
byte chan;
  
counterPPM TCNT1;
  
TCNT1 0;
#if F_CPU == 16000000//thanks to goebisch for this one
  
const long scale 2;
#elif F_CPU == 8000000
  
const long scale 1;
#else
#error // 8 or 16MHz only !
#endif
  
if(counterPPM 510*scale) {  //must be a pulse if less than 510us
    
pulse counterPPM;
  }
  else if(
counterPPM 1910*scale) {  //sync pulses over 1910us
    
chan 0;
  }
  else{  
//servo values between 510us and 2420us will end up here
    
Servo_data[chan]= (counterPPM pulse)/scale;
    
chan++;
  }
}

//BIND_TX
void bind_Flysky() {
while(
counter){
_spi_strobe(0xA0);
_spi_strobe(0xE0);
_spi_write_adress(0x0F,0x01);
Write_Packet(0xaa);
_spi_strobe(0xD0);
delay(10);
if (
bitRead(counter,3)==1
Red_LED_ON;
if(
bitRead(counter,3)==0)
Red_LED_OFF;
counter--;
}
}



//-------------------------------
//-------------------------------
//A7105 SPI routines
//-------------------------------
//-------------------------------
void A7105_WriteID(uint32_t ida) {
 
CS_off;
_spi_write(0x06);
_spi_write((ida>>24)&0xff); 
_spi_write((ida>>16)&0xff);
_spi_write((ida>>8)&0xff);
_spi_write((ida>>0)&0xff);
 
CS_on;
}
void A7105_ReadID(){
uint8_t i;
 
CS_off;
_spi_write(0x46);
for(
i=0;i<4;i++){
aid[i]=_spi_read();
}
CS_on;
}
//----------------------
void Read_Packet() {
uint8_t i;
CS_off;
_spi_write(0x45);
for (
i=0;i<21;i++) {
packet[i]=_spi_read();
}
CS_on;
}
//---------------------------------

void Write_Packet(uint8_t init){//except adress(0x05)should sent to A7105 21 bytes totally)
uint8_t i;
CS_off;
_spi_write(0x05);//TX/RX FIFO adress
_spi_write(init);//0xaa or 0x55(depend on bind packet or data packet)
_spi_write((id >>  0) & 0xff);
_spi_write((id >>  8) & 0xff);
_spi_write((id >>  16) & 0xff);
_spi_write((id >>  24) & 0xff);

for(
i=0;i<8;i++){
cli();
packet[0+2*i]=lowByte(Servo_data[i]);//low byte of servo timing(1000-2000us)
packet[1+2*i]=highByte(Servo_data[i]);//high byte of servo timing(1000-2000us)
sei();
_spi_write(packet[0+2*i]);
_spi_write(packet[1+2*i]);
}

CS_on;
}

//-------------------------------------- 
void _spi_write(uint8_t command) {  
  
uint8_t n=8
  
SCK_off;//SCK starts low
  
SDI_off;
  while(
n--) {
    if(
command&0x80)
      
SDI_on;
    else 
     
SDI_off;
     
SCK_on;
   
NOP();
   
SCK_off;
    
command command << 1;
  }
  
SDI_on;
}  
void _spi_write_adress(uint8_t addressuint8_t data) {
   
CS_off;
  
_spi_write(address); 
   
NOP();
  
_spi_write(data);  
   
CS_on;

//-----------------------------------------
  
uint8_t _spi_read(void) {
  
uint8_t result;
  
uint8_t i;
  
result=0;
  
pinMode(SDI_pin,INPUT);//make SDIO pin input
  //SDI_on;
  
for(i=0;i<8;i++) {                    
  if(
SDI_1)  //if SDIO ==1 
      
result=(result<<1)|0x01;
    else
    
result=result<<1;
    
SCK_on;
    
NOP();
  
SCK_off;
  
NOP();
  }
  
pinMode(SDI_pin,OUTPUT);//make SDIO pin output again
  
return result;
  }   
//--------------------------------------------
uint8_t _spi_read_adress(uint8_t address) { 
  
uint8_t result;
  
CS_off;
  
address |=0x40;
  
_spi_write(address);
  
result _spi_read();  
  
CS_on;
  return(
result); 

//------------------------
void _spi_strobe(uint8_t address) {
 
CS_off;
_spi_write(address);
 
CS_on;
}
//------------------------
void A7105_reset(void) {
  
_spi_write_adress(0x00,0x00); 


Last edited by CrazyRussian; 2020.11.13 at 01:06 PM.
CrazyRussian is offline   Reply With Quote
 

Bookmarks

Tags
diy, fhs, tx module

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Preliminary testing and thoughts for using 2.4G module with EX1UR + 2.4G AWD Aurora 2.4GHz ASF System (Auto Selected Frequency) 9 2008.05.26 03:51 AM


All times are GMT -5. The time now is 10:00 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright 2011 Mini-ZRacer.com
Mini Inferno Sale - Up to $85 Instant Savings!
Micro-T Hop-Ups
RC18R, M18, Micro RS4, Mini-LST, TamTech-Gear, Minizilla, RC18T, RC18B, RC18MT
shop.tinyrc.com Products

more»
Tiny RC Community News
[03/22/17] MZR was on vacation, didn't... : All kidding aside, the host experienced a bit of a server meltdown last week and efforts to restore the site to a new server took longer than anticipated. The current server is temporary until - more»
[11/25/15] Did You Hear? Our Black... : Hey Racers,
We're getting started a bit early with our Black Friday sale this year.  Generally we're not supporters of retailers opening early on Thanksgiving, but in our case, we're - more»
[06/30/15] shop.tinyrc.com: Have You... : Hey All! Just a quick reminder to everyone that we post all of our shop.tinyrc.com Newletters here on the MZR Forum. If for some reason you miss them in your email inbox, you can always see the - more»
Mini-Z, Mini-Z Racer, MR-02, MA-010
M18, M18T, RC18T, Mini-LST, Mini-T, Micro RS4, XRay, 1/18, 18th scale
XMODS, XMOD, Micro Flight, ZipZaps, ZipZaps SE, Bit Char-G, MicroSizers, TTTT, Plantraco Desktop Rover, SuperSlicks, Digi Q
Mini Inferno, Mini Inferno ST, half EIGHT, 1/16, 16th scale
Epoch, Indoor Racer, 1/43, 43rd scale
E-Savage, eSavage, eZilla, e-Zilla, HPI
Robots, Bots, Bipeds, Wheeled, Manoi, Roomba, NXT, Lego, Hacking
Crawling, Crawlers, Micro, RC, Losi Mini-Rock Crawler, Duratrax Cliff Climber
Kyosho Minium, Caliber 120, Minium Forums
Mini-Z Hop-Ups, Mini-Z Parts, Mini Inferno Hop-Ups, Mini Inferno Parts, M18 Hop-Ups, M18 Parts