View previous topic :: View next topic |
Author |
Message |
kingsalmon
Joined: 30 Jun 2009 Posts: 5
|
18F4550 Rs232 problem |
Posted: Mon Jul 06, 2009 10:23 am |
|
|
Hello!
I'm trying to use rs232 to communicate between 2 pics 18f4550.
The transmission is working fine, but the reception is not receiving anything.
I'm simulating it with Proteus.
Transmission:
Code: | #include "D:\PIC\Projetos em C\Rs232\transmissão\new_baud\baud_test.h"
char aux;
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
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(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);
while(TRUE)
{
printf("test");
delay_ms(1000);
}
}
|
Reception
Code: |
#include "D:\PIC\Projetos em C\Rs232\recepção\test_recep\teste_recep.h"
#include <stdlib.h>
#include <INPUT.C>
char a;
#int_RDA
void RDA_isr()
{
a = getc();
delay_ms(1000);
}
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
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);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
setup_low_volt_detect(FALSE);
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);
while(TRUE)
{
if(a == 't')
output_toggle(PIN_D7);
}
}
|
Can anyone help me?
Thanks |
|
|
mskala
Joined: 06 Mar 2007 Posts: 100 Location: Massachusetts, USA
|
|
Posted: Mon Jul 06, 2009 11:08 am |
|
|
Is your receiver going to get a character more than once per second?
Obviously yes. So, your main program will never have time to execute
anything. Putting any kind of delay in an interrupt service routine is a bad
idea except under special circumstances.
Also, in real life your receive buffer would overflow after 2 characters. |
|
|
kingsalmon
Joined: 30 Jun 2009 Posts: 5
|
|
Posted: Mon Jul 06, 2009 11:43 am |
|
|
I`ve changed the interruption handler as you said.
Unfortunately, still not working.
Receive
Code: | #include "D:\PIC\Projetos em C\Rs232\recepção\test_recep\teste_recep.h"
#include <stdlib.h>
#include <INPUT.C>
char a;
#int_RDA
void RDA_isr()
{
a = getc();
}
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
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);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
setup_low_volt_detect(FALSE);
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);
while(TRUE)
{
if(a == 't')
output_toggle(PIN_D7);
delay_ms(100);
}
} |
|
|
|
mskala
Joined: 06 Mar 2007 Posts: 100 Location: Massachusetts, USA
|
|
Posted: Mon Jul 06, 2009 12:09 pm |
|
|
Also, and I didn't look closely before, typically the way we set up the
TX and RX is through a #USE RS232( ) directive. I don't know how that
is handled in the simulator, but without something like that the hardware
UART will not work. Also this directive defines which pins are being used. |
|
|
kingsalmon
Joined: 30 Jun 2009 Posts: 5
|
|
Posted: Mon Jul 06, 2009 5:02 pm |
|
|
While creating the code I used the ccs' wizard. It puts the #use rs232 in the first included file:
Code: | #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) |
|
|
|
mskala
Joined: 06 Mar 2007 Posts: 100 Location: Massachusetts, USA
|
|
Posted: Mon Jul 06, 2009 6:11 pm |
|
|
If it puts the USE_RS232 in an included file, it's not clear where it sits
relative to the setup_oscillator. I'm pretty sure that the settings to get
the baud rate are determined from the oscillator speed at that point. If
you change the oscillator speed later, things may not work. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Mon Jul 06, 2009 6:36 pm |
|
|
Code: | setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF); |
arf? You have too many things OR'd together.
but besides that, just do a:
#use delay (INT=8M);
like the help file says:
//application will use the internal oscillator at 8MHz.
//compiler will set INTOSC_IO config bit, and set the internal
//oscillator to 8MHz.
#use delay(internal=8M)
and you should be good. (and the #use rs232 as the previous author suggested..)
or:
#use rs232 (UART1, baud=yourBitRate)
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 06, 2009 7:15 pm |
|
|
I don't think that will solve the problem. He's using Proteus. If he wants
help, he needs to post the Proteus schematic. |
|
|
kingsalmon
Joined: 30 Jun 2009 Posts: 5
|
|
Posted: Thu Jul 09, 2009 4:42 am |
|
|
After changing the #use rs232 to to main file, after the setup_oscillator I wrote the code on the pic and tested it on a real circuito.
The osciloscope showed that the RC6 is normally at a 0 level.
When the information is sent I could see some bits on the screen and then the pin returns to 0 level.
I guess the normal logic level of the RC6 is 1 before and after the sending, isn`t it?
------
The oscilloscope`s energy cable had no ground, after changing it the transmission pic worked fine.
Now the only trouble is the reception.
|
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Jul 09, 2009 10:47 am |
|
|
If you would please, post all of the relevant code?
You are asking questions about items that are in the "setup" of the PIC but are not included within your posts.
Also, consider backing off to "simple" where you write just enough test code to get your feature in question working..
Whenever I have issues, I get back to basics and tend to find something I'm missing -- OR -- I have code I can submit to CCS for review that is just enough for them to work on the problem. (don't send them 5,000 lines of code. send them 50 -- they'll appreciate it)
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE: |
Posted: Fri Jul 10, 2009 12:44 am |
|
|
You could wire up a simple project that uses a 18F4550, a MAX 232 IC, to test if the RS232 communication works... All you need is the above mentioned ICs, some wires and a DB 9 connector.
thanks
arunb |
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
Re: 18F4550 Rs232 problem |
Posted: Fri Jul 10, 2009 4:19 am |
|
|
kingsalmon wrote: |
I'm simulating it with Proteus.
|
Try it with actual hardware and the results. |
|
|
kingsalmon
Joined: 30 Jun 2009 Posts: 5
|
|
Posted: Tue Aug 11, 2009 11:07 am |
|
|
Hello again!
I finally got it working!
The problem was solved when I started using CCS v4.084.
I guess there was some problem in earlier versions and it was fixed.
The code was not modified.
Thanks for your help. |
|
|
|