Shop Learn P1 Docs P2 Docs Events
c++ prop 2 — Parallax Forums

c++ prop 2

Is there an instruction like this in p2 c in flex prop or other: fdserial_rxChar

How to do it in fullduplexserial for p2?
Thanks

Comments

  • RossHRossH Posts: 4,972

    Catalina wraps such serial functions in a library (in the case of the 2 port serial driver it is libserial2). If you look in the include file "catalina_serial2.h" you will see functions like:

    extern int s2_rx(unsigned port);
    extern int s2_tx(unsigned port, char txbyte);
    
    

    I'm sure the other C compilers would be similar. Here is a complete C test program:

    #include <catalina_serial2.h>
    #include <propeller2.h>
    
    /*
     * Simple test program for the 2 Port serial plugin. This program only tests 
     * one port at a time (as defined by PORT, below).
     *
     * NOTE:
     *
     * By default, the 2 port serial plugin enables port 0 on propeller pins 
     * 63 & 62 and port 1 on pins 52 & 50. This means you cannot use the TTY HMI 
     * option or the debugger (which by default use these same pins). If TTY is 
     * the default HMI option for your Propeller platform, you must disable it 
     * when compiling this program by defining the target symbol NO_HMI.
     * For example:
     *
     *   catalina test_serial.c -p2 -lci -lserial2 -C NO_HMI
     *
     */
    
    #define PORT 0
    
    void main() {
    
       int ch;
    
       char str[] = 
          "Now is the time for all good men to come to the aid of the party. "
          "Twinkle, twinkle little star. How I wonder what you are. "
          "The quick brown fox jumps over the lazy dog. ";
    
       // in the main function, we will use the 2 port serial functions to 
       // interact with one of the serial ports ...
    
       s2_strln(PORT, "Hello, World (from the 2 Port Serial plugin)!");
       s2_txflush(PORT);
       s2_strln(PORT, "Press a key to begin...\n");
       s2_rx(PORT);
    
       while (1) {
          // print a test string once per second, unless a character is received
          s2_str(PORT, str);
          s2_txflush(PORT);
          ch = s2_rxtime(PORT, 1000);
          if (ch != -1) {
             // print out the received character in various formats
             s2_newline(PORT);
             s2_padchar(PORT, 79, '_');
             s2_newline(PORT);
             s2_str(PORT, "Received:");
             if (isprint(ch)) {
                s2_str(PORT, " \'");
                s2_tx(PORT, ch);
                s2_str(PORT, "\',");
             }
             s2_str(PORT, " ");
             s2_dec(PORT, ch);
             s2_str(PORT, ", ");
             s2_ihex(PORT, ch, 2);
             s2_str(PORT, ", ");
             s2_ibin(PORT, ch, 8);
             s2_newline(PORT);
             s2_padchar(PORT, 79, '_');
             s2_newline(PORT);
             s2_rxflush(PORT);
          }
       }
    }
    
    
  • I have a serial library that works with flex prop that can do just that.

    P2 Custom Libraries for Flex Prop

    Mike

  • AribaAriba Posts: 2,619
    edited 2022-12-03 15:31

    In FlexC you can include Spin objects, and use them:

    struct __using("spin/SmartSerial.spin") fds;
    
    enum{ _clkfreq = 160_000_000};
    
    void main()
    {
        int c;
        fds.start(63,62,0,230400);
        for(;;) {
            c = fds.rx();   //serial rx
            fds.tx(c);      //serial tx
        }
    }
    
    

    Or if you use the standard serial port to the PC, do it with the standard-IO lib:

    #include <stdio.h>
    enum{ _clkfreq = 160_000_000};
    
    void main()
    {
        int c;
        for(;;) {
            c = getchar();   //serial rx
            putchar(c);      //serial tx
        }
    }
    

    Andy

  • @Ariba
    @iseries
    @RossH

    Thanks for the information. I will look at it. Been busy.
    Martin

  • @iseries said:
    I have a serial library that works with flex prop that can do just that.

    P2 Custom Libraries for Flex Prop

    Mike

    I found your libraries on github. My assumption is to extract to include file for flexprop. Second where, since you have a lot of libraries is the rx_char equavalent located. I did not see a quick list of the types of libraries.
    Thanks in advance.
    Martin

  • iseriesiseries Posts: 1,311

    @pilot0315 ,

    So you clicked on the green button on github and picked the last option which was to download a zip file. Then extract that zip file to where you want it and it will create a folder called P2Custom-main. Then you go into flexprop and select file and Library directories and add that path.
    In your program you just add an #include "serial.h" and your good to go.
    There are sample programs in P2Custom in libsamples, just look for the libserial folder.

    #include <stdio.h>
    #include <propeller.h>
    #include "serial.h"
    
    #define RXPIN 37
    #define TXPIN 36
    
    char Data[256];
    FILE *s;
    
    int main(int argc, char** argv)
    {
        int i;
    
        s = serial_open(RXPIN, TXPIN, 400000);
    
    
        Data[0] = serial_rxChar(s);
        Data[1] = serial_rxChar(s);
        Data[2] = serial_rxChar(s);
        Data[3] = serial_rxChar(s);
    
        printf("Serial: %x\n", Data[0]);
        printf("Serial2: %x\n", Data[1]);
    
        printf("done\n");
    
        while (1)
        {
            _waitms(1000);
        }
    }
    

    Not a very good example.

    I use Visual Studio Code because it shows me all the options of the function I want to use.
    Visual Studio

    If you don't want all that code you only need to copy the serial.h and libserial folder. Flexprop will only use functions that are used by your program.

    Mike

  • Thanks.
    I am trying desperately to get VSC to work had to delete flexprop completely something was wrong.

  • @iseries

    Thanks. Got the file in and opened. Will be working on it.
    Still trying to intergrate VSC. The quick bytes have broken links and am trying to follow what I can from Marco, not easy.
    Martin

  • iseriesiseries Posts: 1,311

    Since I only code in C and don't use the setup from Marco.

    I use this task to compile my programs:

            {
                "type": "cppbuild",
                "label": "Build FlexSpin Propeller P2 Program",
                "command": "d:/flexprop/bin/flexspin.exe",
                "args": [
                    "-2",
                    "-O1",
                    "-I",
                    "D:/flexprop/include",
                    "-I",
                    "D:/Custom",
                    "-o",
                    "${fileDirname}/build/${fileBasenameNoExtension}.binary",
                    "${file}"
                ],
                "options": {
                    "cwd": "${workspaceFolder}"
                },
                "problemMatcher": [
                    "$msCompile"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": false
                },
                "detail": "compiler: flexspin.exe"
            }
    

    I like to compile my programs in a build folder so that it's not adding files to the source directory. Works great with flexprop.
    I use this task to run the program using com5:

            {
                "label": "Run Propeller Program --> COM5",
                "type": "shell",
                "command": "d:/flexprop/bin/p2loader.exe",
                "args": [
                    "com5",
                    "${fileDirname}/build/${fileBasenameNoExtension}.binary"
                ],
                "problemMatcher": []
            }
    

    But I like to use WiFi so I have a custom WiFi loader:

            {
                "label": "Run Propeller Program --> WiFi",
                "type": "shell",
                "command": "d:/flexprop/bin/p2loader.exe",
                "args": [
                    "wx-de073e",
                    "${fileDirname}/build/${fileBasenameNoExtension}.binary"
                ],
                "problemMatcher": []
            }
    

    I setup this configuration for working with the source code in C:

            {
                "name": "FlexProp",
                "includePath": [
                    "d:/flexprop/include/**",
                    "d:/Custom/"
                ],
                "compilerPath": "",
                "cStandard": "c99",
                "intelliSenseMode": "clang-arm64",
                "compilerArgs": [
                ],
                "cppStandard": "c++98"
            }
    

    Mike

  • @pilot0315 said:
    The quick bytes have broken links and am trying to follow what I can from Marco, not easy.
    Martin

    Hi Martin, when you have a moment could you share the page (or pages) with the bad links please?
    I'll get them fixed up pronto!

  • @VonSzarvas

    https://www.parallax.com/visual-studio/

    Looks like missing videos to do the process. Tried Youtube, no luck. I assume the process is straight forward but I can't follow the steps without the missing? videos.
    Thanks.
    If I am missing something please let me know.
    Thanks in advance.
    Martin

  • @iseries said:
    Since I only code in C and don't use the setup from Marco.

    I use this task to compile my programs:

            {
                "type": "cppbuild",
                "label": "Build FlexSpin Propeller P2 Program",
                "command": "d:/flexprop/bin/flexspin.exe",
                "args": [
                    "-2",
                    "-O1",
                    "-I",
                    "D:/flexprop/include",
                    "-I",
                    "D:/Custom",
                    "-o",
                    "${fileDirname}/build/${fileBasenameNoExtension}.binary",
                    "${file}"
                ],
                "options": {
                    "cwd": "${workspaceFolder}"
                },
                "problemMatcher": [
                    "$msCompile"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": false
                },
                "detail": "compiler: flexspin.exe"
            }
    

    I like to compile my programs in a build folder so that it's not adding files to the source directory. Works great with flexprop.
    I use this task to run the program using com5:

            {
                "label": "Run Propeller Program --> COM5",
                "type": "shell",
                "command": "d:/flexprop/bin/p2loader.exe",
                "args": [
                    "com5",
                    "${fileDirname}/build/${fileBasenameNoExtension}.binary"
                ],
                "problemMatcher": []
            }
    

    But I like to use WiFi so I have a custom WiFi loader:

            {
                "label": "Run Propeller Program --> WiFi",
                "type": "shell",
                "command": "d:/flexprop/bin/p2loader.exe",
                "args": [
                    "wx-de073e",
                    "${fileDirname}/build/${fileBasenameNoExtension}.binary"
                ],
                "problemMatcher": []
            }
    

    I setup this configuration for working with the source code in C:

            {
                "name": "FlexProp",
                "includePath": [
                    "d:/flexprop/include/**",
                    "d:/Custom/"
                ],
                "compilerPath": "",
                "cStandard": "c99",
                "intelliSenseMode": "clang-arm64",
                "compilerArgs": [
                ],
                "cppStandard": "c++98"
            }
    

    Mike

    Could you take one of the above and add some comments so that I can follow.
    Thanks
    Martin

  • VonSzarvasVonSzarvas Posts: 2,966
    edited 2023-01-12 10:36

    @pilot0315 said:
    @VonSzarvas

    https://www.parallax.com/visual-studio/

    Looks like missing videos to do the process. Tried Youtube, no luck. I assume the process is straight forward but I can't follow the steps without the missing? videos.
    Thanks.
    If I am missing something please let me know.
    Thanks in advance.
    Martin

    Something curious afoot! I see all the videos at that link, starting at Step 3.
    Could your browser, ad-blocker, IP filter (etc..) or firewall be blocking the links/feeds somehow ?

    For testing, here's a direct link to one of the videos from that page:

  • JonnyMacJonnyMac Posts: 8,407

    Could you take one of the above and add some comments so that I can follow.

    -- https://code.visualstudio.com/docs/editor/tasks

  • @VonSzarvas said:

    @pilot0315 said:
    @VonSzarvas

    https://www.parallax.com/visual-studio/

    Looks like missing videos to do the process. Tried Youtube, no luck. I assume the process is straight forward but I can't follow the steps without the missing? videos.
    Thanks.
    If I am missing something please let me know.
    Thanks in advance.
    Martin

    Something curious afoot! I see all the videos at that link, starting at Step 3.
    Could your browser or firewall be blocking the links/feeds somehow ?

    For testing, here's a direct link to one of the videos from that page:

    I have used edge, internet exlorer, firefox and water fox and get the same issue.
    One of them should prove good.
    No avail.

  • @pilot0315 said:

    @VonSzarvas said:

    @pilot0315 said:
    @VonSzarvas

    https://www.parallax.com/visual-studio/

    Looks like missing videos to do the process. Tried Youtube, no luck. I assume the process is straight forward but I can't follow the steps without the missing? videos.
    Thanks.
    If I am missing something please let me know.
    Thanks in advance.
    Martin

    Something curious afoot! I see all the videos at that link, starting at Step 3.
    Could your browser or firewall be blocking the links/feeds somehow ?

    For testing, here's a direct link to one of the videos from that page:

    I have used edge, internet exlorer, firefox and water fox and get the same issue.
    One of them should prove good.
    No avail.

    I will turn off all firewalls and stuff and try again.

    -- https://code.visualstudio.com/docs/editor/tasks
    too complicated and no help. Not understanding what that link does.
    I am looking millimeter by millimeter not kilometer by hectar.

Sign In or Register to comment.