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

problem with rs232

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



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

problem with rs232
PostPosted: Tue Dec 31, 2013 1:42 am     Reply with quote

I'm using PIC18F2520, oscillator: Internal type 4Mhz, compiler: 4.114,
controlling LED's using RF transmitter and receiver.

Tx code:
Code:
#include "18F2520.h"
#fuses INTRC_IO
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6)

#define Button1   PIN_A1
#define Button2   PIN_A2

void main()
{
   while(1)
   {
      if(input(button1) == 0)
      {
         putc('a');
         delay_ms(1000);
      }
      if(input(button1) == 1)
      {
         putc('b');
         delay_ms(1000);
      }

      if(input(button2) == 0)
      {
         putc('c');
         delay_ms(1000);
      }

      if(input(button2) == 1)
      {
         putc('d');
         delay_ms(1000);
      }
   }
}


RX code:
Code:

#include "18F2520.h"
#fuses INTRC_IO
#use delay(clock = 4000000)
#use rs232(baud=9600, rcv=PIN_C7)

#define LED1   PIN_A4
#define LED2   PIN_A5

unsigned char value;

void main()
{
   while(1)
   {
      if(kbhit())
      {
         value = getc();
         delay_ms(1000);
      }
      
      if(value == 'a')
      {
         output_high(LED1);
      }      

      if(value == 'b')
      {
         output_low(LED1);
      }

      if(value == 'c')
      {
         output_high(LED2);
      }

      if(value == 'd')
      {
         output_low(LED2);
      }   
   }
}


When i press the button, LED is not glowing.. Please help
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Tue Dec 31, 2013 2:22 am     Reply with quote

Because you are only specifying one pin of the UART port, the compiler will say 'he is not using the UART', and switch to _software_ RS232 mode.

Now, software mode has no buffering. The test 'kbhit' with a software UART, just tests for the RX line being low _at the instant it is called_. Any characters arriving at any other time, are lost.

So first thing, specify both UART pins in the #USE RS232 statements, so the hardware UART is used.

Then have you actually verified that your buttons are seen?. How are they wired?. Pull up resistors on A1, and A2?. Have you also verified your LED's on the Rx chip work. Current limiting resistors?.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Dec 31, 2013 10:25 am     Reply with quote

Besides the #USE RS232 line I suggest that you break down your large project into smaller parts that you can test and proof to be working as expected.

For example, do you know for sure the LEDs on the receiver are working?
I think you will fined LED2 on the receiver not working.
PIN_A5 on the receiver is an analog input by default. See table 10-1 in the data sheet. You will have to disable the analog port and the comparator 2 output.

So there are more small tests you can do. For example test that both boards are running and at the expected speed by adding a LED that is blinking at 1 second intervals. A very simple test but one that fails more often than you would think.

Test the transmitter and receiver board apart. When you make a loop back test, i.e. the transmitted data is connected directly to the receiver on the same board, are you then receiving the same data as is being transmitted?

What happens when you connect the transmitter board and the receiver board directly, so without the RF circuits?

Perhaps you can think of more tests yourself. Start with something as simple as possible. When that works expand in small steps and proof every step is working.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 31, 2013 12:44 pm     Reply with quote

comment: as CK says, breakdown the project into smaller, provable parts. You don't tell us what RF modules you're using but the cheap 433MHz ones can be 'fun' to get up and running properly.

At the very least remove the RF modules and go 'direct' PIC to PIC to eliminate the RF units.You'll be able to quickly debug.

hth
jay
hemnath



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

PostPosted: Tue Dec 31, 2013 10:10 pm     Reply with quote

Thanks guys. I have debugged the code and it is working now.

Now I'm in my home. As i don't have 18F2520 now, and changed the controller to PIC18F4550 for testing, which i have it.

made a simple LED blinking test for 18F4550 controller.

On PIN_RA4, LED is not glowing. Why is it?
I have configured the pin as digital output. But still not working. Any help?
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Dec 31, 2013 10:50 pm     Reply with quote

Hi,

Have you consulted the datasheet? If you had, under the port I/O section you'd note that RA4 is an open-drain pin. That mean that this pin can only
Sink to GND, it cannot go 'hi', ie. source to Vdd.

Use another pin, or change your LED connection to be compatible.

John
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

PostPosted: Wed Jan 01, 2014 9:17 pm     Reply with quote

Hello,

i found this sometimes helps

ensure you have ..... setup_adc(ADC_OFF);

also its a bit strange, sometimes some pics dont like it when you do

setup_adc_ports (NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard

its wierd i know, but try commenting these out and turn your IO's to FAST

#use fastio(a)

and double check set_tris_a(0x00);

its a bit legacy but most of my code has this and ive never yet figured out why it works like this, "you just keep going, no matter how crazy it seems"

good luck
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