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

CAN-SPI Board with MCP2515

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



Joined: 09 Feb 2016
Posts: 53

View user's profile Send private message

CAN-SPI Board with MCP2515
PostPosted: Tue Feb 09, 2016 3:57 pm     Reply with quote

Hi all,

This is my first post here, I am new to Microcontrollers.. almost a month old I should say.

I was able to connect multiple PIC16F and my raspberry pi using I2c however i2c has the limitation of real estate hence I am trying CANBUS now

I would like to keep the cost down hence planning to use PIC16F73 and a canspi board. just like the one here



Has anybody done anything like this here before? I have been searching this forum for quite sometime now and could not find any posts related to this.

Can Somebody share some sample code so that I can understand what needs to be done.

Thanks in Advance.
_________________
Regards,
Devil
temtronic



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

View user's profile Send private message

PostPosted: Tue Feb 09, 2016 5:41 pm     Reply with quote

well the picture is nice BUT you should post a link to the product as well as any mfr/make/model numbers to help us help you.

the CAN bus has a huge overhead in terms of SW and some major pitfalls. Need to know how many sensors and distance you are thinking of having. RS-485 is quite easy,cheap, fast and good for distance.
There are other 'busses' or 'networks' that may work for you. Knowing more about your project will help.


Jay
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Tue Feb 09, 2016 6:05 pm     Reply with quote

CAN has a huge learning curve, particularly if you're a microcontroller virgin. A simple serial link would probably get you going quicker with less effort than CAN.
devilfrmheaven



Joined: 09 Feb 2016
Posts: 53

View user's profile Send private message

PostPosted: Tue Feb 09, 2016 11:37 pm     Reply with quote

Thanks for the response.

I am trying to reinvent the Air Conditioning system Smile by cleverly managing the ventilation system which will help me to cut my power bills.

I would like 3 temperature sensors SHT21 which is again cheap.. in 3 separate locations

1) Living room
2) Out doors
3) Basement

I would then compare the temperatures and open up the ventilation and a blower based on the coolest / warmest location.

I do not want to use wireless communications as it would become a nightmare to troubleshoot in case the system goes down.

I would like my raspberry pi to manage the entire system as programming a pi is much more simpler.

@jay - I found the hardware on Aliexpress for $1.7 ish, so I guess its a chinese manufacturing unit. The chips used are MCP2515 and TJA1050

http://www.aliexpress.com/item/MCP2515-CAN-Bus-Module-Board-TJA1050-Receiver-SPI-For-51-MCU-ARM-Controller-NEW/32574991834.html?spm=2114.01010208.3.2.E1piSu&ws_ab_test=searchweb201556_2,searchweb201644_4_505_506_503_504_301_502_10001_10002_10016_10017_10010_10005_10011_10006_10003_10004_10009_10008,searchweb201560_1,searchweb1451318400_-1,searchweb1451318411_6449&btsid=66fc5270-c7b5-4e98-99b6-1ecdf857e531


@newguy - I see that Canbus have a range of 1000 Meters @ 50kbits/sec. I guess that bandwidth and the range keeps me attracted. I also tried if I could use MODBUS, but again it requires much more advanced microcontroller than PIC16F73.
_________________
Regards,
Devil
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Wed Feb 10, 2016 4:01 am     Reply with quote

In all honesty, just use standard RS485 serial.

You are unlikely to be able to fit the code to operate a Can controller into a small PIC like the 16F73. There is a lot of work involved in this (probably more than a basic Modbus configuration). The advantage of Can, is that once configured, the controller does a lot of the work for you, so automatically identifying messages for you etc.. However this is complex to use, and I'd not want to try to fit this into such a small PIC.

Now if this is for your own project, then 'KISS', and just design your own simple protocol. Think about what you want, and what has to be sent. So you need to read three temperature sensors. Just have each with a simple RS485 interface, and have them all sit 'listening' on this. Then have a simple communication like:

T1<LF>

T2<LF>

etc..

Have the replies be equally simple. So something like
txnnnc<LF.

Using 't' lowercase for the reply, with 'x' being the sensor that is replying, then 'nnn' being the temperature in some suitable integer unit, and 'c' being a simple XOR checksum of all the bytes up to this point.

Your master can then just send a request and get a reply. If it doesn't get a reply in (say) a few seconds, it can ask again. If the checksum is wrong, it can again ask again. After say 10 failures it can alert that it is not getting the required data.

With standard RS485 transceivers, at low rates this can send miles. Reliable, and the code is relatively simple (most of the 'old hands' here could probably have this running in a couple of hours).
CCS has serial code for you, including the option of controlling a transceiver (so allowing a 2wire bus).

Something like this is hundreds of times simpler than either trying to push I2C for longer distances (I suspect this is what you are referring to by 'real estate'?), or use a complex bus/protocol like Can or Modbus.

The reason for more complex busses, is where there are a much larger number of devices, and much more complex commands/responses needed.
temtronic



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

View user's profile Send private message

PostPosted: Wed Feb 10, 2016 7:05 am     Reply with quote

I agree with second Mr T ! Use RS485 BUT use ethernet cable for the connections. That way you can suppy power and data on the wires. Use 2 conductors for each though( +pwr,+dta,-dta,gnd) that way you'll get good power and data to all the remote boards.
These days premade CAT cables are cheap AND you can color them to designate their location.

Be sure to run say +12 for the power and have local regulator to power the individual remotes. I used +24 and could go around noisey building for 1/4 mile.

Jay
devilfrmheaven



Joined: 09 Feb 2016
Posts: 53

View user's profile Send private message

Thank you!!
PostPosted: Mon Feb 15, 2016 4:38 am     Reply with quote

Thanks for responding Mr T and Temtronic..

I am sorry for the late response as I was on vacation Smile

@Temtronic,

Ethernet cables would be useful, but it would be really bulky to fit into the existing wiring panels. One of the reason I was planning to use CAN or MODBus was to reduce the wires required for communication.

I was planning to send 12V with a 4 coil wire and then use a regulator to get 5 Volt.
I would then use an SSR to activate the blower. KISS like Mr T
_________________
Regards,
Devil
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Feb 15, 2016 4:48 am     Reply with quote

The suggestion from Temtronic was to _reduce_ the wiring....

Don't get confused and think of Ethernet wiring as being Ethernet plugs etc..

He was talking about using T568 / 568AA cables to supply both signal and power.

All of the busses being talked about need cables. Canbus uses a twisted pair cable by default. Typically something like 3600X. Modbus RS485, normally uses a 6 core cable, and commonly uses T568A cable when power is included. You are going to need a known impedance twisted cable for the data, for any of these connections, and T568 is about the cheapest cable you can get, with enough pairs to include the power in the same wire.
temtronic



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

View user's profile Send private message

PostPosted: Mon Feb 15, 2016 6:46 am     Reply with quote

Actually using Ethernet will be less bulky, cheaper and easier. Consider that in addition to neding twisted pair to every 'slave' you also need power(another pair of wires) at each slave. Usually there isn't easy access to power where the air duct dampeners are. By using 'ethernet' cables and connections you get 4 pair and factory made connections. Now you could go 'analog' as I did for in my house with buffered LM34 as the slave sensors and a PIC as the host controller. It's been reliable for 2 decades. If you go 'digital' with PICs as slaves and host you must ensure clean signalling and RS485 through ethernet is proven technology.
Using 'off the shelf' cabling and connectors also allows you to color code remotes and quick replacing of faulty slaves. Pop off one connector, done! NO screw terminals, miswiring, lost screws, etc.
Supplying power in the same cable (aka POE or Power Over the Ethernet) allows for a common power supply (at the host location) which reduces wiring and fault finding.
In my remote energy systems I'd pull up to 1000 meters of cable through a plant and feed all the slaves from one 'host' power supply. Needed 24 volts due to line loss but system has been 100% reliable for 30 years.

RS485 with enet cable is probably the best way to go though I should point out that it all can be done on a single conductor if you want to be different than the rest of the crowd.

I tend to look at projects from a reliabilty aspect. What is needed to be done to NOT get phone calls at 3AM complaining about 'no heat'!

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Feb 15, 2016 8:03 am     Reply with quote

I think he is talking about having quite a heavy power wire, which might be why he is 'anti' the Ethernet wiring solution?.
temtronic



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

View user's profile Send private message

PostPosted: Mon Feb 15, 2016 8:46 am     Reply with quote

hmm we need more information that's for sure! Especially the servos that will control air flow. I've seen 4by10 register 'timer - control' units for $5 that are powered by 4AA cells. They could be PICked/ Blutoothed fairly easily.

I prefer the hardwired approach for reliablilty though.

Jay
ezflyr



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

View user's profile Send private message

PostPosted: Mon Feb 15, 2016 12:04 pm     Reply with quote

Hi,

Call me a cynic, but I'm highly dubious that this project/issue has anything at all to do with CCS 'C'!

I think the OP needs to find a general purpose electronics forum!

John
_________________
John

If it's worth doing, it's worth doing in real hardware!
devilfrmheaven



Joined: 09 Feb 2016
Posts: 53

View user's profile Send private message

Thank you gurus
PostPosted: Wed Jun 01, 2016 10:07 am     Reply with quote

Thank you all for helping out and YES! now i think this thread that I started never contained anything about CCS C!

You guys and this forum helped me learn a lot of things about microcontrollers and CCS C.

Ttelmah -
temtronic - Jay
ezflyr - John

You guys are really great!!! and helped me a lot!!!
I started studying more on Microcontrollers, I am trying to implement what I mentioned in this thread with UART over RS485 in CCS C Smile

There are a lot of helpful threads here that helped me out.

Again I understand that this post is really really late, but I would like to thank you all for helping me out.. this is a really great place.
_________________
Regards,
Devil
ezflyr



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

View user's profile Send private message

Re: Thank you gurus
PostPosted: Thu Jun 02, 2016 3:58 am     Reply with quote

devilfrmheaven wrote:
YES! now i think this thread that I started never contained anything about CCS C!


Dude, I can smell a 'forum miscreant' a mile away! Cool

But, nice try anyway! Razz
_________________
John

If it's worth doing, it's worth doing in real hardware!
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