I am currently working with ATTiny1634, executing the following code
After executing break statement the program is not exiting from the inner while loop to outer while loop; instead, it jumps to main function.
To test, I removed all the USART functions uart_init
, writecommand
, transmit
, after removing all these function code is working perfectly.
The code works with ATMega16A, but getting problem in ATTiny1634. Why?
int main()
{
DDRC=1<<DDRC0;
DDRA|= 1<<PORTA3;
uart_init();
sei();
writecommand("AT");
writecommand("ATE0");
while (1)
{
int8_t t;
PORTA=1<<PORTA3;
// controller sleep mode
if(MCUSR & (1<<WDRF))
{
MCUSR&= ~(1<<WDRF);
WDTCSR|= 1<<WDE;
WDTCSR= 0x00;
}
PORTA=0<<PORTA3;
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode selected
//PRR=0X75;
wdt_reset();
WDTCSR |= 1<<WDE;
WDTCSR |= (1<<WDIE|1<<WDP3 |1<<WDP0); // ENABLE WATCH DOG TIMER INTERRUPT WITH 8S TIME OUT
sleep_enable(); //set SE bit
sei();
sleep_cpu(); //sleep mode activated
while (1)
{
if(count >=2) // 80S DELAY
{
count=0;
sleep_disable(); // SE bit reset
WDTCSR|=0<<WDE|0<<WDIE; // disable watch dog timer
transmit("AT+CFUN=1\r\n");
_delay_ms(2000);
clearbuffer(buff);
clearbuffer(temp_buff);
_delay_ms(2000);
break;
}
else
{
WDTCSR|=1<<WDIE;
sleep_cpu();
}
}
}
}
The code for writecommand
:
void writecommand(char *q)
{
char str[3]="OK";
char str1[50];
do
{
clearbuffer(str1);
strcpy(str1,q);
i=0;
_delay_ms(10);
clearbuffer(buff);
clearbuffer(temp_buff);
transmit(str1);
transmit("\r\n");
_delay_ms(200);
for(j=10;j>0;j--)
_delay_ms(10);
logic(); // my me
clearbuffer(buff);
}while(strcmp(str3,str)!=0);
I am using the 8 MHz internal osc and the baud rate in USART is 9600. Other functions are:
void uart_init()
{
UCSR0B=(1<<TXEN0)|(1<<RXEN0)|(1<<RXCIE0); //transmitter enable,receiver enable,receive complete interrupt enable
UCSR0C=(1<<UCSZ01)|(1<<UCSZ00);//8 bit data bits
UBRR0L=51; // baud rate 9600
}
void uart_send(unsigned char ch)
{
while(!(UCSR0A &(1<<UDRE0)));
UDR0=ch;
}
void transmit(char *p)
{
i=0;
while(*p!='\0')
{
uart_send(*p);
p++;
}
}
void clearbuffer(char *p)
{
while(*p!=0)
{
*p=' ';
p++;
}
}