Graupner/SJ SUMD serial receiver addition

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Graupner/SJ SUMD serial receiver addition

Post by Plüschi »

config.h

Code: Select all

    /*******************************    HOTT RECIVER    ************************************/
      /* Graupner Hott  HD */
      //#define SUMD PITCH,YAW,THROTTLE,ROLL,AUX1,AUX2,AUX3,AUX4
      //#define RX_SERIAL_PORT 1


rx.cpp
configureReceiver()

Code: Select all

  // Init Graupner/SJ RX
  #if defined (SUMD)
    SerialOpen(RX_SERIAL_PORT,115200);
  #endif
  // Init SBUS RX
  #if defined(SBUS)
    SerialOpen(RX_SERIAL_PORT,100000);
    switch (RX_SERIAL_PORT) { //parity
      case 0: UCSR0C |= (1<<UPM01)|(1<<USBS0); break;
      case 1: UCSR1C |= (1<<UPM11)|(1<<USBS1); break;
      case 2: UCSR2C |= (1<<UPM21)|(1<<USBS2); break;
      case 3: UCSR3C |= (1<<UPM31)|(1<<USBS3); break;
    } 
  #endif

Note i did omit the mega #ifdef for sbus parity, since bitnames for 328 and 32u4 are the same as for mega. This "should" work ...

the driver:

Code: Select all

/**************************************************************************************/
/***************                    SUMD                           ********************/
/**************************************************************************************/

#if defined(SUMD)
#define SUMD_SYNCBYTE 0xA8
#define SUMD_MAXCHAN 8
#define SUMD_BUFFSIZE SUMD_MAXCHAN*2 + 5 // 6 channels + 5 -> 17 bytes for 6 channels
static uint8_t sumdIndex=0;
static uint8_t sumdSize=0;
static uint8_t sumd[SUMD_BUFFSIZE]={0};

void readSumD(void) {
  while (SerialAvailable(RX_SERIAL_PORT)) {
    int val = SerialRead(RX_SERIAL_PORT);
    if(sumdIndex == 0 && val != SUMD_SYNCBYTE) continue;
    if(sumdIndex == 2) sumdSize = val;
    if(sumdIndex < SUMD_BUFFSIZE) sumd[sumdIndex] = val;
    sumdIndex++;
   
    if(sumdIndex == sumdSize*2+5)
    {
      sumdIndex = 0;
      spekFrameFlags = 0x00;
      debug[1] = sumd[1];
      if (sumdSize > SUMD_MAXCHAN) sumdSize = SUMD_MAXCHAN;
      for (uint8_t b = 0; b < sumdSize; b++)
        rcValue[b] = ((sumd[2*b+3]<<8) | sumd[2*b+4])>>3;
      spekFrameDone = 0x01; // havent checked crc at all

      #if defined(FAILSAFE)
      if (sumd[1] == 0x01)
        {if(failsafeCnt > 20) failsafeCnt -= 20; else failsafeCnt = 0;}   // clear FailSafe counter
      #endif
     }
  }
}
#endif


readrawrc()

Code: Select all

  #if defined(SPEKTRUM) || defined(SBUS) || defined(SUMD)


computeRC()

Code: Select all

      #if defined(SPEKTRUM) || defined(SBUS) || defined(SUMD) // no averaging for Spektrum & SBUS & SUMD signal


multiwii.cpp

Code: Select all

#if defined(SPEKTRUM) || defined(SBUS) || defined(SUMD)
  volatile uint8_t  spekFrameFlags;
  volatile uint32_t spekTimeLast;
  uint8_t  spekFrameDone;
#endif


Code: Select all

  #if defined(SPEKTRUM)
    if (spekFrameFlags == 0x01) readSpektrum();
  #endif
  #if defined(SBUS)
    if (spekFrameFlags == 0x01) readSBus();
  #endif
  #if defined(SUMD)
    if (spekFrameFlags == 0x01) readSumD();
  #endif

  #if defined(SPEKTRUM) || defined(SBUS) || defined(SUMD)
  if ((spekFrameDone == 0x01) || ((int16_t)(currentTime-rcTime) >0 )) {


serial.cpp
store_uart_in_buf()

Code: Select all

#if defined(SPEKTRUM) || defined(SBUS) || defined(SUMD)


I hope i did not forget anything.

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Plüschi »

Bumping that up so if alex goes online this weekend he might consider it.

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Graupner/SJ SUMD serial receiver addition

Post by Alexinparis »

ok, done.
there was some definition missing in deh.h, please check if it works.

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Plüschi »

Ty Alex.

Not yet working.
You missed the last change, serial.cpp, store_uart_in_buf()

Code: Select all

#if defined(SPEKTRUM) || defined(SBUS) || defined(SUMD)


And i totally forgot one thing ...
Protocol.cpp, serialcom() :

Code: Select all

#if (defined(SPEKTRUM) || defined(SBUS) || defined(SUMD)) && (UART_NUMBER > 1)

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Graupner/SJ SUMD serial receiver addition

Post by Alexinparis »

>You missed the last change, serial.cpp, store_uart_in_buf()
for me it was already done

>#if (defined(SPEKTRUM) || defined(SBUS) || defined(SUMD)) && (UART_NUMBER > 1)
ok, corrected.

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Plüschi »

Ty, works now!

I did forget to remove a debug output.

rx.cpp, readSumD(),

Code: Select all

debug[1] = sumd[1];


Cosmetical: The indent got corrupted somehow.

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Plüschi »

I think we should combine spek, sbus and sumd in a SERIALRC group. SERIALRC would be set in def.h :

Code: Select all

#if defined(SPEKTRUM) || defined(SBUS) || defined(SUMD)
   #define SERAILRC
#endif


then all the 5 files with this

Code: Select all

#if defined(SPEKTRUM) || defined(SBUS) || defined(SUMD)

could be modified to this

Code: Select all

#if defined(SERIALRC)


and the addition of new serial receivers would me much much simpler.

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Graupner/SJ SUMD serial receiver addition

Post by Alexinparis »

yes, I also think we can increase the simplicity of the code regarding the scaterred RXs

Cat 1
Posts: 9
Joined: Sat Sep 20, 2014 4:24 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Cat 1 »

I have incorporated Plüschi's changes and it working very well on a Mega board on one of my quads.. Very good and clean RC signal using a "cheap" gr-12L receiver.. will interface well with the Graupner telemetry setup i am planning on a new Quad...

I am however having issues making it work with a FLIP 1.5 (328) board... I understand the challenges of this because of the inavalibility of the GUI... I am using a I2C OLED for setup but I can't seem to get a clean data stream from the receiver. There is data coming through but it is corrupt causing the RC values to jump to both extremes...

I struggle with code and understand the scripting just enough to be dangerous :)

Can you advise if this code should work with the smaller processor when the SUMD if fed into Serial 0 ??? I will keep trying as running the small (cheap) micro receivers on the "flip" style mini boards using SumD would be great...

thanks

Chris

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Plüschi »

The 328 boards have only 1 serial port. This serial is used for GUI communication, not for serial receivers.

You can try to disable the GUI since you use oled for setup.
Protocol.cpp, serialcom() :

Code: Select all

// instead of
#if (defined(SPEKTRUM) || defined(SBUS) || defined(SUMD)) && (UART_NUMBER > 1)
// do this
#if (defined(SPEKTRUM) || defined(SBUS) || defined(SUMD))


Only fly if it's 100% glitch free !

Cat 1
Posts: 9
Joined: Sat Sep 20, 2014 4:24 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Cat 1 »

Thanks Plüschi. It's working now. Just have to familiarize myself with the oled setup routines and some more bench testing before flying but data looks good now. Thanks for your help. This is an awesome option for graupner users.

Cat 1
Posts: 9
Joined: Sat Sep 20, 2014 4:24 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Cat 1 »

Have found an issue with the SumD addition coding... When an I2C OLED is connected the Data stream from the receiver is corrupted and causes glitching.. I am attempting to use a serial SUMD receiver on a "328" board and require the OLED for setup.. I further tested it on a MEGA board and found the same effect.. When the OLED is activated and Plugged in the receiver stream is corrupted.. Also on both the 328 and MEGA boards the "OLED config" does not work.. When the setup screen is entered the board freezes and setup cannot be done and a power down reset is required. Tested the same setup on both boards with PPM receivers and OLED config works fine.

will post a video to show the glitching
https://www.youtube.com/watch?v=W9F9BY9B1h4

Have flown a mega board with the code (no OLED) and its very smooth with no issues.. The 328 board also runs smooth on the bench without the OLED.. when OLED is connected both show glitching...

Chris

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Plüschi »

I am not familiar with oled.

SUMD (and others) expect a 100% exclusive serial line. If someone gets a byte from serial sumd will glitch.
Seems somewhere in oled code someone steals a byte. Find it, kill it :)

Cat 1
Posts: 9
Joined: Sat Sep 20, 2014 4:24 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Cat 1 »

Will keep working this when I get a chance. Have working solutions on both boards and my coding and debugging skills are "ancient". Learned to program in "basic" on a Commodore VIC 20... with the awesome 5KB expander module ... my, how far we have come.

The part that troubles me is that it is happening with the Mega too with its dedicated serial line.. I suspect OLED has a bug when it collects info from this stream.. might try to see if it happens with a spectrum serial rec also.

I suspect the freezing in OLED config is a different issue. It seems like the data from the serial port is shut off when OLED config is turned on and you get stuck there with no input ability.

Chris

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Plüschi »

Seems a pretty bad one you caught there.

The reason might be LCD code calls readRawRC() outside of main loop. This isnt working any more.

I propose this thing, lcd.cpp, configurationLoop() :

Code: Select all

  while (LCD == 1) {
    if (refreshLCD) {
      ConfigRefresh(p);
      refreshLCD = 0;
    }
    #if defined(SPEKTRUM)
      if (spekFrameFlags == 0x01) readSpektrum();
    #endif
    #if defined(SBUS)
      if (spekFrameFlags == 0x01) readSBus();
    #endif
    #if defined(SUMD)
      if (spekFrameFlags == 0x01) readSumD();
    #endif
    #if defined(LCD_TEXTSTAR) || defined(LCD_VT100) || defined(LCD_TTY) // textstar, vt100 and tty can send keys
      key = ( SerialAvailable(LCD_SERIAL_PORT) ? SerialRead(LCD_SERIAL_PORT) : 0 );
    #endif
    #ifdef LCD_CONF_DEBUG


Can you test that? Stupidly it did power my oled the wrong way around and now it smells funny.

Another thing, the indent around SUMD is fucked up since REV R1694. All the files concerning SUMD. I dont like that. MY OCD runs amok.

Cat 1
Posts: 9
Joined: Sat Sep 20, 2014 4:24 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Cat 1 »

We almost have it now Plüschi.. I can enter and navigate around in config but have another issue now.. the inputs from the sticks seem to be glitchy on occasion causing the menu to scroll or values to change randomly.. sometimes its ok.. best method seems to be a quick stab at the stick and wait.. a normal stick movement will cause position or values to change by 3 to 5 steps.. it occasional "self exits" too which makes setting things a real chore...

might be caused by the same glitch i am seeing on the rc values on the telemetry screen but these look very quiet now as i have changed the receivers "period" setting from 20ms to 10ms.. seems to drastically improve the signal quality but if it is still "popping" it could cause this odd behaviour in the config..

think if i could filter this serial "read" in the config and only fly without the oled disconnected my issue would be solved...

trying to post a video showing the issue...

Cat 1
Posts: 9
Joined: Sat Sep 20, 2014 4:24 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Cat 1 »

https://vimeo.com/106781279

video will be here in 40 min.. "converting"!!!!! hope the oled is readable on this copy...tried on youtube but the quality was crappy and you couldn't see the issue clearly..

Chris

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Plüschi »

The receiver needs:

Code: Select all

if (spekFrameFlags == 0x01) readSumD();


Called at least every 7ms. If this is not called enough a buffer overflow and glitch may happen.
Whenever new data is avaliable the flag spekFrameDone will be set and readrawrc() can be safely done.

Code: Select all

  if ((spekFrameDone == 0x01) 
  {
    spekFrameDone = 0x00;
    for all channels ... readRawRC(chan); ...
    ... process rcdata here ...


I have no idea of the LCD loop timing. Is there a delay or something?

Cat 1
Posts: 9
Joined: Sat Sep 20, 2014 4:24 am

working..

Post by Cat 1 »

OK.... Have successfully flown the Graupner SumD serial addition on a "flip 1.5" 328 single serial board... it works well but was a bear to set up... When the I2C OLED (which is required because of the single serial port) is plugged in it causes some instability in the serial radio data and can be troublesome trying to get the board set up as the radio inputs are not communicated well and clean.. I solved this by lowering the "#define SUMD_MAXCHAN 8" to "#define SUMD_MAXCHAN 5" in RX.cpp.. only use 5 channels anyway because of the limited options on this board.. it also helped to set the receiver "period" to 10ms in the graupner RX setup on the radio...

somebody smarter than me can probably figure out a way to make this work better but I am happy flying my quad with a cheap little board and a cheap tiny RX hooked together with one wire...

Thanks Again Plüschi and all others involved with this addition... you ROCK!!!! :)

TheBum
Posts: 35
Joined: Wed Dec 03, 2014 9:53 pm

Re: Graupner/SJ SUMD serial receiver addition

Post by TheBum »

Pre-2.4 r1729 does appear to have fixed the serial issue. As long as I left the USB cable disconnected for several seconds, the OLED and the channel telemetry looked good. The display would come up with what looked like a star field if USB was connected.

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Graupner/SJ SUMD serial receiver addition

Post by Plüschi »

There is a 60ms delay in the oled routines which makes the serial receivers (speksat,sbus,sumd) instable / not reliable. I have posted a better way to do stuff in lcd.cpp in this forum, but i think it was not added because someone did not understand the problem.

viewtopic.php?f=8&t=5662

Post Reply