View previous topic :: View next topic |
Author |
Message |
amit
Joined: 08 Mar 2014 Posts: 7 Location: India
|
pic 18f6722 uart |
Posted: Sat Apr 26, 2014 12:00 pm |
|
|
i am not able to run a simple uart program. I am using a max232 for level shifting and hardware is perfect, it works with pic18f452.
below is the code Code: | #include "serial.h"
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_spi2(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_low_volt_detect(FALSE);
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF);
// TODO: USER CODE!!
while(1)
{
printf("hello");
delay_ms(500);
}
} |
below is the header file Code: |
#include <18F6722.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC //Internal RC Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode enabled
#FUSES BBSIZ1K //1K words Boot Block size
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
|
can anyone please help me in correcting the code! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Sat Apr 26, 2014 12:09 pm |
|
|
Several faults/possible faults.
LVP.
Are you sure?. 99.9% of systems must have NOLVP. If LVP is selected (only is programming from a specific low voltage programmer), then you must have a resistor to ensure the programming line is held 'off' when you want to run.
setup_spi(SPI_SS_DISABLED);
No. Syntax is setup_spi(FALSE);
You are enabling both SPI ports, and turning off slave select. This is a common fault from setting things incorrectly in the wizard...
When using the hardware UART, you should (must...) always have 'ERRORS' in the #use RS232. Omitting this can hang the UART, unless _you_ add code to handle errors.
A search here will find a lot about this.
You are enabling MCLR. Have you got this pin pulled up?, |
|
![](templates/subSilver/images/spacer.gif) |
amit
Joined: 08 Mar 2014 Posts: 7 Location: India
|
|
Posted: Sat Apr 26, 2014 9:04 pm |
|
|
I have code similar to this for LCD and keypad. So the possible faults of LVP and MCLR does not apply to this.
Setup_spi(false) and errors also does not works. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Sun Apr 27, 2014 12:06 am |
|
|
Seriously, how are you programming the chip?.
LVP _will_ give problems unless LVP is being used, and unless you are using an LVP cable, then this should be off. The faults may well change with different hardware connected..... |
|
![](templates/subSilver/images/spacer.gif) |
amit
Joined: 08 Mar 2014 Posts: 7 Location: India
|
|
Posted: Sun Apr 27, 2014 1:19 am |
|
|
Ttelmah,
I tried setup_spi(FALSE) as suggested by you, the message hello appeared for 4-5 times and then no action. Also, this output does not repeat everytime I switch ON. I think there may be problem related to oscillator.
I also tried NOLVP. I am using pickit2 for programming. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Sun Apr 27, 2014 1:46 am |
|
|
You definitely want NOLVP then.
Are you sure your actual supply is stable?. Once the oscillator starts it is 'rare' for it to stop without external cause. Spike on supply, line on the chip being overloaded etc..
Now you say the hardware works with a 452, but this is a 40pin chip versus a 64/80 pin chip. So you can't actually be using the same hardware....
Generally you have to be much more careful about good grounding, to all the Vss pins on the chip, and good smooth supply to all the Vdd pins, with these larger chips. Good HF decoupling capacitors right adjacent to the chip's supply pins. |
|
![](templates/subSilver/images/spacer.gif) |
|