tip for creating a function for AT Commands

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi

in atmel studio 06

i want create a function that return at command

i have this "AT+GSLP=time" , in this time can be changetime

i want right a function like this

Set_time(unsigned char time) and this return "AT+GSLP=time"

Example:

Set_time(100);

Return:

"AT+GSLP=100"

This topic has a solution.
Last Edited: Mon. Apr 25, 2016 - 10:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And I want Ice Cream......

 

You will need to show what you have done so far, explain what is happening and someone here will help you get it right.  No code, no help!

 

 

Jim

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well i try with function to return array but it cant be in c atmel studio
Maybe i should work with pointer but i could not do it so far

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, that may be, but without seeing your code, how would we know?

There is a sticky at the start of the forum that explains how to ask good questions so you can get good answers.

 

 

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is not a big question that want whole code.
Just give me a hint. I'll do the rest

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

navidrct wrote:
This is not a big question that want whole code. Just give me a hint. I'll do the rest

I think that kiObk gave you a pretty good tip in his posts in this thread. Also, I am allergic to milk, so I want a pony instead.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks I'll figure it out
Sorry to bother u

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have two options (at least):

 

Option #1

Pass an allocated buffer to the function.

 

Example call:

char timeCmdBuffer[32];  //.. or whatever langth is neccesary
// Build the command
​BuildTimerCmdString( time, timeCmdBuffer);
// Send it
UartSendString(timeCmdBuffer);

 

Option #2

Have the string-building funtion allocate a local buffer. For this to work the buffer must be declared 'static' in the function (or it will effectively cease to exist when the function exits). The function returns a pointer to this buffer.

 

Example call:

 

UartSendString(BuildTimerCmdString(time));

Enough hints?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

navidrct wrote:
Well i try with function to return array but it cant be in c atmel studio

Why can't it ?

 

Show what you tried; explain why you feel it didn't work.

 

 

i should work with pointer

You do realise that arrays and pointers in 'C' are very closely related - don't you?

 

http://c-faq.com/aryptr/index.html

 

Quote:
but i could not do it so far
 

 

So, again, show what you tried!

 

This is basic 'C' stuff - nothing specifically to do with Atmel, Atmel Studio, nor AVR.

 

Here are some 'C' learning & reference resources: http://blog.antronics.co.uk/2011...

 

Just give me a hint

To start with, It will probably be easier to experiment on a PC - rather than on a microcontroller.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Another hint: look at the way that the standard string handling functions work: they manage to be passed strings (ie, arrays) and to return string (ie, array) results - don't they ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

On a more general note,

navidrct wrote:
Example:

Set_time(100);

Return:

"AT+GSLP=100"

Seems a rather bizarre approach.

 

Would it not be more straightforward to just have a set_time() function which would issue the appropriate AT Command?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

navidrct wrote:
Well i try with function to return array but it cant be in c atmel studio

Why can't it ?

I suspect the OP can't use Atmel Studio because he is not using an Atmel microprocessor in his project. Here is why I think so: https://www.avrfreaks.net/forum/a.... There is some conflicting information is his posts so I can't be sure. It is also clear the OP is not even doing a basic online search. The first keywords I typed into google returned 2 different app notes put out by NXP that does exactly what the OP is trying to do as the first links.

 

Edit to add: As far as doing it on a PC, this is my go to development setup for doing just that: https://sourceforge.net/projects... and this is the search string I tried: nxp send string out uart

Last Edited: Mon. Apr 25, 2016 - 07:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Someguy22 wrote:
 this is the search string I tried: nxp send string out uart 

To be fair, that isn't what he was trying to do - he was trying to get a function to return a string.

 

I guess his next question would be, "how can I send this string out of the UART?"

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Someguy22 wrote:

I suspect the OP can't use Atmel Studio because he is not using an Atmel microprocessor in his project.

 

In the OP, he states:

in atmel studio 06

i want create a function that return at command

so he is trying to use Atmel Studio.

 

navidrct wrote:

Well i try with function to return array but it cant be in c atmel studio

What I believe he is trying to say is that he is unable to implement the desired function in C using Atmel Studio.

 

He was just asking for help in how to get started.

 

Last Edited: Mon. Apr 25, 2016 - 08:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The thread has nothing to do with Studio issues so it is at best in the wrong forum. Moving to general programming for now.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly