HI,
Have an issue to toggle led on,off using GSM SIM900 interface with atmega 8
AT command work fine, uart work fine
I made this function [USART_WriteChar] to send all characters of strings one by one and will wait for [\n] and after that get [\r]
But when i try to send my message that will be here [DEV1 or DEV0] to make led turn on or off nothing happen
I use this code :
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "uart.h"
int main(void)
{
uint8_t count;
char ch[200];
DDRC|=(1<<0)|(1<<1)|(1<<2);
DDRB|=(1<<0);
USARTInit(103);
for(count=0;count<200;count++)
{
ch[count] = ' ';
}
_delay_ms(1000);
USART_WriteChar('\n');
USART_WriteChar('A');
USART_WriteChar('T');
USART_WriteChar('+');
USART_WriteChar('C');
USART_WriteChar('N');
USART_WriteChar('M');
USART_WriteChar('I');
USART_WriteChar('=');
USART_WriteChar('1');
USART_WriteChar(',');
USART_WriteChar('1');
USART_WriteChar(',');
USART_WriteChar('0');
USART_WriteChar(',');
USART_WriteChar('0');
USART_WriteChar(',');
USART_WriteChar('0');
USART_WriteChar('\n');
while(1)
{
_delay_ms(100);
USART_WriteChar('\n');
USART_WriteChar('A');
USART_WriteChar('T');
USART_WriteChar('+');
USART_WriteChar('C');
USART_WriteChar('M');
USART_WriteChar('G');
USART_WriteChar('R');
USART_WriteChar('=');
USART_WriteChar('1');
USART_WriteChar('\n');
_delay_ms(100);
if(ch[0]=='D'&&ch[1]=='E'&&ch[2]=='V')
{
if(ch[0]=='1')
{
PORTC &=~ (1<<0);
PORTC |= (1<<1);
PORTC |= (1<<2);
}
if (ch[0]=='0')
{
PORTC |= (1<<0);
PORTC &=~ (1<<1);
PORTC &=~ (1<<2);
}
}
else
{
PORTB |= (1<<0);
}
//_delay_ms(100);
USART_WriteChar('\n');
USART_WriteChar('A');
USART_WriteChar('T');
USART_WriteChar('+');
USART_WriteChar('C');
USART_WriteChar('M');
USART_WriteChar('G');
USART_WriteChar('D');
USART_WriteChar('=');
USART_WriteChar('1');
USART_WriteChar(',');
USART_WriteChar('4');
USART_WriteChar('\n');
break;
_delay_ms(100);
}
return(0);
}
USART HEADER FILE :
#ifndef UART_H_
#define UART_H_
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
void USARTInit(uint16_t ubrr_value);
void uart_init();
static int USART_WriteChar(char data);
static int USART_WriteChar(char data)
{
//Wait untill the transmitter is ready
if (data == '\n')
USART_WriteChar('\r');
while(!(UCSRA & (1<<UDRE)));
//Now write the data to USART buffer
UDR=data;
return 0;
}
void USARTInit(uint16_t ubrr_value)
{
//Set Baud rate
UBRRL = ubrr_value;
UBRRH = (ubrr_value>>8);
/*
Set Frame Format
>> Asynchronous mode
>> No Parity
>> 1 StopBit
>> char size 8 */
UCSRA=(1<<U2X);
UCSRC=(1<<URSEL)|(3<<UCSZ0);
UCSRB=(1<<RXEN)|(1<<TXEN);
//stdout = &uart_out;
}
#endif /* UART_H_ */