This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

c code to send at cmmand and receive ok

Other Parts Discussed in Thread: TMS320C5515

hii

i am using TMS320C5515 AND TELIT GL865 AND TXS 0102 as voltage converter

and code composer studio v5

i want to send AT command and receive OK but am not getting ok ,i don't know what is problem and where is it

i am using following code to send AT command

*******************************************

void UartTxChar(unsigned char ch) //function to transmit character
{
CSL_Status status;
while (((hUart->uartRegs->LSR) & (0x0020)) != 0x0020);
status = UART_write(hUart, &ch, 1, 0);
if(status == CSL_SOK)
{
// printf("\n sent %c",ch);
}
else
{
//printf("\n Write Failed");
}
//USBSTK5515_waitusec(1000);
//while(command != ch );

}
void UartTxString(unsigned char *str) //function to transmit string
{

//while(*str != '\0')
{
UartTxChar(*str);
*str++;
}
UartTxChar(0X0D);
UartTxChar(10);
USBSTK5515_waitusec(25000);//put it to wait for sending
USBSTK5515_waitusec(2500000);//put to wait for the ok

}

**************************************

and following code to receive ok

**************************************


void uart_rxIsr(void)
{

//printf("rxc");
//UART_read(hUart,&command,1,0);
command = CSL_FEXT(hUart->uartRegs->RBR,UART_RBR_DATA);
//if (command == 's')
//{
// gcount = 1;

// dsp_call = 0;
//}

Recv[etc] = command;
for( j = 0; j<=etc; j++ )
printf("%c",Recv[j]);
etc++;
}

**********************************************

is any think wrong with is code please help me .

  • Congratulations on moving to a more appropriate forum - from: http://www.keil.com/forum/21798/

    Did you take time to read the linked FAQ on Smart Questions ?

    If you want to get the best responses to your forum posts, you would do well to pay attention to it... 

    ummed singh said:
    i don't know what is problem and where is it

    OK, so what have you done to try to find out what the problem is?

    Have you stepped through the code in the debugger to verify that it is actually doing what you intended?

    You have identified two requirements of your code:

    1. send AT command;
    2. receive OK.

    Clearly, you won't receive the "OK" if the "AT" didn't get sent - so have you checked that the "AT "does actually get sent?

    ummed singh said:
    is any think wrong with is code

    Yes, there is at least one basic error - it should be easy to see by stepping in the debugger...

    Debugging is an essential part of software development - so it's an important skill for you to learn.

    Here are some tips:

    http://www.8052.com/faqs/120313

    http://www.eetimes.com/discussion/break-point/4027526/Developing-a-good-bedside-manner?pageNumber=0

     

  • i have checked tms320c5515 by using loop back mode and  telit by using hyper terminal both are working properly.

    so where may be the problem ?

  • So does the "AT" get transmitted or not?

  • yeah, AT is get transmitted,but not receiving OK

  • How, exactly, did you verify that?

     If it leaves the TMS320C5515 output pin OK, how have you verified that it does actually arrive at the GL865 input pin?

    Does the GL865 actually send "OK" back?

  • ummed singh said:
    yeah, AT is get transmitted

    In that case, you are not actually using the code that you posted!!

     

    void UartTxString(unsigned char *str) //function to transmit string
    {

    //while(*str != '\0')
    {
    UartTxChar(*str);
    *str++;
    }
    UartTxChar(0X0D);
    UartTxChar(10);
    USBSTK5515_waitusec(25000);//put it to wait for sending
    USBSTK5515_waitusec(2500000);//put to wait for the ok

    }

    That's pretty illegible, isn't it? So lets format it correctly to start with:

    void UartTxString(unsigned char *str) //function to transmit string
    {

       //while(*str != '\0')
       {
          UartTxChar(*str);
          *str++;
       }

       UartTxChar(0X0D);
       UartTxChar(10);

       USBSTK5515_waitusec(25000);//put it to wait for sending
       USBSTK5515_waitusec(2500000);//put to wait for the ok
    }

    That code will just send the 1st character of the string, then character 0x0D, then character 10 - so you cannot use that code to send "AT" !!

    You Need to post the exact code that you are using!!

    Use copy & paste - do not do any manual editing/typing!

  • sorry for mistake

    my exact code is

    void UartTxChar(unsigned char ch) //function to transmit character

    {

    CSL_Status status;
    while (((hUart->uartRegs->LSR) & (0x0020)) != 0x0020);
    status = UART_write(hUart, &ch, 1, 0);
    if(status == CSL_SOK)
    {
    // printf("\n sent %c",ch);
    }
    else
    {
    //printf("\n Write Failed");
    }
    //USBSTK5515_waitusec(1000);
    //while(command != ch );

    }
    void UartTxString(unsigned char *str) //function to transmit string
    {

    while(*str != '\0')

    UartTxChar(*str++);

    UartTxChar(0X0D);
    UartTxChar(10);
    USBSTK5515_waitusec(25000);//put it to wait for sending
    USBSTK5515_waitusec(2500000);//put to wait for the ok

    }

  • ummed singh said:

    my exact code is

    No, I don't think it is - is it?

    And it's still pretty illegible, isn't it - or do you not believe in the conventional ways to lay-out code with indentation ?

    Note that you have to use a monospaced font - such as Courier or Courier New - to get indentation to work (as I showed you).

    You probably also need to ensure that you use only spaces - not TAB characters - for indenting.

    This is because the interpretation of TAB characters is entirely outside of your control.

    You should have already noticed this on the Keil forum...

    Any decent programmer's editor can be configured to insert spaces when you press the TAB button on the keyboard.

     

  • function to transmit AT cammand

    *********************************************************

    void UartTxChar(unsigned char ch) //function to transmit character
    {
    CSL_Status status;
    while (((hUart->uartRegs->LSR) & (0x0020)) != 0x0020);
    status = UART_write(hUart, &ch, 1, 0);
    if(status == CSL_SOK)
    {
    // printf("\n sent %c",ch);
    }
    else
    {
    //printf("\n Write Failed");
    }
    //USBSTK5515_waitusec(1000);
    //while(command != ch );

    }
    void UartTxString(unsigned char *str) //function to transmit string
    {

    while(*str != '\0')

    UartTxChar(*str++);

    UartTxChar(0X0D);
    UartTxChar(10);
    USBSTK5515_waitusec(25000);//put it to wait for sending
    USBSTK5515_waitusec(2500000);//put to wait for the ok

    }

    ****************************************************

    function to receive OK

    ******************************************************

    void uart_rxIsr(void)
    {

    //printf("rxc");
    //UART_read(hUart,&command,1,0);
    command = CSL_FEXT(hUart->uartRegs->RBR,UART_RBR_DATA);
    //if (command == 's')
    //{
    // gcount = 1;

    // dsp_call = 0;
    //}

    Recv[etc] = command;
    for( j = 0; j<=5; j++ )
    printf("%c",Recv[j]);
    etc++;
    }

    ***********************************

    is it ok ?

    know can you tell me,what is wrong with code ??? 

  • ummed singh said:

    is it ok ?

    Does it look OK to you?

    Do you really not believe in any indentation?

  • No,don't believe

  • If you want other people to read your code - especially if you want them to do it for free - then it is very much in your interest to present your code in a readable format!

     

  • actually problem is that i am not getting how  to intended code.

  • You mean you don't know how to create it in your editor, or you don't know how to post it into this forum?

     

  • CODE TO SEND AT COMMAND

    void UartTxChar(unsigned char ch) //function to transmit character
    {
        CSL_Status status;
        while (((hUart->uartRegs->LSR) & (0x0020)) != 0x0020);
        status = UART_write(hUart, &ch, 1, 0);
        if(status == CSL_SOK)
                {
                  // printf("\n  sent %c",ch);// ummed ,check wether sent or not
                }
                else
                {
                    //printf("\n  Write Failed");
                }
        //USBSTK5515_waitusec(1000);
        //while(command != ch );

    }
    void UartTxString(unsigned char *str) //function to transmit string
    {

    while(*str != '\0')
    UartTxChar(*str++);
    UartTxChar(0X0D);
    UartTxChar(10);
    USBSTK5515_waitusec(25000);//put it to wait for sending
    USBSTK5515_waitusec(2500000);//put to wait for the ok

    }

    *************************************************

    CODE TO RECEIVE OK

    ******************************************

    void uart_rxIsr(void)
    {

        //printf("rxc");
    //UART_read(hUart,&command,1,0);
        command = CSL_FEXT(hUart->uartRegs->RBR,UART_RBR_DATA);
        //if (command == 's')
        //{
        //    gcount = 1;

    //        dsp_call = 0;
        //}

        Recv[etc] = command;
        for( j = 0; j<=etc; j++ )
         printf("%c",Recv[j]);
        etc++;
    }

    IS IT OK ?

  • ummed singh said:
    IS IT OK ?

    Does it look OK?

    Does it look like the kind of presentation that you see in your textbook examples?

    Does it look like the example I posted earlier?

    What did I say to you about mono-spaced fonts...?

    Why is it full of commented-out stuff?

    Get it tidied up, then build & test it, then - and only then - post it.

  • It has been said that the purpose of source code is as much to convey the programmer's intent to the human reader as it is to convey the programmer's intent to the compiler.

    This is why it is important to make your code clear and easy to read for human readers.

    One of the key tools to making source code clear and easy to read is the use of indentation; ie, varying the spacing of the start of lines away from the left-hand margin.

    Left margin
    :
    :
    if( condition )
       do_something();
           :
           :
            Indented

    The purpose of indentation is to show that one section of code is controlled by or subordinate to another; in the example above, do_something() is controlled by the if line -  the function is called if (and only if) the condition is true.

    When a block or group of statements is subordinate, then each controlled statement should be at the same level of indentation:

    Left margin
    :
    :
    if( condition )
    {

       do_this();
       do_that();
       do_theother();
    :

           :
            All indented to the same level.

    Note that the positioning of the braces is a matter of personal preference (or imposed policy) and can be a subject of hot debate!

    Of course, a controlled statement can (and very often does) have its own subordinates:

    Left margin
    :
    :
    if( condition1 )
    {

       do_this();
       do_that();
       do_theother();
       if( condition2 )
          do_something_special();
    }    
    :

                  :
                   Further indent!

    The amount by which to indent each step is a matter of personal preference (or imposed policy); I find that 3 or 4 columns is a good compromise between legibility and excessive line length.

    The easiest way to achieve the indentation when writing the code is, obviously, just to press the space key on the keyboard the requisite number of times at the start of each line!

    Do not use TAB characters (ASCII code 9) to indent code, because there is no standard definition of how TAB characters will be interpreted!
    In particular, many (most?) web forums will ignore them entirely!

    Instead of having to manually type all the spaces, any decent programmer's editor will have the option to insert the appropriate number of spaces when you press the TAB key on the keyboard. Use this facility!

    Also, decent programmer's editors will have facilities such as:

    • Select a block of text (several lines) and increase the indent level of that block;
    • Select a block of text (several lines) and decrease the indent (sometimes called "outdent");
    • Automatically set the indent level when you start a new line, based on the indent of the previous line.

    So it really isn't difficult or tiresome to do this!

    Finally, to get source code to display properly, it is important that all characters have the same width; ie, to use a mono-spaced or fixed-width font - such as Courier  or Courier New.

    Most web forums have some specific format which must be applied to do this - and prevent other undesirable text effects like word wrapping.

    On this forum, just using the  Courier New  font is sufficient.


    Addendum:

    Jens-Michael Gross said:
    It is important that the text you paste into the E2E editor is plain ASCII text without any formatting information (font/bold/whatever). Else the editor will see this formatting and embed it into the later generated HTML code, overriding the default editor style - with the side-effect that leading spaces are swallowed (HTML standard).

    http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/p/227376/804056.aspx#804056

  • Perhaps you should attach your entire test code. Hopefully your test code is entirely in one file. That way people can see the UART setup, IRQ handler setup, etc.

    I haven't used the C55xx series directly. I've had to port code from a C5507 to another platform. Are you using the C55xx CSL library? Your UART calls do not match the usual CSL UART calls.

    It sounds like you trying to talk to your device immediately. Maybe try attaching your serial port to a PC and use a HyperTerminal or TeraTerm to test you code.

  • Before attaching any code, there is some basic debugging that the OP needs to do himself:

    1. Is the "AT" command actually being transmitted correctly from the DSP's output pin?
      If not, then the fault obviously lies somewhere in the transmit code, and the debugger can be used to step through that.
       
    2. Once step 1 is working, is the "AT" command actually reaching the modem's input pin?
      If not, then there is obviously some hardware  fault in the connection.
       
    3. Once steps 1&2 are working, is the "OK" response appearing at the modem's output pin?
      Obviously, the DSP cannot receive this response if it is not being sent!
       
    4. Once steps 1-3 are working, is the "OK" response reaching the DSP's input pin?
      If not, then there is obviously some hardware  fault in the connection.
       
    5. Once steps 1-3 are working, the debugger can again be used to step through the receiving code...

    Again, this is just a really basic, common-sense, methodical approach to tracing through what should happen - and seeing where it goes wrong.

     

  • Norman Wong said:
    Maybe try attaching your serial port to a PC and use a HyperTerminal or TeraTerm to test you code.

    That is, in general, a very good way to approach this kind of thing!

    Using a terminal emulator, you can answer the questions:

    1. Is the "AT" actually transmitted?
    2. When you manually send "OK", is it received?

    But one important point to note:

    Do not connect RS232 direct to DSP/microcontroller pins!!

     

  • Andy Neil said:

    Do not connect RS232 direct to DSP/microcontroller pins!!

    See: http://bit.ly/T6utXh for details...