View previous topic :: View next topic |
Author |
Message |
peterl
Joined: 09 Oct 2009 Posts: 13 Location: SF,BG
|
PIC16F88 UART |
Posted: Fri Dec 25, 2009 3:53 am |
|
|
Hi,
I have a problem with configuration of UART on pic16f88. This is my code:
Code: |
#include <16F88.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Resistor/Capacitor Osc with CLKOUT
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES BROWNOUT //Reset when brownout detected
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES IESO //Internal External Switch Over mode enabled
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8)
#include "C:\Users\ILS\Desktop\GSM Dialer\main.h"
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
for(;;)
{
printf("ATD+359XXXXX");
delay_ms(20000);
}
}
|
I have simulated code in proteus and it works. I make the PCB and it
does not work. I measured with oscilloscope and there wasn't a signal on
the output(PIN 11). Where is my mistake?
Thank's |
|
|
Ttelmah Guest
|
|
Posted: Fri Dec 25, 2009 5:40 am |
|
|
Probably the oscillator is not running.
XT=4MHz max.....
Best Wishes |
|
|
peterl+ Guest
|
pic16f88 UART |
Posted: Fri Dec 25, 2009 7:25 am |
|
|
I measured PIN15/16 with oscilloscope and I saw that oscillator work. |
|
|
Ttelmah Guest
|
|
Posted: Fri Dec 25, 2009 10:37 am |
|
|
Correct it anyway. The 'odds' are that it will be running at a lower frequency 'undertone', rather than at the 20MHz harmonic that it should be on.
What compiler version?.
A search here will find previous threads, where some versions don't initialise the UART properly. However this should be visible in the simulation. Unfortunately, Proteus, is not as accurate at spotting such things as MPLAB, so might well work, with it setup incorrectly....
Best Wishes |
|
|
peterl+ Guest
|
PIC16F88 UART |
Posted: Fri Dec 25, 2009 12:05 pm |
|
|
Ok, I will make it 4 MHZ. Compiler version is 4.084. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 25, 2009 12:23 pm |
|
|
Quote: | void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
|
Get rid of all this Wizard code. You don't need any of it, and in fact,
the line in bold is setting the TRIS on pin B2 to be an output pin,
which is the opposite of what you need for the UART Rx pin.
Delete all those lines above.
This is wrong. If pin B3 goes high, the PIC will lock up. Change it to
NOLVP. Proteus probably ignores this feature, but in a real hardware
design, you will see the problem.
Quote: | I measured PIN15/16 with oscilloscope and I saw that oscillator work |
It doesn't matter if it "works". The vast majority of the time, it will not
work when you use XT with a 20 MHz crystal. Always use HS with 20 MHz.
Also, make sure you have the correct capacitors in the crystal circuit.
A commonly used value is 22 pf. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Dec 25, 2009 12:51 pm |
|
|
not to pile on here BUT:
you were using NOPUT - with a crystal - not an X-O
i don't thinks that i so swift w/ HS xtals !!
try fuse: PUT instead !!
i have a design that uses 18.432Mhz for precise baud division -
with older 16Cxxx PICs in particular
- i have found that above 12MHZ - generally I get best startup ( observed on CLKOUT with SCOPE ) on many different designs with pashing caps as low as 15 -18pf & YES HS setting ONLY
i typically use 18Pf with 16F series
just a few PF can make a difference in how quickly the oscillator starts and settles
just my 2 cents |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 25, 2009 1:10 pm |
|
|
If you want to stock only one value, 22 pf works reliably with both 4 MHz
and 22 pf crystals. In some cases it might pull the crystal off frequency
very slightly, but in most applications that doesn't matter. |
|
|
peterl+ Guest
|
PIC16F88 UART |
Posted: Sat Dec 26, 2009 7:33 am |
|
|
Hi guys,
this is my repaired code:
Code: | #include <16F88.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //Resistor/Capacitor Osc with CLKOUT
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOLVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES IESO //Internal External Switch Over mode enabled
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8)
#include "C:\Users\ILS\Desktop\GSM Dialer\main.h"
void main()
{
for(;;)
{
printf("ATD+359XXXX");
delay_ms(1000);
}
}
|
But it's still not working :( I tried with #FUSES NOPUT and with #FUSES PUT but changes has no effect. I didn't replace crystal, because magazines not working today. The capacitors is 20pf. Now I will connect my dialer with RS232-TTL converter to see UART sending something,
Best regards. |
|
|
peterl+ Guest
|
PIC16F88 |
Posted: Sat Dec 26, 2009 7:51 am |
|
|
The PIC works, I saw my AT command on hyperterminal , but the problem actually is that the GSM not dial. |
|
|
Ttelmah Guest
|
|
Posted: Sat Dec 26, 2009 2:59 pm |
|
|
You need to put the modem into 'command mode'.
You have to remember that it'll quite probably have seen some garbage as the PIC wakes up, so will probably have switched to data mode.
The default for a modem is to wake up in command mode, but if you see _anything_ that is not a legitimate command it switches to data mode. Switching to command mode is triggered by sending:
Line Feed
Pause 1 second
+++
Pause 1 second
Try sending this at the start of your code, then the AT command
Remember also,once you have sent the AT command you should look for, and wait for the 'OK' reply. Only retry the AT command, if this is not seen.
Best Wishes |
|
|
peterl+ Guest
|
16F88 UART |
Posted: Thu Dec 31, 2009 8:13 am |
|
|
Sorry for stupid question, but what mean "Line Feed"? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Thu Dec 31, 2009 8:39 am |
|
|
It means an ASCII LF character.
The ASCII Chart here:
http://www.asciitable.com/ _________________ Google and Forum Search are some of your best tools!!!! |
|
|
|