element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Smarter Life
  • Challenges & Projects
  • Design Challenges
  • Smarter Life
  • More
  • Cancel
Smarter Life
Blog PSoC 4 Tricopter (Smarter Life Challenge) part #4
  • Blog
  • Forum
  • Documents
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: yuritikhonov
  • Date Created: 17 Nov 2013 8:02 PM Date Created
  • Views 1003 views
  • Likes 1 like
  • Comments 4 comments
  • RoadTest
  • tricopter
  • psoc4
  • Multiwii
  • smarter_life_challenge
  • smarter_life
  • smart_tricopter
  • smart_control_and_diagnostics
  • arduino
  • quadcopter
Related
Recommended

PSoC 4 Tricopter (Smarter Life Challenge) part #4

yuritikhonov
yuritikhonov
17 Nov 2013

If you like my project vote for "A Smarter Tricopter - Yuri Tikhonov" image

 

Good day comrades!

As I promised, today we talk about the communication of PSoC 4 with standard MultiWii PC Software. Today the following modules are 90% ready:

  1. UpTime system.
  2. System of communication with the receiver (this week I'll fix some bugs).
  3. UART module for configuration and telemetry.

 

"PSoC schematics" looks like this:

image

 

The testing station has not changed and it has the view as follows:

image

 

Expectedly, I want to talk about the UART module.


Green: UART communication module works using interrupts. I use two interrupts in a single handler (UART_INTR_TX_EMPTY and UART_INTR_RX_NOT_EMPTY).

Now I only modify MultiWii to work correctly with the PSoC, later I'll make it's optimization.

 

CY_ISR(serialInterruptHandler) // interrupt
{
    if ( (UART_GetTxInterruptMode() & UART_INTR_TX_EMPTY) != 0 ) // RX interrupt
    {
        UART_ClearTxInterruptSource(UART_INTR_TX_EMPTY); // clear interrupt
        if( headTX != tailTX )
            UART_UartPutChar(bufTX[tailTX++]); // Transmit next byte in the ring
        if ( tailTX == headTX )                // Check if all data is transmitted
            serialIntOff;                      // Disable transmitter interrupt
    }

    if ( (UART_GetRxInterruptMode() & UART_INTR_RX_NOT_EMPTY) != 0 ) // RX interrupt
    {
        UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY);  // clear interrupt
        if ( UART_SpiUartGetRxBufferSize() < 1) return;
        uint8_t d = UART_UartGetChar();
        UART_SpiUartClearRxBuffer();
        uint8_t i = serialHeadRX[0] + 1;
        if (i != serialTailRX[0])
        {
            serialBufferRX[serialHeadRX[0]][0] = d;
            serialHeadRX[0] = i;
        }
    }
}

 

To better understand how the code works, here are some explanations:

  • as buffers Rx/Tx we use bufTX[] and serialBufferRX[][0] arrays;
  • tail and head of this buffers are stored, respectively, in tailTX, serialHeadRX[0], headTX and serialTailRX[0];
  • serialIntOff = UART_SetTxInterruptMode(0x00 - disable Tx interrupts);
  • serialIntOn = UART_SetTxInterruptMode(UART_INTR_TX_EMPTY) - turn on Tx interrupts (all data was transmitted and hardware Tx buffer is empty);
  • UART_INTR_RX_NOT_EMPTY - this interrupt occurs if the input UART read some data.

 

I would also speak about other functions adapted for the correct work with MultiWii GUI:

 

1. Adding two byte word in the Tx buffer (unsigned int16):

void serialize16(int16_t a)
{
  bufTX[headTX++]  = a;
  bufTX[headTX++]  = a>>8&0xff;
}

 

2. Adding one byte word in the Tx buffer (unsigned int8):

void serialize8(uint8_t a)
{
  bufTX[headTX++]  = a;
}

 

3. Turn on UART transmitting (realy - turn on Tx interrupts):

void UartSendData(void)
{                      // Data transmission acivated when the ring is not empty
  serialIntOn;          // Enable transmitter interrupt
}

 

 

4. Activate the data transmission on the UART. In my project I use only one module UART, and only one fixed speed 115200 baud, so variables port and baud temporarily left only for compatibility with MultiWii:

void SerialOpen(uint8_t port, uint32_t baud)
{
  UART_Start();
  uartIsr_StartEx(serialInterruptHandler);
}

 

5. Turn off UART transmitting (variable port is only for  compatibility with MultiWii):

void SerialEnd(uint8_t port)
{
  UART_Stop();
}

 

6. Reading data via UART. Realy - buffer reading (variable port is only for compatibility with MultiWii):

uint8_t SerialRead(uint8_t port)
{
    uint8_t c = serialBufferRX[serialTailRX[port]][port];
    if ((serialHeadRX[port] != serialTailRX[port])) serialTailRX[port] = serialTailRX[port] + 1;
    return c;
}

 

7. Checking Rx data availability (variable port is only for compatibility with MultiWii):

uint8_t SerialAvailable(uint8_t port)
{
  return serialHeadRX[port] - serialTailRX[port];
}

 

8. Transfer one byte via UART (variable port is only for compatibility with MultiWii):

void SerialWrite(uint8_t port,uint8_t c)
{
  serialize8(c);
  UartSendData(); // Serial TX is driven via a buffer and a background intterupt
}

 

The function of ensuring communication with MultiWii GUI has a name serialCom(), It is currently undergoing a "permanent modifications," because yet I have not IMU, EEPROM, and some other functions.

 

So, the moment of truth, start of MultiWii GUI:

image

 

As you can see, telemetry data is successfully transferred! Reaction to the sticks of radio equipment, fast and accurate, in general I am happy!

Next week I plan to do another small but necessary system: EEPROM. Because without it, store settings and calibration unit is not yet possible.

See you next week!

 

                                                                                                                                              

#linkdescription
1PSoC 4 Tricopter Part #1Introduction
2PSoC 4 Tricopter Part #2Purchase of components from Farnell and HobbyKing
3PSoC 4 Tricopter Part #3PSoC firmware: upTime & Rx
4PSoC 4 Tricopter Part #4PSoC firmware: UART & MultiWii GUI
5PSoC 4 Tricopter Part #5PSoC firmware: EEPROM emulation
6PSoC 4 Tricopter Part #6PSoC firmware: Servo & ESC control
7PSoC 4 Tricopter Part #7PSoC firmware: IMU, LED's & PID
8PSoC 4 Tricopter Part #8Hardware: PCB
9PSoC 4 Tricopter Part #9Hardware: tricopter's frame
10PSoC 4 Tricopter Part #10Hardware: YAW mechanics & motors
11PSoC 4 Tricopter Part #11Hardware: ESC's, wires & misc
12PSoC 4 Tricopter Part #12Final: The first fly

 

If you like my project vote for "A Smarter Tricopter - Yuri Tikhonov" image

  • Sign in to reply

Top Comments

  • yuritikhonov
    yuritikhonov over 11 years ago in reply to cy.gul +1
    Hello Gagan! MultiWii is my favourite RC platform! 1. After the completion of the RoadTest I want to make this project open source (GNU) 2. After completion of the MultiWii "fork", I want to create my…
  • yuritikhonov
    yuritikhonov over 11 years ago in reply to cy.gul

    Hello Gagan! MultiWii is my favourite RC platform!

    1. After the completion of the RoadTest I want to make this project open source (GNU)

    2. After completion of the MultiWii "fork", I want to create my fully own flight control system, with elements of MultiWii source code.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • cy.gul
    cy.gul over 11 years ago

    great progress! I assume the MultiWii SW is a commonly used one in the copter RC world?

    It is great that you're doing this work that many will be able to reuse.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • yuritikhonov
    yuritikhonov over 11 years ago in reply to DAB

    Hello DAB!

    As you know any aircraft consists of many system and I think "divide and conquer" is a best approach.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 11 years ago

    Hi Yuri,

     

    Good update and explanation of your code.

    I also like the way you are attacking the problem step by step.

     

    DAB


    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube