Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AVR USART Receive Interrupt problem

Status
Not open for further replies.

kushal1211

Newbie level 4
Joined
Mar 21, 2016
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
38
I have the following code. I am trying to make port C high when i receive an SMS with "ON1" on GSM SIM900A.
But i am facing problems with interrupts it is not working. Following is the attached code. Help will be appreciated. I am using mikroC pro


Code:
#include <built_in.h>
unsigned char rx1[95],Rxdata;
unsigned int i=0,j;

void UartRxInterrupt() iv IVT_ADDR_USART__RXC
{
	RxData = UART1_Read();
	if(Rxdata=='S')
	{
		SREG|=(1<<7);
		UART1_Write('A');
		UART1_Write('T');
		UART1_Write('+');
		UART1_Write('C');
		UART1_Write('M');
		UART1_Write('G');
		UART1_Write('R');
		UART1_Write('=');
		UART1_Write('1');
		UART1_Write(13);
		Delay_ms(50);
		for(i=0;i<95;i++)
		{
			while (UART1_Data_Ready() != 1);
			Rxdata = UART1_Read();
			rx1[i] = Rxdata;
		}
		for(i=60;i<95;i++)
		{
			if(rx1[i]=='O' && rx1[i+1]=='N')
			{
				if(rx1[i+2]=='1')
				{
					PORTC = 0xFF;
				}
				if(rx1[i+2]=='2')
				{
					PORTC = 0x00;
				}
				if(rx1[i+2]=='3')
				{
					PORTC = 0x0f;
				}
				if(rx1[i+2]=='4')
				{
					PORTC = 0xf0;
				}

				UART1_Write('A');
				UART1_Write('T');
				UART1_Write('+');
				UART1_Write('C');
				UART1_Write('M');
				UART1_Write('G');
				UART1_Write('D');
				UART1_Write('=');
				UART1_Write('1');
				UART1_Write(13);
				Delay_ms(100);
				UART1_Write('A');
				UART1_Write('T');
				UART1_Write('+');
				UART1_Write('C');
				UART1_Write('M');
				UART1_Write('G');
				UART1_Write('D');
				UART1_Write('=');
				UART1_Write('1');
				UART1_Write(13);
				Delay_ms(100);
				SREG|=(1<<7);
			}
		}
	}
 }


void main()
{
	DDRC = 0xFF;
	PORTC = 0x00;

	UART1_Init(9600);               // Initialize UART module at 9600 bps
	UCSRB |= (1<<RXCIE);
	SREG|=(1<<7);                   //Enable Global Interrupt
	Delay_ms(100);

	UART1_Write('A');
	UART1_Write('T');
	UART1_Write(13);
	Delay_ms(200);
	UART1_Write('A');
	UART1_Write('T');
	UART1_Write('+');
	UART1_Write('C');
	UART1_Write('M');
	UART1_Write('G');
	UART1_Write('F');
	UART1_Write('=');
	UART1_Write('1');
	UART1_Write(13);
	Delay_ms(200);
	UART1_Write('A');
	UART1_Write('T');
	UART1_Write('e');
	UART1_Write('0');
	UART1_Write(13);
	Delay_ms(200);
	UART1_Write('A');
	UART1_Write('T');
	UART1_Write('+');
	UART1_Write('C');
	UART1_Write('N');
	UART1_Write('M');
	UART1_Write('I');
	UART1_Write('=');
	UART1_Write('1');
	UART1_Write(',');
	UART1_Write('1');
	UART1_Write(',');
	UART1_Write('0');
	UART1_Write(',');
	UART1_Write('0');
	UART1_Write(',');
	UART1_Write('0');
	UART1_Write(13);
	Delay_ms(50);
	UART1_Write('A');
	UART1_Write('T');
	UART1_Write('&');
	UART1_Write('W');
	UART1_Write(13);
	Delay_ms(50);
	UART1_Write('A');
	UART1_Write('T');
	UART1_Write('+');
	UART1_Write('C');
	UART1_Write('M');
	UART1_Write('G');
	UART1_Write('D');
	UART1_Write('=');
	UART1_Write('1');
	UART1_Write(13);
	Delay_ms(200);
	UART1_Write('A');
	UART1_Write('T');
	UART1_Write('+');
	UART1_Write('C');
	UART1_Write('M');
	UART1_Write('G');
	UART1_Write('D');
	UART1_Write('=');
	UART1_Write('1');
	UART1_Write(13);
	Delay_ms(200);

}
 

You have to use a 300 bytes buffer for UART and once the SMS is received (New SMS received notification). You have to issue AT+CMGR=x where x is SMS index. Then you have to extract the actual SMS and then use strcmp() to compare the received SMS with the messages stored in ROM.
 

Does this mean i have issue with only reading and parsing the sms ? remaining SREG values and initialization of interrupt is working correctly?
 

If you want me to test if ISR is working or not then zip and post the complete mikroC PRO AVR project files.
 

Can you please explain what is pooling delay?
Your way or coding is completly wrong. ISR should be performed as fast as possible. You only can read the input register, put the data to input buffer, increment index counter and possible start timeout timer. When buffer if fullfilled, the routine should report the error or switch to another buffer.
Pooling means you changing register value and waiting for the flag, like 'data send'. This are you doing in UART1_Write function.
If you don't care about time needed to send data, you can use UART1_Write in main loop, but not in ISR! I suppose, this compilier should show you a warning if you try to put UART1_Write in ISR.
 

If you want me to test if ISR is working or not then zip and post the complete mikroC PRO AVR project files.

Ok there is only a single c file which i am posting. This shown code was just reduced to simplify. I am attaching the full code, here i am taking values from ADC and showing on LCD at PORTB. Then sending SMS to a particular number on crossing thresholds. Interrupts receives SMS and toggling PORTC accordingly..

View attachment code.zip
 

I have to debug and test if ISR is working. If you want me to test then zip and post the complete mikroC PRO AVR project files.
 

Ok guys now i was successful in reading the SMS. Now problem is when i am sending sms from AVR. The control comes inside the interrupt. how can we disable interrupt when sending sms and enable again after transmit is complete
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top