Interfacing a GSM module with AT32U3C3

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

Hello all, I hope I'm posting this on the right forum.

I lately got a gsm module (Quectel M10) which I want to interface with my AT32U3C3 to send an sms through, for now I am able to send an sms by using putty emulator to send the AT commands.

Is it a correct approach to write a code that will send those same AT commands as strings through the microcontroller's tx pin to the module's rx pin ?

For example:

gsm_send_command("AT/n");

void gsm_send_command(char *str)

{ while(*str)
{
usart_putchar(Usart, *str++);
}
}

Last Edited: Sun. Jul 9, 2017 - 01:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, that's the way to do it.

 

But note:

 

  1. The command terminator is a single CR character - not LF nor CRLF.
     
  2. The biggest mistake that people make is failing to observe the responses from the module to each command that you send.
    The AT Command protocol is a command-response protocol - so you must wait for the response to each command before sending the next command.
    Do not rely upon "blind" delays.
    See http://www.avrfreaks.net/comment... and many others.
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And remember how to properly post source code: http://www.avrfreaks.net/comment...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include <asf.h>
#include <user_board.h>

const gpio_map_t USART_GPIO_MAP =
{
	#if defined(AVR32_USART3)
	{83, 5},

	{84, 5},

	{82, 5},

	{117, 0},
	#endif
};

const usart_options_t USART_OPTIONS =
{
	.baudrate = 9600,
	.channelmode = USART_NORMAL_CHMODE,
	.charlength = 8,
	.paritytype = USART_NO_PARITY,
	.stopbits = USART_1_STOPBIT,
};

void gsm_putstring(char *str);
void send_sms(char *number, char *text);

int i;

int main (void)
{
	board_init();
	sysclk_init();

	// Assign GPIO to USART.
	gpio_enable_module(USART_GPIO_MAP,
	sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));

	// Initialize USART in RS232 mode.
	usart_init_rs232(&USART, &USART_OPTIONS, sysclk_get_main_hz());

	// Check connection
	gsm_putstring("AT\n");
	gsm_putstring("CR");

	int at_response = usart_getchar(&USART);

	while(1)
	{
	if (at_response == "OK")
	gpio_set_gpio_pin(LED_GREEN);
	break;

	else
	gpio_set_gpio_pin(LED_RED);
	}
}

void gsm_putstring(char *str)
{
	while (*str)
	{
		usart_putchar(&USART, *str++);
	}
}

 So this is what i have now, unfortunately i'm unable to get a response fro the module yet (getting red LED), I think i should define at_response as a char rather than int, but the usart_getchar function returns an integer.

Last Edited: Sun. Jul 9, 2017 - 04:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hani_N wrote:
but the usart_getchar function returns an integer.

So think about why that is ...

 

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

You might want to follow this thread: http://www.avrfreaks.net/forum/a...

 

EDIT

 

In particular, look at the 'Attentive' library found by ki0bk:

http://www.avrfreaks.net/comment...

http://www.avrfreaks.net/comment...

Last Edited: Wed. Jul 12, 2017 - 01:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks awneil ! those were really helpful :)