CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RS232 INT_RDA problem with PIC18f4550

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ajinkya.k



Joined: 09 Mar 2016
Posts: 2

View user's profile Send private message

RS232 INT_RDA problem with PIC18f4550
PostPosted: Wed Mar 09, 2016 7:57 pm     Reply with quote

My program
Code:

#include <18F4550.h>
#use delay(clock=8000000) // tell compiler what we intend to use
#fuses INTRC,  HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN,PUT
#BYTE OSCCON = 0xFd3
#BYTE RCREG = 0xFAE
#use rs232(baud=9600,xmit=PIN_C6,bits=8,rcv=PIN_C7)
    #define LCD_ENABLE_PIN  PIN_D3                                    ////
     #define LCD_RS_PIN      PIN_D1                                    ////
     #define LCD_RW_PIN      PIN_D2

#include<lcd.c>
int8 densityCount=0;

#int_EXT
EXT_isr(void)
{
delay_ms(100);
  densityCount++;
}

#int_EXT1
EXT1_isr(void)
{
delay_ms(100);
densityCount--;

}
#int_RDA
RDA_isr(void)
{
lcd_init();
lcd_putc("got");
delay_ms(100);     
}
 
 
char getID()
{
char c=getc();
//while(c!='\n')
lcd_putc(c);

/*

if((char)c=='0')
{
                printf("AT+CIPSEND=0,15\r\n");
                delay_ms(500);
                printf("<html>hi</html>\r\n");
                delay_ms(500);
                printf("AT+CIPCLOSE=0\r\n");
               
}           
 
 */
}


initESP()
{
 
   printf("AT+RST\r\n");delay_ms(2000);
   printf("AT+CWMODE=3\r\n");delay_ms(2000);
   printf("AT+CWSAP=\"st2\",\"123456789\",1,3\r\n");delay_ms(2000);
   printf("AT+CIPMUX=1\r\n");delay_ms(2000);
   printf("AT+CIPSERVER=1,8000\r\n");delay_ms(2000);
 
}

initInterrupts()
{
   enable_interrupts(PERIPH );                 //GIE=1
   enable_interrupts(INT_EXT_L2H );               //INTE=1
   enable_interrupts(INT_EXT1_L2H );               //INTE=1

}

void main()
{
char c;
OSCCON = 0x72;

lcd_init();
lcd_putc("Booting Wifi:st2");
lcd_gotoxy(1,2);
lcd_putc("Station 2");
initESP();

initInterrupts();
delay_ms(2000);
              //INTE=1)
     
while(1)
{
   enable_interrupts(INT_RDA);
//getID();
delay_ms(100);
lcd_init();
delay_ms(100);
    lcd_putc("Traffic: st2");
    // lcd_putc(getc());
lcd_gotoxy(1,2);
printf(lcd_putc,"%u",densityCount);
delay_ms(100);
}
   
}

Function to be done by this program: Counting traffic density from INT_EXT and INT_EXT.

Problem in program i am facing:
I am not able to get request to the RS232 reception, after ESP module (ESP8266, connected and initialised at hardware serial port). Hence can't respond to client request when i put 192.168.4.1:8000 at browser'
Please help'
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Mar 09, 2016 8:15 pm     Reply with quote

Some things that are critically wrong...
1) errors must be added to the uses rs232(.....) options
2) delays must NOT be in int_EXT
3) delays must NOT be in int_EXT1
4) delays must NOT be in int_RDA
5) prints must NOT be in int_RDA
6) lcd_init() only needs to be issued once in the program
7) have no idea why osccon=72h
8) potential hardware conflict assuming 5V PIC, 3V ESP module
9) #use delay issued before fuses

others may see more, but this is a start.

Jay
ajinkya.k



Joined: 09 Mar 2016
Posts: 2

View user's profile Send private message

After changes
PostPosted: Wed Mar 09, 2016 8:27 pm     Reply with quote

072 is used to boost internal oscillator.
Using delay is just to let go any blurry signal from IR sensor module.
Current situation:
Every time i reset the system and ESP get initialised, it show got on lcd.
I think it's reading the earlier command in register every time, hence giving INT_RDA call.

One more thing to add,..
PIC can call the int_rda but, it's not calling it when needed, to illustrate more:
When system get restart, it directly go to int rda.. not event looping in main.
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Thu Mar 10, 2016 2:05 am     Reply with quote

The delays will stop the INT_RDA from working.

Because you have these, the interrupts will be delayed in the 'main' code.

Data arrives during this time, interrupt does not occur. Another byte arrives, and the UART then gets locked up. Result no RS232.
Similarly, a second byte arrives while it is in the ISR, and again the UART will be locked.
Second problem, is that an interrupt _must_ always handle the physical event that the interrupt signifies. INT_RDA, says 'a byte is waiting to be read', so INT_RDA, _must_ read this byte. Because you don't, the interrupt can never exit. It tries to exit, and then is immediately called again, since there is still a byte waiting....

So:
1) Use a timer to do your IR pulse. Simply setup a timer giving a reasonable count rate, in the 'main', and then when you want the delay in the interrupt, set the timer to the value to timeout in 100mSec, clear it's interrupt, enable it's interrupt, and exit the current interrupt. When the timer interrupts, you know that 100mSec has passed.

2) Add 'ERRORS' to the #use RS232. This _must_ always be present when using the hardware UART, unless _you_ add error handling to your code. This will prevent the UART becoming hung.

3) Get rid of the delays in all interrupts - this includes removing the LCD routines from inside the interrupt.

4) you must read the UART in INT_RDA. So getc.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group