PDA

View Full Version : CAN communications with PICS



earltyso
- 25th November 2008, 21:08
Hello Pic Users,
It has been a long time since my last post/ question.
Could someone point me in the right direction.
Are dsPIC's the only pics that can communicate with CAN communication?
Has anyone attempted this with PBP?
How about 16F pics with CAN tranceivers?

Thanks,

rmteo
- 25th November 2008, 21:24
According to here, there are 64 PIC's with CAN modules (and not just dsPICs - PIC18s and PIC24s as well):
http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=8094&mid=14&lang=en&pageId=75

As for software, many choices are available - if you are not limiting yourself to PBP.

BigWumpus
- 26th November 2008, 20:54
I have solved a simple CAN-Readonly in PICBASIC on a 18F4585. You have to read a lot of datasheets and when the program is ready - it seems to be so easy...

earltyso
- 1st December 2008, 16:01
BIG WUMPUS,
Thanks for the success story.

I am doing the same basic thing, just need to be able to read a single can bus and decode data from it, then outputting data to LCD, leds, etc.
Later this year I will be moving back into C programming with dsPIC's to talk to multiple CAN modules. This will take time of coarse, but for now I would really like to see If I can use PBP to just decode the data from the can.

Can you provide any other places to begin researching, datasheets etc?
thanks,

BigWumpus
- 1st December 2008, 17:51
I have written this code:

Get it, look inside the datasheet of the CAN-Module and try to understand it.
There is some trouble about timing, then I configure the filters and registers.
In the main-program I poll the flags in order to see new data.


---

;================================================= =========================
;CAN-Interface steuern
;================================================= =========================
CAN_Init:
CANCON=%10010000:Repeat:Until (CANSTAT & %11100000)=%10000000;Configuration Mode einschalten
ECANCON=%01000000 ;Mode 1
RXFCON0=%00000000:RXFCON1=%00000000 ;alle 16 Filter:deaktiviert
MSEL0=%11111111:MSEL1=%11111111:MSEL2=%11111111:MS EL3=%11111111;alle 16 Filter:no mask
RXFBCON0=%00110010:RXFBCON1=%01010100:RXFBCON2=%01 110110;Filter 0-5 -> B0-B5
CIOCON=%00100000
select case CAN_Mode
case wMode_EuroTiger: ;Euro-Tiger
BRGCON1=%01000001:BRGCON2=%10110001:BRGCON3=%00000 101;BRP=0TQ,Sync=1TQ,Prop=2TQ,Phase1=7TQ,Phase2=6T Q,SJW=2TQ
;B0: EEC1 $0CF00400 Motordrehzahl
RXF0SIDH=%01100111:RXF0SIDL=%10001000:RXF0EIDH=%00 000100:RXF0EIDL=%00000000
;B1: EEC2 $0CF00300 Lastquotient
RXF1SIDH=%01100111:RXF1SIDL=%10001000:RXF1EIDH=%00 000011:RXF1EIDL=%00000000
;B2: Eng_Temp $18FEEE00 Temperaturen
RXF2SIDH=%11000111:RXF2SIDL=%11101010:RXF2EIDH=%11 101110:RXF2EIDL=%00000000
;B3: Inlet Conditions $18FEF600 Ladeduck
RXF3SIDH=%11000111:RXF3SIDL=%11101010:RXF3EIDH=%11 110110:RXF3EIDL=%00000000
RXFCON0=%00001111 ;Filter 0-3 aktiviert
End select

CAN_ON:
tCAN_Sleep=wInput ;CAN-Transmitter einschalten
CANCON=%01110000:Repeat:Until (CANSTAT & %11100000)=%01100000;Listen Mode einschalten
CAN_Clear=%00111111:CAN_Restart=%00111111 ;alle Buffer leeren und alle Timer neu starten
Return

CAN_OFF:
CANCON=%00110000:Repeat:Until (CANSTAT & %11100000)=%00100000;Disable Mode einschalten
CAN_Sleep=true:tCAN_Sleep=wOutput:Return ;CAN-Transmitter ausschalten
---

earltyso
- 2nd December 2008, 14:10
Thanks for the code example,
I will begin my research today on this.

earltyso
- 28th January 2009, 19:28
All,
A good friend suggested that I try CCS software and compiler for pic CAN BUS communication called "PCD". Not to be an advertiser of another companies product but the software is GREAT for CAN applications, lcds, glcd. PCD is alot more work than PBP (mostly because of the pure C syntax) but other than that they have alot of built in functions (similar to PBP) you can use.....

So far I have been able to recieved and send data between 4 nodes (uP's) at 125k baud. If you need/ want to use CAN communications I high suggest going with CCS. The software is 2-3 x PBP $ but well worth it especially because you can program all 8/16/24/dsPIC's on the list. They also have some great development boards and demo kits for all kinds of projects.

there ya have it....