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

RS485 interrupt

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



Joined: 24 Apr 2016
Posts: 9

View user's profile Send private message

RS485 interrupt
PostPosted: Sun Apr 24, 2016 12:37 pm     Reply with quote

Hello!

I'm trying to RS485 communication between two PIC16F887 with a simple code. RS485 is necessary, because i'd like to use at least 10 slaves and long distances.

In first phase, i'm trying the code in virtual (yes... in isis), but something is wrong, because the hardware interrupt works once. The second, third etc. messages don't make rda interrupts in slave, so the incomming_rs485() function runs once in the beginning.

I'm using MAX487 ICs, resistors etc.

What is missing from the code? Thanks for help!

(Sorry for my English)

MASTER:
Code:

// MASTER

#include <16f887.h>

#fuses HS,NOMCLR,NOWDT,NOPROTECT,NOLVP,NODEBUG

#use delay(crystal=20000000)

#define RS485_ID 0x00

#define RS485_RX_ENABLE PIN_C2
#define RS485_ENABLE_PIN PIN_C2
#define RS485_USE_EXT_INT FALSE

#include <rs485.c>

int data[5] = {"hello"};

void main()
{
   rs485_init();
   while(true)
   {
      if (rs485_send_message(0x01, 5, data))
      {
            output_toggle(PIN_A0);
      }
      delay_ms(500);
   }
}


SLAVE:
Code:

// SLAVE

#include <16f887.h>

#fuses HS,NOMCLR,NOWDT,NOPROTECT,NOLVP,NODEBUG

#use delay(crystal=20000000)

#define RS485_ID 0x01

#define RS485_RX_ENABLE PIN_C2
#define RS485_ENABLE_PIN PIN_C2
#define RS485_USE_EXT_INT FALSE

#include <rs485.c>

unsigned int data[16];

void main()
{
   rs485_init();
   delay_ms(100);
   while(true)
   {
     
      if (rs485_get_message(data, false))
      {
         output_toggle(PIN_A0);
      }
   }
}
temtronic



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

View user's profile Send private message

PostPosted: Sun Apr 24, 2016 12:44 pm     Reply with quote

please..

Read PIC101 sticky.

We cannot help you with ISIS/proteus 'code' as it is busted, broken, full of faulty DRCs.....

Use real hardware and use the CCS examples (they both work !!).

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 24, 2016 2:09 pm     Reply with quote

Read this previous thread on how to make rs-485 work with CCS.
This is a 3-page thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=52757
Ttelmah



Joined: 11 Mar 2010
Posts: 19186

View user's profile Send private message

PostPosted: Mon Apr 25, 2016 2:05 am     Reply with quote

There is also the glaring problem with this declaration:

int data[5] = {"hello"};

The array is too small to hold what is being put into it.

A five character string _requires_ six characters of storage....
anemo



Joined: 24 Apr 2016
Posts: 9

View user's profile Send private message

RS485 interrupt
PostPosted: Mon Apr 25, 2016 7:32 am     Reply with quote

Hello!

Quote:
Use real hardware and use the CCS examples (they both work !!).


As I said, in the first phase, i'd like to try it in virtual, but i'll build this circuit for you, after i bought devices (soon).

Quote:
Read this previous thread on how to make rs-485 work with CCS.


I have already read it (before i posted) and my "circuit" is similar to that.

Quote:
The array is too small to hold what is being put into it.


Thanks, i fixed it, but the code is still not working. The slave's led doesn't blink.
temtronic



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

View user's profile Send private message

PostPosted: Mon Apr 25, 2016 3:47 pm     Reply with quote

You're basing 'it doesn't work' on a faulty 'simulation' program aka ISIS aka Proteus !
drolleman



Joined: 03 Feb 2011
Posts: 116

View user's profile Send private message

PostPosted: Mon Apr 25, 2016 6:57 pm     Reply with quote

Even for a first phase, simulators are not worth the time. You can chase bugs that real hardware will work with, and others that real hardware won't work with. Bottom line, experienced developers don't use simulators, it doesn't save time.
anemo



Joined: 24 Apr 2016
Posts: 9

View user's profile Send private message

reply
PostPosted: Sun May 01, 2016 7:00 pm     Reply with quote

Hello!

So, Today I built the real hardware:

https://drive.google.com/file/d/0B5gu1D-K_ShcTEpxTVByRWhlSDA/view?usp=sharing

And I have to apologize to you, because it works... I've already built some circuits with proteus, and they worked in real, unfortunately the simulator is wrong in this situation and I made a mistake because of it..

So.. sorry and thank you for showing the right way.
Ttelmah



Joined: 11 Mar 2010
Posts: 19186

View user's profile Send private message

PostPosted: Mon May 02, 2016 12:15 am     Reply with quote

Very Happy

You now know why there are so many posters here saying 'ignore what Proteus/Isis say'....

Generally, small very simple projects will work in Isis. However as things get more complex, the probabilities of it giving the right answer, 'shoot down'.
There are little errors in almost every Isis component in the PIC's.

I've got two demo projects, one shows a project that works perfectly in Isis, but can never work in the real world. The second shows a project that will not function in Isis, but works for real (you now have your own example of this....).

A few years ago (Okay, Isis was younger then), a company I worked for did a 'viability study', evaluating whether certain tools were worth paying the charges to keep up to date or not. The product that came _lowest_ on the list at the end of the study, was Isis. Basically they found that every microprocessor project where Isis was used, took longer to complete, than similar projects done without this tool....
Duh!.

We use Proteus as a PCB design tool, and still will use Isis for a few specific analog simulations, as being quicker than Spice to set up (it works well for these simulations), but when it comes to microprocessor sections, Isis is not used at all.
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