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

18F4550 Rs232 problem

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



Joined: 30 Jun 2009
Posts: 5

View user's profile Send private message

18F4550 Rs232 problem
PostPosted: Mon Jul 06, 2009 10:23 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 06, 2009 11:08 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 06, 2009 11:43 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 06, 2009 12:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 06, 2009 5:02 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 06, 2009 6:11 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 06, 2009 6:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 06, 2009 7:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 09, 2009 4:42 am     Reply with quote

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.
Smile
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Jul 09, 2009 10:47 am     Reply with quote

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

View user's profile Send private message Send e-mail

RE:
PostPosted: Fri Jul 10, 2009 12:44 am     Reply with quote

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

View user's profile Send private message

Re: 18F4550 Rs232 problem
PostPosted: Fri Jul 10, 2009 4:19 am     Reply with quote

kingsalmon wrote:

I'm simulating it with Proteus.

Try it with actual hardware and the results. Wink
kingsalmon



Joined: 30 Jun 2009
Posts: 5

View user's profile Send private message

PostPosted: Tue Aug 11, 2009 11:07 am     Reply with quote

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.
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