CAN bus using PIC - Page 1
Forum section: electronics / general

author: Udayan Sinha
author_rank: Regular Contributor
timestamp: April 04, 2014, 06:20:56 am
content: I am trying to setup a CAN bus for simple communication between 2 PIC MCUs. One of them (PIC18F4550) is sending an ASCII character which is read by the other (PIC18F2550) & displayed via UART. I am not able to compile the code in MPLAB-X for the receiving PIC. It shows the following-CLEAN SUCCESSFUL (total time: 535ms)make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-confmake: Entering directory `E:/Microchip/PIC18F2550_C/PIC18F2550_C.X'make -f nbproject/Makefile-default.mk dist/default/production/PIC18F2550_C.X.production.hexmake: Entering directory `E:/Microchip/PIC18F2550_C/PIC18F2550_C.X'"E:\Microchip\XC\xc8\v1.21\bin\xc8.exe" --pass1 --chip=18F2550 -Q -G --double=32 --float=24 --emi=wordwrite --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,+hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -obuild/default/production/CAN_RX.p1 CAN_RX.c(908) exit status = 1CAN_RX.c:87: error: (314) ";" expectedCAN_RX.c:87: warning: (374) missing basic type; int assumedCAN_RX.c:87: error: (314) ";" expectedCAN_RX.c:87: warning: (374) missing basic type; int assumedCAN_RX.c:95: error: (314) ";" expectedCAN_RX.c:95: warning: (374) missing basic type; int assumedCAN_RX.c:95: error: (314) ";" expectedCAN_RX.c:95: warning: (374) missing basic type; int assumedCAN_RX.c:107: warning: (1385) variable "RC6" is deprecated (declared at E:\Microchip\XC\xc8\v1.21\include\pic18f2550.h:9266)CAN_RX.c:170: warning: (357) illegal conversion of integer to pointerCAN_RX.c:170: warning: (357) illegal conversion of integer to pointerCAN_RX.c:170: warning: (357) illegal conversion of integer to pointerCAN_RX.c:176: warning: (357) illegal conversion of integer to pointerCAN_RX.c:176: warning: (357) illegal conversion of integer to pointerCAN_RX.c:176: warning: (357) illegal conversion of integer to pointermake: *** [build/default/production/CAN_RX.p1] Error 1make: *** [.build-conf] Error 2make: *** [.build-impl] Error 2make: Leaving directory `E:/Microchip/PIC18F2550_C/PIC18F2550_C.X'make: Leaving directory `E:/Microchip/PIC18F2550_C/PIC18F2550_C.X'BUILD FAILED (exit value 2, total time: 4s)I am not able to understand the mistake I am making (I suspect that the CAN library functions are not receiving the input arguments in the desired data format but I can't figure out how to go around it)Code I used-[See attachment]

author: Lajon
author_rank: Contributor
timestamp: April 04, 2014, 08:43:07 pm
content: QuoteYou can't assign a value in the declaration of a union member, remove the =0 assignment.QuoteCAN2510DataRead expects 3 pointers, your msgID0, numbytes0 and rxdata0 are already pointers, so don't dereference them, i.e., the call should bemsg_stat=CAN2510DataRead(CAN2510_RXB0, msgID0, numbytes0, rxdata0);/Lars

author: Udayan Sinha
author_rank: Regular Contributor
timestamp: April 09, 2014, 05:23:49 pm
content: Quote from: Lajon on April 04, 2014, 08:43:07 pmDid as you said. Thanks a ton man. But if you don't mind, can you please explain the pointer problem? I haven't worked with pointers before much so I didn't understand the reason of error properly.

author: aroby
author_rank: Regular Contributor
timestamp: April 09, 2014, 08:20:03 pm
content: Quote from: Udayan Sinha on April 09, 2014, 05:23:49 pmIf the function accepts a pointer, you need to send it a pointer. Dereferencing a pointer means retrieving the value at the address contained in the pointer. So if numbytes0 is a pointer, when you say *numbytes0, you are referring to what it points to, not the pointer itself.

author: Udayan Sinha
author_rank: Regular Contributor
timestamp: April 10, 2014, 01:51:54 am
content: Quote from: aroby on April 09, 2014, 08:20:03 pmOkay that makes sense. And the union problem, it applies to structures as well?

author: jav
author_rank: Contributor
timestamp: April 10, 2014, 08:20:55 am
content: Quote from: Udayan Sinha on April 10, 2014, 01:51:54 amUnions/structs can be initialized this way:Code:union can2510_msg_ID_1{unsigned long msg_ID_1;unsigned char msg_ID_UART_compatible;}can_msg_ID_1 = { 0 };If you're using ANSI C99 (I don't know which C flavor your compiler uses) you can do:Code:union can2510_msg_ID_1{unsigned long msg_ID_1;unsigned char msg_ID_UART_compatible;}can_msg_ID_1 = { .msg_ID_1 = 0 };to select which members of the struct/union are initialized.

author: Udayan Sinha
author_rank: Regular Contributor
timestamp: April 10, 2014, 12:14:16 pm
content: Quote from: jav on April 10, 2014, 08:20:55 amOh...okay. Thanks