aminpix
Advanced Member level 4
I am trying to work with GSM module M590/Neoway connected to a Atmega32A.
I went through the command set and datasheet. but still I can't communicate with M590. for example i wrote the following code to get any response from M590, but after running the code, i didn't get anything from M590.
Is there anybody here can help me and share some code (especially AVR, because I only know AVR micro-controllers) with me.
I went through the command set and datasheet. but still I can't communicate with M590. for example i wrote the following code to get any response from M590, but after running the code, i didn't get anything from M590.
Is there anybody here can help me and share some code (especially AVR, because I only know AVR micro-controllers) with me.
Code:
#ifndef F_CPU
#define F_CPU 8000000UL // 8 MHz clock speed
#endif
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#define USART_BAUDRATE 115200
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
volatile unsigned char value;
volatile unsigned char LED_ind ;
ISR(USART_RXC_vect){
value = UDR; //read UART register into value
LED_ind = 0b00000100 ;
PORTA = LED_ind ;
_delay_ms(3000);
}
void uart_init()
{
UCSRB = ((1<<RXEN) | (1<<TXEN) | (1<<RXCIE)); // Enable Receiver, Transmitter, Receive Interrupt
UCSRC = ((1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0)); // 8N1 data frame
UBRRL = BAUD_PRESCALE;// Load lower 8-bits into the low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8);
}
void USART_SendByte(uint8_t u8Data)
{
// Wait until last byte has been transmitted
while((UCSRA &(1<<UDRE)) == 0);
// Transmit data
UDR = u8Data;
}
void uart_putc(unsigned char c)
{
// wait until UDR ready
while(!(UCSRA & (1 << UDRE)));
UDR = c; // send character
}
uint8_t USART_ReceiveByte(){
while((UCSRA &(1<<RXC)) == 0);
LED_ind = 0b00000100 ;
PORTA = LED_ind ;
_delay_ms(2000);
return UDR;
}
void uart_puts(char *s,int s_size)
{
// loop until *s != NULL
for(int i = 0 ; i < s_size; i++)
{
uart_putc(s[i]);
}
}
int main(void)
{
DDRA = 0xFF; //Configure PortA as an Output port
uart_init();
sei(); // enable all interrupts
char *str ;
while(1)
{
//TODO:: Please write your application code
LED_ind = 0b00000000 ;
PORTA = LED_ind ;
_delay_ms(500);
LED_ind = 0b00000001 ;
PORTA = LED_ind ;
_delay_ms(500);
uart_puts("AT+CREG?",8);
LED_ind = 0b00000100 ;
PORTA = LED_ind ;
USART_ReceiveByte();
_delay_ms(1000);
}
}