Shop OBEX P1 Docs P2 Docs Learn Events
FlexC problems — Parallax Forums

FlexC problems

The program below compiles, but it is not starting the new COG. The FlexC docs and examples are very skimpy on showing how to start a new COG, at least for beginners.

I do not know why this is not working as expected.

Ray
/* 
cr2rpi.c

*/
#include <simpletools.h>

struct __using("efds.spin") fds;
struct __using("efds.spin") rpi;
static long stack[32];



void start_rpi();

int main()
{
  fds.start(0, 1, 0, 115200);
  pause(150);
  int startit = __builtin_cogstart(start_rpi(),&stack[32]);  
  
  print("Here I am!");
  
  while(1)
  {
  	pause(500);  
  }
}

void start_rpi()
{
  rpi.start(2, 3, 0, 115200);
  char inBuff[40];
  
 	while(1)
 	{
 	  rpi.rxstr(inBuff);
 	  if(!strcmp(inBuff,"gofore"))
 	  {
 	    rpi.str("Something!\n");
 	  }
 	  pause(500);
 	} 
}[i][/i]

Comments

  • Use "&stack[0]", not "&stack[32]".

    Here's an example that flashes two pins in different cogs:
    #include <simpletools.h>
    #define PIN1 26
    #define PIN2 27
    
    static long stack[32];
    
    
    
    void start_rpi();
    
    int main()
    {
        int startit = __builtin_cogstart(start_rpi(PIN1, 270),&stack[0]);
        start_rpi(PIN2, 312);
    }
    
    void start_rpi(int pin, int delayms)
    {
      unsigned long mask;
      char inBuff[40];
    
      mask = 1<<pin;
      DIRA |= mask;
      
      while(1)
      {
          OUTA ^= mask;
          pause(delayms);
      } 
    }
    
  • RsadeikaRsadeika Posts: 3,837
    edited 2020-08-08 13:47
    Below is a little test program, to try out the usage of starting a COG, and some other things.

    I am using efds.spin, which is ExtendedFullDuplexSerial.spin, because it has some commands like str(), and rxStr(). Now I noticed that when I have:
    rpi.str("\n")
    it is not working as expected, it only does a LF, and not a CRLF. Not sure if that is a problem with FlexC or with edfs.spin. When I tried using rpi.str("\r"), I get nothing.

    I am also having a problem with using rxStr(), it seems like it is not reading the input, at all, or maybe incorrectly, not sure if this is problem with FlexC or with efds.spin.

    Is there a functional FullDuplexSerial object that can handle reading incoming strings?

    Another inconsistency, when I placed efds.spin, in the inc folder, and then tried:
    struct __using("spin/edfs.spin") fds;
    in the program, I kept getting an error that it could not find edfs.spin. Not sure why that is occurring.

    Ray
    /* test.c*/
    #include <simpletools.h>
    
    //struct __using("spin/FullDuplexSerial.spin") fds;
    struct __using("efds.spin") fds;
    struct __using("efds.spin") rpi;
    static long stack[32];
    
    int main()
    {
    fds.start(0, 1, 0, 115200);
    int startrpi = __builtin_cogstart(start_rpi(),&stack[0]);
      
      while(1)
      {
        //fds.tx('A');
        pause(500);
      }
    }
    
    void start_rpi()
    {
    rpi.start(2, 3, 0, 115200);
    char inBuff[40];
     
       while(1)
      {
        //fds.tx('A');
        //fds.tx(13);
        //fds.tx(10);
        //rpi.tx('A');
        //rpi.str("\r");  // The \r is not working.
        //rpi.str("\n");  // Works partialy, only does a 10, and 13 10.
        rpi.rxstr(@inBuff);
        if(@inBuff == "yes")
        {
    			rpi.str("Where am I!\n");
    		}
    		else
    		{
    		  rpi.rxstr("Invalid Command!");
    		}
        
        pause(2000);
      } 
    }
    
Sign In or Register to comment.