|
|
View previous topic :: View next topic |
Author |
Message |
otavio_fisica
Joined: 20 Jul 2006 Posts: 29
|
Problem with serial communication between 18F4550 and 16F689 |
Posted: Mon Sep 17, 2007 7:46 pm |
|
|
Hello people.
Here I come with a problem related to the RS232 communication between PIC18F4550 and PIC16F689. The 16F689 keeps sending data to the 18F4550 which receives only. The problem is that sometimes the 18F4550 stops receiving data. Some other times, it just does not initiate getting the data.
The piece of code for the 16F689 is the following:
Code: | #FUSES NOWDT
#FUSES XT
#FUSES NOPROTECT
#FUSES NOBROWNOUT
#FUSES NOMCLR
#FUSES NOCPD
#FUSES NOPUT
#FUSES NOIESO
#FUSES NOFCMEN
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B7,rcv=PIN_B5,bits=8,stream=sensor)
int saidera;
void main()
{
setup_adc_ports(sAN4|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(4);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
delay_us(50);
while(true){
saidera++;
delay_ms(100);
putc(saidera);
}} |
The piece of code for the 18F4550 is the following. I've put the commas here just for it to be easy to understand. Note that I use the USB function from the 18F4550.
Code: | #FUSES NOWDT; #FUSES WDT128; #FUSES NOPROTECT; #FUSES BROWNOUT_NOSL ; #FUSES NOBROWNOUT ; #FUSES BORV20 ; #FUSES NOPUT;#FUSES NOCPD ;#FUSES NOSTVREN ;#FUSES NODEBUG ;#FUSES NOLVP;#FUSES NOWRT;#FUSES NOWRTD ;#FUSES NOIESO; #FUSES NOFCMEN ;#FUSES NOPBADEN ;#FUSES NOWRTC;#FUSES NOWRTB ;#FUSES NOEBTR ;#FUSES NOEBTRB ;#FUSES NOCPB ;#FUSES NOMCLR ;#FUSES NOLPT1OSC;#FUSES NOXINST;#FUSES PLL1 ; #fuses XTPLL,CPUDIV1; #fuses USBDIV; #fuses VREGEN;
#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=sensor)
#use i2c(Master,Fast,sda=PIN_B0,scl=PIN_B1)
int sens;
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_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_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_low_volt_detect(FALSE);
setup_oscillator(False);
lcd_init();
while (true){
if (kbhit(sensor)){
sens = getc(sensor);
printf(lcd_putc,"\f%3.1f",sens);
}
} |
I use the compiler version 4.013. Do you have any ideas of what may be happening that 18F4550 can't receive data correctly? I was first working in the same project with 18F2450 and it worked perfectly. Now, I've decided to change to 18F4550 and it is not working properly. The 16F689 is certainly sending data. I've verified with the PC. And the 18F4550 sometimes receives from the PC (in these times, it also receives from the 16F689), but sometimes it does not receive data from the PC too.
Sometimes it happens that when I turn on the system, the 18F4550 receives a first data, shows it in the display and then stops receiving... What's the problem??
Any contribution will certainly be appreciated.
I also wanted to know if someone knows how to send float numbers via serial RS232.
Thanks a lot! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 17, 2007 8:17 pm |
|
|
Quote: | #FUSES NOWDT; #FUSES WDT128; #FUSES NOPROTECT; #FUSES BROWNOUT_NOSL ; #FUSES NOBROWNOUT ; #FUSES BORV20 ; #FUSES NOPUT;#FUSES NOCPD ;#FUSES NOSTVREN ;#FUSES NODEBUG ;#FUSES NOLVP;#FUSES NOWRT;#FUSES NOWRTD ;#FUSES NOIESO; #FUSES NOFCMEN ;#FUSES NOPBADEN ;#FUSES NOWRTC;#FUSES NOWRTB ;#FUSES NOEBTR ;#FUSES NOEBTRB ;#FUSES NOCPB ;#FUSES NOMCLR ;#FUSES NOLPT1OSC;#FUSES NOXINST;#FUSES PLL1 ; #fuses XTPLL,CPUDIV1; #fuses USBDIV; #fuses VREGEN; |
This code doesn't compile for me. The CCS manual doesn't show a
semi-colon at the end of the #fuses statement. I don't think this is
your real code. |
|
|
otavio_fisica
Joined: 20 Jul 2006 Posts: 29
|
|
Posted: Mon Sep 17, 2007 8:28 pm |
|
|
I told in the text that I've put the semi-colons just to make the code easier to be read here in the post... sorry. I did not know I couldn't do that... I'll put that fuses here, the way they are in the compiler.
Code: | #FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT_NOSL //Brownout enabled during operation, disabled during SLEEP
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOLPT1OSC //Timer1 configured for higher power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1 //No PLL PreScaler
#fuses XTPLL,CPUDIV1
#fuses USBDIV
#fuses VREGEN
#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=sensor)
#use i2c(Master,Fast,sda=PIN_B0,scl=PIN_B1) |
Sorry about that. I thought it would be easier. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 17, 2007 9:10 pm |
|
|
Before doing anything else, add the ERRORS directive to both #use rs232
statements. |
|
|
otavio_fisica
Joined: 20 Jul 2006 Posts: 29
|
|
Posted: Tue Sep 18, 2007 9:55 am |
|
|
Well, that solved the problem!!! But why? What was happening?
And about sending a float number through RS232, do you have any ideas?
Thanks a lot!!! |
|
|
|
|
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
|