Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 #include <mega32.h> #include <stdio.h> #include <stdlib.h> #asm .equ __lcd_port=0x18 ;PORTB #endasm #include <lcd.h> #include <delay.h> void ustx(void) { UDR=0x0d; UDR=0x0a; } void srtx(void) { UDR=0x1a; } void main(void) { UCSRA=0x00; UCSRB=0x08; UBRRH=0x00; UBRRL=0x33; lcd_puts("hello"); printf("A"); delay_ms(5000); printf("AT"); ustx(); delay_ms(2500); printf("AT+IPR=9600"); ustx(); delay_ms(2500); printf("AT"); ustx(); delay_ms(2500); printf("AT+CMGF=1"); ustx(); delay_ms(2500); printf("AT+CSMP=17,167,0,241"); ustx(); delay_ms(2500); printf("AT+CMGS=\"9566809793\""); ustx(); delay_ms(2500); printf("Hello!!"); srtx(); ustx(); delay_ms(2500); }
Inside ustx():drtvskuthsav said:Here is My code. It is not working.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 #include <mega32.h> #include <delay.h> #include <stdio.h> #include <stdlib.h> #include <delay.h> unsigned char si=0,qi=0; char q[160]; interrupt [USART_TXC] void usart_transmit_isr(void) {if(qi!=si) UDR=q[si++]; } void sendmsg(char *s) { qi=0; si=1; while(*s) {q[qi++]=*s++; } UDR=q[0]; } void main(void) { UCSRA=0x00; UCSRB=0x48; UBRRH=0x00; UBRRL=0x33; #asm ("sei") sendmsg("AT\r\n"); delay_ms(2000); sendmsg("AT+CMGF=1\r\n"); delay_ms(2000); sendmsg("AT+CSMP=17,167,0,241\r\n"); delay_ms(2000); sendmsg("AT+CMGS=\"+917739478576\"\r\n"); delay_ms(2000); sendmsg("Hello!"); delay_ms(2000); UDR=0x1A; }
Still this code does not listen to the modem's responce, no rx interrupt exists.drtvskuthsav said:I tried this with Hyperterminal. Its printing the code as expected. But when I use this with modem am not able to send any messages.
Still this code does not listen to the modem's responce, no rx interrupt exists.
Since you are using a terminal software, could you please share what is the modem's responce to your commands?
A snapshot of the terminal screen would be even better.
Yes please, a screenshot would be even better.drtvskuthsav said:I used Hyperterminal to test if the modem is able to send messages. Do you want me to share the response I got from the modem when I used Hyperterminal?
I attached the snapshot of Hyperterminal when used to communicate with SIM900 ModemYes please, a screenshot would be even better.
It looks OK. The modem responds that the sms left to network.
It may sound stupid, but are you sure that this phone is valid? Maybe you would try to send it by typing the number in international format?
For example in my country the international code is 0030. So I would try sending an sms to 0030123456 or +30123456.
OK. Can you debug your code?drtvskuthsav said:Am receiving the message on my phone when I send the message using Hyperterminal. But am not receiving the message when am sending the 'at commands' to modem from ATmega32.
OK. Can you debug your code?
drtvskuthsav said:I was trying to send AT Commands to SIM900 using Serial Communication. Here is My code. It is not working.
I tried this with Hyperterminal. Its printing the code as expected. But when I use this with modem am not able to send any messages.
Am receiving the message on my phone when I send the message using Hyperterminal. But am not receiving the message when am sending the 'at commands' to modem from ATmega32. I want help with this part.
When I connect microcontroller to PC via DB9, it is printing the code on Hyperterminal as it should. Then I disconnected it from PC and connected it to MODEM. No message is sent.
https://en.wikipedia.org/wiki/DebuggingI did not understand what do you mean by debug.
OK, this is how an interrupt routine should look like. I don't use your compiler so the function name is random. You need to set RXCIE bit inside UCSRB register in order to activate rx interrupt.I don't have a code for receive. Can you give some code?
volatile unsigned char in_data[200]
volatile unsigned char in_cnt = 0;
void rx_isr (void)
{
volatile unsigned char _udr = UDR
if(in_cnt >= 200)
in_cnt = 0;
in_data[in_cnt] = _udr;
}
OK please decide what is your problem. First you have problems in general, then the problem was that everything looked good but no sms was sent, then you send the sms only through hyperterminal and finally the code is printed OK but no sms is sent. We are not playing games here, give a clear description from the beggining if you want to get help. After 12 posts, still the problem is not clear because you constantly change your mind about what the problem is.
OK, this is how an interrupt routine should look like. I don't use your compiler so the function name is random. You need to set RXCIE bit inside UCSRB register in order to activate rx interrupt.
Code:volatile unsigned char in_data[200] volatile unsigned char in_cnt = 0; void rx_isr (void) { volatile unsigned char _udr = UDR if(in_cnt >= 200) in_cnt = 0; in_data[in_cnt] = _udr; }
So now you have your incoming data stored inside in_data[] array. I just wonder what are you going to do with those data since no debug will take place...
OK, now you cleared things a bit.
1. You send sms from hyperterminal but you cannot do that from ATmega?
1. If so, then the problem is easy to fix. Since the baudrate is OK (because hyperterminal printed the bytes that the MCU send to the modem), then the problem is you are missing something. This "something" should possibly be control bytes, like \r, or \n or the sub character, after you send sms text. It would help if we could see in hyperterminal the exact same screenshot, but this time in hex bytes and not as text. I know hyperterminal is kind of simple software, I don't know if it can print in hex. There other terminal software you can get for free, please take a look at the below edaboard thread.
https://www.edaboard.com/threads/228501/
So the problem is that the modem does not at all respond to your commands.drtvskuthsav said:Here I attached the snapshots of terminal software when I used ATmega and Docklight.
So the problem is that the modem does not at all respond to your commands.
As far I saw from the docklight screenshots, you set the baudrate at 9600. From your register values it also seems that you are using an 8MHz crystal (or the internal RC).
Reading the datasheet's note with bold in page 11, someone can find out that the modem operates by default at 115200.
https://robokits.co.in/datasheets/SIM900_ATC_V1_00.pdf
If the problem is not with baudrate (you mentioned that autobaud is used), then you should look into hardware. Commands seem to be OK.
Check out power supply, reset pin, and all power pins of the modem in general.
However, I would make sure 100% that baudrate is not a problem, by reseting modem's factory settings and then try again at 115200.
I have already checked your UART settings and they seem OK. Since we have the screenshot, all the information we need is there.drtvskuthsav said:Can you once again make sure that my code is ok.
The "AT" or "at" prefix must be set at the beggining of each Command line. To terminate a Command line enter <CR>.
Commands are usually followed by a responce that includes "<CR><LF><responce><CR><LF>".
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?