hi guys i m testing CAN design example of mikroc pro extra board on my desiged board WITH PIC18F2580 AND MCP2551 but i m experiencing sort of problems in reading data but i m sure my connections of transceiver and controller are fine as according to schematics since i have transformed both transciever and controller on same pcb board b/s transciever i got were in soic package so i had no way other to design both on pcb so connections are right and fine same as program and as it is design example of mikroc pro i m actually unable to receive or in other way other node is unable to read the data, but there is however voltage on canh and canl pins, there is about more then 3 V on both canh and canl pins . but i get no result in portc pins connected to leds i m sure about my connections as well as the program oscillator frequency is same as of design example , timing bits are also same but i dont know why there is no data on portc pins but i have definetly some voltage on canh and canl pins , i have terminated bus with 120 ohm resistor the other program are working definetely fine on both boards i m sending schematics of my designed board, i have just attached 10 ohm resistor with rs pin5 of mcp2551 i m also attaching config settings for the program and schematics of both nodes as well as both programs.
node#2:
node 1 starts communication by sending some sort of data and node 2 receive that data and displays it on leds connected to portc pins , while node 2 increment received data and then sent it back to node 1 then node 1
displays it on leds connected to portc pins and then increments this data and send it back to node 2 so this process keep on continuing but i m unable to see any sort of data on portc pins.please tell what could be possible wrong things, what more i can try can timings settings are same as given in example program i have tried my own settings , i m using 7-8 cm long bus terminated with 120 ohm resistor, both boards are working on other programs i will also post pics of my actual project later.please have comments about my config settings for device.
Code:
node#1:
unsigned char Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags; // can flags
unsigned char Rx_Data_Len; // received data length in bytes
char RxTx_Data[8]; // can rx/tx data buffer
char Msg_Rcvd; // reception flag
const long ID_1st = 12, ID_2nd = 3; // node IDs
long Rx_ID;
void main() {
PORTC = 0; // clear PORTC
TRISC = 0; // set PORTC as output
Can_Init_Flags = 0; //
Can_Send_Flags = 0; // clear flags
Can_Rcv_Flags = 0; //
Can_Send_Flags = _CAN_TX_PRIORITY_0 & // form value to be used
_CAN_TX_XTD_FRAME & // with CANWrite
_CAN_TX_NO_RTR_FRAME;
Can_Init_Flags = _CAN_CONFIG_SAMPLE_THRICE & // form value to be used
_CAN_CONFIG_PHSEG2_PRG_ON & // with CANInit
_CAN_CONFIG_STD_MSG &
_CAN_CONFIG_DBL_BUFFER_ON &
_CAN_CONFIG_VALID_XTD_MSG &
_CAN_CONFIG_LINE_FILTER_OFF;
CANInitialize(1,3,3,3,1,Can_Init_Flags); // Initialize CAN module
CANSetOperationMode(_CAN_MODE_CONFIG,0xFF); // set CONFIGURATION mode
CANSetMask(_CAN_MASK_B1,-1,_CAN_CONFIG_XTD_MSG); // set all mask1 bits to ones
CANSetMask(_CAN_MASK_B2,-1,_CAN_CONFIG_XTD_MSG); // set all mask2 bits to ones
CANSetFilter(_CAN_FILTER_B2_F4,ID_2nd,_CAN_CONFIG_XTD_MSG);// set id of filter B2_F4 to 2nd node ID
CANSetOperationMode(_CAN_MODE_NORMAL,0xFF); // set NORMAL mode
RxTx_Data[0] = 9; // set initial data to be sent
CANWrite(ID_1st, RxTx_Data, 1, Can_Send_Flags); // send initial message
while(1) { // endless loop
Msg_Rcvd = CANRead(&Rx_ID , RxTx_Data , &Rx_Data_Len, &Can_Rcv_Flags); // receive message
if ((Rx_ID == ID_2nd) && Msg_Rcvd) { // if message received check id
PORTC = RxTx_Data[0]; // id correct, output data at PORTC
RxTx_Data[0]++ ; // increment received data
Delay_ms(10);
CANWrite(ID_1st, RxTx_Data, 1, Can_Send_Flags); // send incremented data back
}
}
}
Code:
unsigned char Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags; // can flags
unsigned char Rx_Data_Len; // received data length in bytes
char RxTx_Data[8]; // can rx/tx data buffer
char Msg_Rcvd; // reception flag
const long ID_1st = 12, ID_2nd = 3; // node IDs
long Rx_ID;
void main() {
PORTC = 0; // clear PORTC
TRISC = 0; // set PORTC as output
Can_Init_Flags = 0; //
Can_Send_Flags = 0; // clear flags
Can_Rcv_Flags = 0; //
Can_Send_Flags = _CAN_TX_PRIORITY_0 & // form value to be used
_CAN_TX_XTD_FRAME & // with CANWrite
_CAN_TX_NO_RTR_FRAME;
Can_Init_Flags = _CAN_CONFIG_SAMPLE_THRICE & // form value to be used
_CAN_CONFIG_PHSEG2_PRG_ON & // with CANInit
_CAN_CONFIG_STD_MSG &
_CAN_CONFIG_DBL_BUFFER_ON &
_CAN_CONFIG_VALID_XTD_MSG &
_CAN_CONFIG_LINE_FILTER_OFF;
CANInitialize(1,3,3,3,1,Can_Init_Flags); // initialize external CAN module
CANSetOperationMode(_CAN_MODE_CONFIG,0xFF); // set CONFIGURATION mode
CANSetMask(_CAN_MASK_B1,-1,_CAN_CONFIG_XTD_MSG); // set all mask1 bits to ones
CANSetMask(_CAN_MASK_B2,-1,_CAN_CONFIG_XTD_MSG); // set all mask2 bits to ones
CANSetFilter(_CAN_FILTER_B2_F3,ID_1st,_CAN_CONFIG_XTD_MSG);// set id of filter B2_F3 to 1st node ID
CANSetOperationMode(_CAN_MODE_NORMAL,0xFF); // set NORMAL mode
while (1) { // endless loop
Msg_Rcvd = CANRead(&Rx_ID , RxTx_Data , &Rx_Data_Len, &Can_Rcv_Flags); // receive message
if ((Rx_ID == ID_1st) && Msg_Rcvd) { // if message received check id
PORTC = RxTx_Data[0]; // id correct, output data at PORTC
RxTx_Data[0]++ ; // increment received data
CANWrite(ID_2nd, RxTx_Data, 1, Can_Send_Flags); // send incremented data back
}
}
}
displays it on leds connected to portc pins and then increments this data and send it back to node 2 so this process keep on continuing but i m unable to see any sort of data on portc pins.please tell what could be possible wrong things, what more i can try can timings settings are same as given in example program i have tried my own settings , i m using 7-8 cm long bus terminated with 120 ohm resistor, both boards are working on other programs i will also post pics of my actual project later.please have comments about my config settings for device.
Attachments
Last edited: