Hi
I am very confused to communicate between sim800 and xmega in Atmel Studio 6.2, I set baud rate 9600 and use USARTD on PORTD it works fine in one xmega but it may be lost because of VCC gnd short circuit, I use another one but send is ok and sms can send by my command to sim800 but when I want to receive data it does not work properly and receive "AT" instead of my sms. here is the code of usart initial and clock set to 32mhz internal:
PORTD.DIRSET = PIN7_bm; PORTD.DIRCLR = PIN6_bm; USARTD1_BAUDCTRLA=0xCF; //for baud rate 9600, BSEL=12, BSCALE=4 as per data sheet USARTD1_BAUDCTRLB=0x00; //BSCALE=4, upper 4 bits out of 12 bit used for USART baud rate setting will be zero USARTD1_CTRLB|=USART_RXEN_bm|USART_TXEN_bm; //enable USART receiver and transmitter USARTD1_CTRLC|=USART_CHSIZE1_bm|USART_CHSIZE0_bm; //asynchronous mode, 8-bit character size, 1 stop bit, no parity
sms receive code:
for (sms_n=0;sms_n<=100;sms_n++){ sms[sms_n]=Null;} end_message=0;sms_n=0; sendString("AT+CMGF=1\n\r");_delay_ms(250); sendString("AT+CMGR=1\n\r");_delay_ms(1000); sendString("AT+CMGR=1\n\r"); //read sms while(end_message==0) { rec=usart_receiveByte(); if(rec==Null) { } else if (((rec==LF || rec==CR)) && sms[1]!=Null) { end_message=1; } else { if(sms_n>=100) { } else { sms[sms_n]=rec; sms_n++; } } }
and receive function:
char usart_receiveByte() { while( !(USARTD1_STATUS & USART_RXCIF_bm) ); return USARTD1_DATA; }
I tested my sim800 with Arduino Uno it works perfectly.