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

RS485 Communication - Error in Output -------SOLVED!!! THX!

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



Joined: 09 Oct 2007
Posts: 62

View user's profile Send private message

RS485 Communication - Error in Output -------SOLVED!!! THX!
PostPosted: Tue Feb 05, 2008 10:09 am     Reply with quote

I used the example in the "RS485 woes" thread to help establish communication from slave (PIC16F690) to master (Computer).
http://www.ccsinfo.com/forum/viewtopic.php?t=32232

Hardware used:
PCM 4.060--->PIC16F690--->MAX485--->ICD2--->Telebyte Model 245 Opto-Isolated Superverter (RS485 to RS232 converter)--->Windows XP PC Xenon CPU

There is communication between the PIC16F690 and PC. I'm using Comm Operator (a hyperterminal-like program) and set the output to hex.

It is suppoused to show:

12
Hello World!
12
Hello World!
12
Hello World!

In my case, it is showing:

9D 9B E5 EB 6F 35 27 27 21 BF 51 21 1B 27 37 BD E5 EB (HEX)

I do not understand why it comes out differently.
I notice that the output changes when the frequency is increased or decreased. It will even jump to another value for a second before it "stabilizes" on a certain value. Why does it do that? Thanks!

Code:
#include <16F690.h>
#device adc=10                                   //Configures the read_adc return size. 10 will return the full A/D reading of 10 bits.
//#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT
#fuses INTRC,NOWDT,NOPROTECT,BROWNOUT,NOMCLR,BROWNOUT,NOIESO,NOFCMEN,PUT
#use delay(clock=4000000)

#define Rx_In PIN_B5         // serial data receive pin
#define Tx_Out PIN_B7         // serial data transmit pin
#define Serial_Enable PIN_C1   // Serial data enable

#use rs232(baud=9600, xmit=Tx_Out, rcv=Rx_In, enable=Serial_Enable, ERRORS, stream=Network)


void Network_fputc(char c)
{
fputc(c, Network);
}

//===============================

void main() {

   while(1){
      delay_ms(1000);
      fputc('1', Network);
      fputc('2', Network);
      printf(Network_fputc, "\r\nHello World!\r\n");
   }




Last edited by ThomasC on Tue Feb 05, 2008 2:55 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 05, 2008 1:22 pm     Reply with quote

The data that you're getting is inverted and shifted left one bit position,
compared to the source data. I don't understand what you're doing,
but you've got a very long, complex chain of driver/inverters. I suspect
that you've got one un-necessary inversion in there somewhere.

Just as a test, add the FORCE_SW and INVERT parameters to your
#use rs232() statement. See if that fixes it.
ThomasC



Joined: 09 Oct 2007
Posts: 62

View user's profile Send private message

PostPosted: Tue Feb 05, 2008 2:17 pm     Reply with quote

I used the FORCE_SW and INVERT, and it fixed it.

The output is now:

12
Hello World!
12
Hello World!
12
Hello World!
12
Hello World!

I must have inverted the wires like you said and once I reversed the wires between the MAX485 and the Telebyte 245 and the output is correct even without using the FORCE_SW and INVERT.

I can't believe it was something this simple. It would would have taken me days to figure out that this was wrong.

I would like to not use all this hardware, but I thought the MAX485 was required for RS485 PIC communication? Then I thought the Telebyte Model 245 Opto-Isolated Superverter was required to hook up the MAX485 to the RS232 port on the PC? If there's a better way I'm open to suggestions. Thanks PCM Programmer.
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