Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Sending AT Commands from ATmega8 to GM862-GPS using data from EEPROM

Status
Not open for further replies.

tasosmi

Newbie level 6
Joined
Nov 18, 2009
Messages
11
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
GREECE
Activity points
1,371
Hello,
i am using the ATmega8 to send some AT commands to GM862-GPS. I am using C language.

To send the PIN of the SIM card, i send "AT+CPIN=xxxx"

My question is: instead of the 4 digit number (xxxx), can i put there something that would read the pin number from EEPROM?

Is there a sample C code that i could use?

Thank you in advance
 

Hi.
I'll assume you know how to read from EEPROM, and let's say your PIN is stored in a 2-byte unsigned int eepin.

You can then write:
Code:
char strbuf[20];
sprintf(strbuf, "AT+CPIN=%04u", eepin);
then send strbuf to your device.

If your compiler doesn't support formatted sprintf, you'll have to write your own routine to convert the integer eepin to ASCII, but don't forget to add the leading zeros up to the length of the PIN (4, in this case).
 
Last edited:
  • Like
Reactions: tasosmi

    tasosmi

    Points: 2
    Helpful Answer Positive Rating
Last edited:
  • Like
Reactions: tasosmi

    tasosmi

    Points: 2
    Helpful Answer Positive Rating
hi arthur0,
first of all i want to say thank you and also that i am a begginer in c language. so the more you can expain the better!!!

from eeprom i read with the command: eeprom_read_block(...) and yes my compiler supprts sprintf. I use the AVR Studio 4.18 with winavr.

so here is a little bit of the code:

const char AT_P[] PROGMEM = "AT"; // say hello to GM862-GPS
const char ATIPR_P[] PROGMEM = "AT+IPR=19200"; //setting baus rate
const char ATCMEE_P[] PROGMEM = "AT+CMEE=2"; // extended error report

const char *MODEM_INIT_SEQ[] = {AT_P, ATIPR_P, ATCPIN_T, ATCMEE_P};

uint8_t EEMEM pin[4] = "3163";

void atcpin(void){
char ATCPIN_T[5+1];
sprintf(ATCPIN_T, "AT+CPIN=%04u", pin);
}

and then i use MODEM_INIT_SEQ (i = 0 - 4) to send them to GM862-GPS

I'll give it a try and i would come back with some more questions!!!

Thank you, you are very very helpfull :grin:

---------- Post added at 16:03 ---------- Previous post was at 16:00 ----------

why not to use integrated free python interpreter?
**broken link removed**

Python for m2m Applications

hi js,
i alredy have made a board with ATmega8 onboard and also i don't know nothing about python. Maybe is easier but i am not going to use that method. Thank you for your suggestion
 

Hi tasosmi,

I’m glad I could help. On the other hand, looking back at my code, I realized that the string buffer is too small! You need enough space to accommodate the whole AT command, not just the resulted ASCII number (of up to 5 chars (if eepin € [10000, 65535]) plus a null). I edited my code and made the buffer 20 chars long ‘cause I didn’t feel like counting the chars.
Now I don’t know in detail how your system is built up and works, but in my previous experience, I had to send carriage return (CR = ‘\r’) and line feed (LF = ’\n’) after every command, for it to be accepted.
You might want to consider that in your code and write "AT+CPIN=%04u\r\n", in the sprintf, if needed (of course, your buffer needs to accommodate 2 extra chars).

Arthur
 
  • Like
Reactions: tasosmi

    tasosmi

    Points: 2
    Helpful Answer Positive Rating
Thank you Arthur for your indication
i had already incorporate the \r\n in an other loop.
Now i am starting to understand the C language syntax and how i can write a code, so i might come back with some other questions!!! Thanks again!!!

Tasos
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top