Shop OBEX P1 Docs P2 Docs Learn Events
serial TX issue — Parallax Forums

serial TX issue

Hello everyone,

I have a JDY-40 2.4ghz module. i am having zero luck sending commands to it using the flip but i am receiving "START" from it when i first connect power.
I can communicate with the module perfectly using the arduino terminal, 9600 baud with both NL and CR after sending AT+BAUD command
but i just cant seem to figure out what im missing with the propeller? Thanks in advance for any help.


#include "simpletext.h"
#include "simpletools.h"                      // Include simple tools
#include "fdserial.h" 



fdserial *program;

int m = 0;

//-----------------------------------------------------------------


int main()
{

pause(100); 
  
                         // RX-TX  
   program = fdserial_open(0, 2, 0, 9600);     // p0-p1  transmit to receiver
     pause(100); 

print("RUNNING\n");  


pause(100); 



//dprint(program, 'AT+BAUD');    //change text

//fdserial_txChar(program, "AT+BAUD\r\n"); //Command byte

//dprint(program, "%s%d%d", "AT+BAUD", 13, 10);    //change text 
//dprint(program, "%s%c%c", "AT+BAUD", 0x0D, 0x0A);    //change text 
//dprint(program, "AT+BAUD%c%c", 13, 10);   //send specific text
//dprint(program, "AT+BAUD%c%c", 0x0D, 0x0A);   //send specific text



fdserial_txChar(program, "AT+BAUD"); //Command byte
fdserial_txChar(program, 0x0D); //Command byte
fdserial_txChar(program, 0x0A); //Command byte


while(1)
{
  m = fdserial_rxChar(program);      
  print("m= %c,  %d,\n",m, m);              
  pause(100);   
}  



int i=0;
 
for( i=0; i<=17; i++ )
{ 
  m = fdserial_rxChar(program);      
  print("m= %c,  %d,\n",m, m);              
  pause(100);      
}  

print("DONE!\n");     
}


//---------------------------------------------------------------

Comments

  • I'd suggest adding a carriage return after the newline.

    print("RUNNING\n\r");
  • I don't remember which is supposed to come first. The new line or carriage return. You might want to try the statement below if my first suggestion doesn't work.

    print("RUNNING\r\n");
  • It's \r\n

    I found this on page 4 of the datasheet.
    the AT instruction need to end the symbol \r\n
  • hi Duane, the "running" is only being sent to my terminal so i know its running not to the module. ive tried \r\n which i beleive is the same as 13,10, or 0x0D,0x0A in hex.
    i have tried so many combinations i have lost count. i am also able to send and receive with the propeller using it as just a wireless transmitter, but i can not send to it when i try to program it. if that makes sence?
  • fdserial_open(0, 2, 0, 9600);     // p0-p1  transmit to receiver
    
    This actually defines P2 as the TX pin.
  • gust a guess,

    inverted serial communication?

    program = fdserial_open(0, 2, 1 , 9600);
  • Hi Jonny Mac i started with pin1 as TX then switched to pin2 to make sure it wasnt the pin.

    Ltech, if i invert will that also change the RX? i know i can currentlty receive with (0,2,0,9600)?
  • from arduino terminal i can send "AT+BAUD" with NL and CR at the end and it works fine
  • This is very simple module to communicate with. I assume you only have one of these.

    Pin 12 needs to be grounded to send AT commands and the commands need to be ended with CR/LF or \r\n

    dprint(program, "AT+BAUD\r\n");

    Mike
  • hello Iseries, i have 10 of them and with pin 12 ungrounded using two flip modules i can send back and forth just fine, when i ground the "SET" pin and try to send the module an AT command i get no response back. i have tried dprint(program, "AT+BAUD\r\n"); but get nothing back.
  • something is different from how the arduino terminal and the propeller send out the command
  • Serial is serial and they both do the same thing. Show me the code on the Arduino side.

    Mike
  • I just figured it out, but i have no idea why it is so??
    #include "simpletext.h"
    #include "simpletools.h"                      // Include simple tools
    #include "fdserial.h" 
    
    
    // SET pin pulled low to program ID
    // SET pin pulled high for normal operation
    
    
    fdserial *program;
    
    char m = 0;
    char trash = 0;
    
    
    //-----------------------------------------------------------------
    
    
    int main()
    {
    
    //low(10);
    pause(100); 
      
                             // RX-TX  
       program = fdserial_open(0, 1, 0, 9600);     // p0-p1  transmit to receiver
         pause(100); 
    
    print("RUNNING\r\n");  
    high(7);
    
    pause(1000); 
    
    
    
    
    writeChar(program, 0x41); 
    writeChar(program, 0x54); 
    writeChar(program, 0x2B); 
    writeChar(program, 0x42); 
    writeChar(program, 0x41); 
    writeChar(program, 0x55); 
    writeChar(program, 0x44); 
    writeChar(program, 0x0D); 
    writeChar(program, 0x0A); 
     
    
    
    while(1)
    {
      m = fdserial_rxChar(program); 
          
      print("receive= %c,\n", m);  
               
      pause(100); 
        
    }  
    
    
    
    
    
    
      
    //high(10);  
    print("DONE!\n");     
    }
    
    
    //---------------------------------------------------------------
    
  • writeChar gave me a response back
  • with the arduino terminal you simply write AT+BAUD and hit send
  • I believe the Arduino terminal doesn't send any characters until you press Send. The benefit is that you don't have to worry about character timeouts -- this may be causing you problems with the Simple IDE terminal (I'm a Spin guy, so I don't use Simple IDE myself).
  • The problem is that the dprint function is converting \n into \r character for you. It's a feature.

    I ran across this before.

    The fdserial_txChar function is fine and will transmit the characters as is.

    Mike

  • Try this:
    char Data[] = "AT+BAUD\r\n";
    
    for (int i =0;i<strlen(Data);i++)
      fdserial_txChar(program, Data[i]);
    
    

    Mike
  • fdserial_txChar(program, "AT+BAUD"); //Command byte
    

    I think that fdserial_txChar(...) Only writes the single "A" character to the program device... "T+BAUD" just get dropped into the bit bucket. (Just my guess, as you've seemed to have fixed the problem by sending out the characters one at a time).


    dgately
  • Iseries, your code loop worked i just had to move the "int i" declaration before the loop for some reason, i kept getting the error below.

    JDY-40 PROGRAM (1).c:72:1: error: 'for' loop initial declarations are only allowed in C99 mode
  • You can keep the "for(int i = 0; i<strlen(Data);i++)" if you include "-std=c99 " in SimpleIDE's "Other Compiler Options" field.


    dgately
  • Dgately, thank you, i added it and it is working
  • here is the final code i am using to talk to all the chips.
    #include "simpletext.h"
    #include "simpletools.h"                      // Include simple tools
    #include "fdserial.h" 
    
    
    // SET pin pulled low to program ID
    // SET pin pulled high for normal operation
    //added "-std=c99 " in SimpleIDE's "Other Compiler Options" field.
    
    fdserial *program;
    
    char m = 0;
    
    //int i=0; 
    
    char baud[] = "AT+BAUD\r\n";//BAUD RATE
    char rfid[] = "AT+RFID\r\n";//WIRELESS ID
    char dvid[] = "AT+DVID\r\n";//DEVICE ID
    char rfc[] = "AT+RFC\r\n";//CHANNEL
    char powe[] = "AT+POWE\r\n";//TRANSMIT POWER
    char clss[] = "AT+CLSS\r\n";//MODE
    
    
    
    //-----------------------------------------------------------------
    
    
    int main()
    {
    
    //low(10);
    pause(100); 
      
                             // RX-TX  
       program = fdserial_open(0, 1, 0, 9600);     // p0-p1  transmit to receiver
         pause(100); 
    
    print("RUNNING\r\n");  
    
    
    pause(1000); 
    
    
    
    for (int i = 0;i<strlen(baud);i++)
      fdserial_txChar(program, baud[i]);
    
    while(m != 10)
    {
      m = fdserial_rxChar(program);       
      print("%c", m);             
      //pause(100);     
    }  
    m = 0;
    pause(100); 
    
    
    
    
    
    for (int i = 0;i<strlen(rfid);i++)
      fdserial_txChar(program, rfid[i]);
    
    while(m != 10)
    {
      m = fdserial_rxChar(program);       
      print("%c", m);             
      //pause(100);     
    }  
    m = 0;
    pause(100);
    
    
    
    
    
    for (int i = 0;i<strlen(dvid);i++)
      fdserial_txChar(program, dvid[i]);
    
    while(m != 10)
    {
      m = fdserial_rxChar(program);       
      print("%c", m);             
      //pause(100);     
    }  
    m = 0;
    pause(100);
    
    
    
    
    
    for (int i = 0;i<strlen(rfc);i++)
      fdserial_txChar(program, rfc[i]);
    
    while(m != 10)
    {
      m = fdserial_rxChar(program);       
      print("%c", m);             
      //pause(100);     
    }  
    m = 0;
    pause(100);
    
    
    
    
    
    for (int i = 0;i<strlen(powe);i++)
      fdserial_txChar(program, powe[i]);
    
    while(m != 10)
    {
      m = fdserial_rxChar(program);       
      print("%c", m);             
      //pause(100);     
    }  
    m = 0;
    pause(100);  
    
    
    
    
    
    for (int i = 0;i<strlen(clss);i++)
      fdserial_txChar(program, clss[i]);
    
    while(m != 10)
    {
      m = fdserial_rxChar(program);       
      print("%c", m);             
      //pause(100);     
    }  
    m = 0;
    pause(100);  
      
      
     
     
    print("DONE!\n");     
    }
    
    
    //---------------------------------------------------------------
    
Sign In or Register to comment.