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

PIC18F452 , 3.3Volt , EX_SISR.C, ESP8266

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



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

PIC18F452 , 3.3Volt , EX_SISR.C, ESP8266
PostPosted: Mon Jul 02, 2018 2:52 am     Reply with quote

Hai,

I've modified EX_SISR.C for communicating PIC18F452 with ESP8266 wifi module. Since this PIC can function with supply voltage 3.3V same as ESP8266, i've connect directly PIC TX pin to RX pin of ESP8266 and PIC RX pin to TX pin of ESP8266.

When PIC send "AT", wifi module will reply "OK", but the problem is the pic will wrongly display the buffer data. What is wrong with my code ? Please help me.

Code:

#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7)

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;

#int_rda
void serial_isr() {
   int t;

   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;           // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}

void main() {
delay_ms(5000); 
   enable_interrupts(int_rda);
   #if defined(__PCD__)
   enable_interrupts(intr_global);
   #else
   enable_interrupts(global);
   #endif

printf("AT\r\n");

   do {
      delay_ms(500);

      while(bkbhit)
        putc( bgetc() );
   } while (TRUE);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19516

View user's profile Send private message

PostPosted: Mon Jul 02, 2018 3:10 am     Reply with quote

Your PIC can not operate at 3.3v. Minimum supply voltage for the F452, is 4.2v. You need the 18LF452 to operate at 3.3v.
Your PIC is probably 'just working' but with parts not operating correctly....

Also add 'ERRORS' to your RS232 declaration. This is _required_ when using hardware RS232, unless you are adding your own error code. Without this the UART will become hung if more than 32 bytes arrive in your delay.
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

PostPosted: Mon Jul 02, 2018 4:25 am     Reply with quote

Hai Ttelmah,

I've checked the parts datasheet and it say that the operating voltage range (2.0V to 5.5V). I also test EX_SISR.C with 3.3v supply using this PIC18F452, and no problem. Why need signal 4.2v ?
temtronic



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

View user's profile Send private message

PostPosted: Mon Jul 02, 2018 4:56 am     Reply with quote

Mr. T is correct, I just checked the datysheet to confirm, that PIC has a MINIMUM of 4.2 volts for VDD. Please check chapter 22, Electrical Specs, see figure 22-1, it graphically shows the allowable operating VDD vs clock speed.
While your part may be operating now, it probably will fail doing some operations or using some other internal peripherals.
This is similar to 'overclocking' a PC motherboard. Sometimes you can get them to go faster but but they aren't designed to do so, and randomly fail.

also....

unless you have 2 compilers, get rid of the IF... in the ISR. Visually it cleans up your code, so you can concentrate on 'real' code making it easier to see possible typos or other errors.
Ttelmah



Joined: 11 Mar 2010
Posts: 19516

View user's profile Send private message

PostPosted: Mon Jul 02, 2018 7:16 am     Reply with quote

You need to check the version. The datasheet is for both the F, and the LF parts. The range you are quoting is not for your F part.

Electrical Characteristics Figure 22-1, gives the voltage range for the F part.
The table below 22-2, gives the range for the LF part.
In the parameter table. D001, you have one line for the LF part and one for the F part. The line for the F part gives 4.2v minimum, 5.5v max.

Also look at this thread:
<http://www.ccsinfo.com/forum/viewtopic.php?t=57204>

It actually turned out here that the chip wasn't running at the voltage the poster thought, but what is interesting is that the first part that went wrong, was the UART....

art wrote:
Hai Ttelmah,

I've checked the parts datasheet and it say that the operating voltage range (2.0V to 5.5V). I also test EX_SISR.C with 3.3v supply using this PIC18F452, and no problem. Why need signal 4.2v ?
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

PostPosted: Mon Jul 02, 2018 9:00 pm     Reply with quote

Hi Ttelmah, temtronic,

Thank you very much for your help, I add ERRORS to rs232 declaration and it works !!!

It seems that this PIC18F452 with "F" works fine with supply 3.3V, not as mention in the datasheet.
Ttelmah



Joined: 11 Mar 2010
Posts: 19516

View user's profile Send private message

PostPosted: Mon Jul 02, 2018 11:07 pm     Reply with quote

It is common for devices to work under their rated voltage. However you may well find it'll fail if the weather gets hot for example. Don't rely on it!.
Yes the UART being hung was the obvious fault in the code.
Glad it worked.
Ttelmah



Joined: 11 Mar 2010
Posts: 19516

View user's profile Send private message

PostPosted: Mon Jul 02, 2018 11:07 pm     Reply with quote

It is common for devices to work under their rated voltage. However you may well find it'll fail if the weather gets hot for example. Don't rely on it!.
Yes the UART being hung was the obvious fault in the code.
Glad it worked.
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

PostPosted: Fri Jul 13, 2018 11:00 pm     Reply with quote

Dear Ttlemah,


You were right.... once I expand the code, sometimes it is ok and sometimes not ok( no communication)....so finally I've change the PIC to PIC18LF452.
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