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 support@ccsinfo.com

Send message through RS485

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



Joined: 14 May 2008
Posts: 13
Location: Germany

View user's profile Send private message

Send message through RS485
PostPosted: Tue Jun 10, 2008 3:59 am     Reply with quote

Hi,

I am trying to send data stream through UART, specifically through RS485. I wrote the following simple code, just to check how I can send data through RS485 is working:

Code:
#if defined(__PCH__)
#include <18F8520.h>
#fuses Hs,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#include <rs485.c>
#include <stdlib.h>

void main() {
char data[10]="123456789";
int *pointer;
pointer=&data[0];

rs485_init();  //Initialize RS485 Communication

while(1)
      {
      rs485_wait_for_bus(FALSE);
      rs485_send_message( 1, 9, pointer );
      delay_ms(100);
      }
}


In the rs485.c file I just modified the pins numbers:

Code:
#if (RS485_USE_EXT_INT==FALSE)
   #define RS485_RX_PIN       PIN_C7
   #define RS485_TX_PIN       PIN_C6
   #define RS485_ENABLE_PIN   PIN_C0   //controls DE pin.  low for RX, high for TX . //For our Kit//
   #define RS485_RX_ENABLE    PIN_C1   //controls RE pin.  should keep low.

   #use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=8, long_data, errors, stream=RS485)
   #use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=8, long_data, force_sw, multi_master, errors, stream=RS485_CD)


I connected the four pins from PORTC to a RS485 Tranceiver (circuit shown in the below link):
http://www.mikroe.com/pdf/rs485_board_schematic.pdf

I checked the output signal of the tranceiver (pin A & B) on an oscilloscope, and what I got is a clock signal (sinewave) of 4KHz frequency only.

I am not an experienced person, I would appreciate any comment or advise.

Thank you
_________________
Hakam B Saffour
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

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

RE:
PostPosted: Tue Jun 10, 2008 11:01 am     Reply with quote

Hi,

RS 485 defines only the electrical standard, you have to implement a protocol that sends RS 485 frames/packets and receives them.

You could start by sending some data like 'A' , 'C' etc. To check the transmission there must be a RS 485 converter connected to the serial port of the computer. You could then use hyperterminal (or some other better program) to receive the data (the receiver must be enabled for this, this is usually done by the RTS pin of the serial port).

thanks
arunb
hakam_saffour



Joined: 14 May 2008
Posts: 13
Location: Germany

View user's profile Send private message

PostPosted: Wed Jun 11, 2008 1:42 am     Reply with quote

Dear Arunb:

Thank you for your reply, actually I want to connect PIC to other controller (system) using RS485, but first I want to make sure that every thing is ok from the PIC side.

Is it ok if I checked the output signal on an oscilloscope?
Is there any thing wrong in my code?
Why am I getting the 4KHz clock signal?

If there is any mistake in my C code, please let me know!

Thank you
_________________
Hakam B Saffour
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

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

RE:
PostPosted: Wed Jun 11, 2008 11:07 am     Reply with quote

I am not sure if 4Khz is normal. There is nothing wrong with using an oscilloscope. You could use the scope to see what character is actually being sent by examining the pulses.

An easier way would be to use the converter and the PC. But with this method you can only determine if characters are being received.

Hope this helps..

arunb
Guest_7068
Guest







PostPosted: Sun Jun 15, 2008 3:10 pm     Reply with quote

At 9600 baud, you should see 1 byte transmitted in about 1ms. I am not sure what this 4Khz means.

Make sure the baud rate at the RX matches the one are the TX.
Make sure the other parameters like number of bit, parity etc match.
The transceiver should be taking care of the voltage requirements, so hopefully you should not need to probe too much with a scope.
Also make sure you are transmitting the packet correctly, if there is some checksum involved etc.
Ttelmah
Guest







PostPosted: Mon Jun 16, 2008 2:19 am     Reply with quote

Each bit at 9600bps, will happen in 1/9600th second. The highest 'frequency' that can occur in the output stream, is when you have alternate 1's and 0's, and will be at 4800Hz. Close to the 4KHz being mentioned.
I'd suspect this is what is being seen.

Best Wishes
hakam_saffour



Joined: 14 May 2008
Posts: 13
Location: Germany

View user's profile Send private message

PostPosted: Mon Jun 16, 2008 6:05 am     Reply with quote

Ttelmah, Guest_7068, and arunb thanks for your advise.

Appreciate your support

Best Regards'
_________________
Hakam B Saffour
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