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 anyone help me about CAN BUS

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







Can anyone help me about CAN BUS
PostPosted: Sat Apr 05, 2003 1:40 am     Reply with quote

Hi,
can anyone help me about can bus in 18F458 ???
I have just download the library 18XXX8.c and 18XXX8.h.
I make two board :

in tx board transmit ADC value

in rx board receive :

id correct
len correct
data incorrect

If I assign the adc value at id value, RX board receive adc value in id.

Thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 13436
Eric Girard
Guest







Re: Can anyone help me about CAN BUS
PostPosted: Sat Apr 05, 2003 12:04 pm     Reply with quote

I'm not sure if I understood your problem but I used this library in the past and here is quick list of things I remember

- RTR packet CANNOT transfer data

-to send a message with a 16 bit variable name ADC_Value :


CanSendMessage(11 or 32 bits ID,&ADC_Value,2,CAN_TX_STD_FRAME & CAN_TX_NO_RTR_FRAME & CAN_TX_PRIORITY_0);

Note that the flag are ANDED together and you need to send a pointer to the function, not the data itself

- To receive the message :
Assume you have a 8 byte buffer (unsigned char Buffer[8])
Assume unsigned char DataLen will hold the # of byte in the message
Assume unsigned int Flags will hold status of received packet
CanReceiveMessage(&[32 bit var],&Buffer[0],&DataLen,&Flags)

-Use flag & CAN_RX_xxx constant to find how type of packet etc.
CAN_RX_STD_FRAME - 11 bit ID
CAN_RX_EXT_FRAME - 29 bit ID
CAN_RX_RTR_FRAME - RTR frame (NO DATA)
CAN_RX_INV_FRAME - Invalid frame
CAN_RX_OVF_FRAME - Overflow (you missed a message)
(please check to make sure the spelling is OK...)


I have written a CANOpen library and I am using the CAN18xx8.c lib to access the CAN bus. I did not have any problem running it on the PIC18F258

Eric Girard

:=Hi,
:=can anyone help me about can bus in 18F458 ???
:=I have just download the library 18XXX8.c and 18XXX8.h.
:=I make two board :
:=
:=in tx board transmit ADC value
:=
:=in rx board receive :
:=
:= id correct
:= len correct
:= data incorrect
:=
:=If I assign the adc value at id value, RX board receive adc value in id.
:=
:=Thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 13444
Mirko
Guest







Re: Can anyone help me about CAN BUS
PostPosted: Mon Apr 07, 2003 8:44 am     Reply with quote

I finded but I haven't nothing.
ID is correct
Len is correct

data is all the same value. Have you a new idea.
Thanks

******************************************
TX PROGRAM
******************************************
#include <18F458.h>
#use delay(clock=4000000)
#fuses XT,NOWDT,WDT1
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include <can18xx8.c>

void main() {
//rx
int32 rx_id;
int in_data[8];
int rx_len;
int rx_flags;
//tx
int out_data[8];
int32 tx_id=25;
int1 tx_rtr=1;
int1 tx_ext=0;
int tx_len=2;
int tx_pri=3;
//******************
int i;

setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(FALSE);

for (i=0;i<8;i++) {
out_data[i]=0;
in_data[i]=0;
}
printf("\r\n\r\nCCS CAN EXAMPLE\r\n");

CanInitialize(0,0,1,1,1,CAN_CONFIG_DEFAULT);
set_adc_channel( 0 );
while(TRUE) {
if (CANIsTxReady()) { // tx
out_data[0] = Read_ADC();
CanSendMessage (tx_id,&out_data[0],tx_len,tx_pri & tx_ext & tx_rtr);
}
}
}

**********************************************
RX PROGRAM
**********************************************
#include <18F458.h>
#use delay(clock=4000000)
#fuses XT,NOWDT,WDT1
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include <can18xx8.c>

void main() {
//rx

struct rx_stat {
int1 err_ovfl;
int filthit:3;
int1 buffer;
int1 rtr;
int1 ext;
int1 inv;
};
struct rx_stat rxstat;
int32 rx_id;
int in_data[8];
int rx_len;
int rx_flags;

//tx
int out_data[8];
int32 tx_id=25;
int1 tx_rtr=1;
int1 tx_ext=0;
int tx_len=2;
int tx_pri=3;

//******************
int i;

setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(FALSE);

for (i=0;i<8;i++) {
out_data[i]=0;
in_data[i]=0;
}
printf("\r\n\r\nCCS CAN EXAMPLE\r\n");
CanInitialize(0,0,1,1,1,CAN_CONFIG_DEFAULT);

set_adc_channel( 0 );

while(TRUE) {
delay_ms (2000);
if (CANIsRxReady()) { // rx
CanReceiveMessage(&rx_id,&in_data[0],&rx_len,&rx_flags);
printf("\r\n RX ID : \%lu RX LEN : \%u RX FLAGS : \%u",rx_id,rx_len,rx_flags);
printf("\r\n");
for (i=0;i printf(" \%X ",in_data[i]);
}
printf("\r\n");
}
}
}

*********************************************
:=I'm not sure if I understood your problem but I used this library in the past and here is quick list of things I remember
:=
:=- RTR packet CANNOT transfer data
:=
:=-to send a message with a 16 bit variable name ADC_Value :
:=
:=
:= CanSendMessage(11 or 32 bits ID,&ADC_Value,2,CAN_TX_STD_FRAME & CAN_TX_NO_RTR_FRAME & CAN_TX_PRIORITY_0);
:=
:= Note that the flag are ANDED together and you need to send a pointer to the function, not the data itself
:=
:=- To receive the message :
:= Assume you have a 8 byte buffer (unsigned char Buffer[8])
:= Assume unsigned char DataLen will hold the # of byte in the message
:= Assume unsigned int Flags will hold status of received packet
:= CanReceiveMessage(&[32 bit var],&Buffer[0],&DataLen,&Flags)
:=
:= -Use flag & CAN_RX_xxx constant to find how type of packet etc.
:= CAN_RX_STD_FRAME - 11 bit ID
:= CAN_RX_EXT_FRAME - 29 bit ID
:= CAN_RX_RTR_FRAME - RTR frame (NO DATA)
:= CAN_RX_INV_FRAME - Invalid frame
:= CAN_RX_OVF_FRAME - Overflow (you missed a message)
:= (please check to make sure the spelling is OK...)
:=
:=
:=I have written a CANOpen library and I am using the CAN18xx8.c lib to access the CAN bus. I did not have any problem running it on the PIC18F258
:=
:=Eric Girard
___________________________
This message was ported from CCS's old forum
Original Post ID: 13462
Mirko
Guest







Example to use can bus with 18f458
PostPosted: Tue Apr 08, 2003 10:17 am     Reply with quote

OK I resolve my problem Thenk you a lot.
If anyone interessed I write after the example :

by Mirko
*********************************************************
#include <18F458.h>
#use delay(clock=4000000)
#fuses XT,NOWDT,WDT1
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include <can18xx8.c>


void main() {
//rx
int32 rx_id;
int in_data[8];
int rx_len;
int rx_flags;

//tx
int out_data[8];
int32 tx_id=25;
int1 tx_rtr=1;
int1 tx_ext=0;
int tx_len=1;
int tx_pri=3;

//******************
int i;
int tx_app;
int rx_app;

setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(FALSE);


for (i=0;i<8;i++) {
out_data[i]=0;
in_data[i]=0;
}
printf("\r\n\r\nCCS CAN EXAMPLE\r\n");
CanInitialize(0,64,4,4,4,CAN_CONFIG_DEFAULT);

set_adc_channel( 0 );


while(TRUE) {

if (CANIsTxReady()) { // tx
out_data[0]=READ_adc();
CanSendMessage (tx_id,&out_data[0],tx_len,CAN_TX_STD_FRAME & CAN_TX_NO_RTR_FRAME & CAN_TX_PRIORITY_0);
}

delay_ms (2000);
if (CANIsRxReady()) { // rx
CanReceiveMessage(&rx_id,&in_data[0],&rx_len,&rx_flags);
printf("\r\n RX ID : \%lu RX LEN : \%u RX FLAGS : \%u",rx_id,rx_len,rx_flags);
printf("\r\n");
for (i=0;i printf(" \%X ",in_data[i]);
}
printf("\r\n");
}

}

}

**********************************************************


:=I'm not sure if I understood your problem but I used this library in the past and here is quick list of things I remember
:=
:=- RTR packet CANNOT transfer data
:=
:=-to send a message with a 16 bit variable name ADC_Value :
:=
:=
:= CanSendMessage(11 or 32 bits ID,&ADC_Value,2,CAN_TX_STD_FRAME & CAN_TX_NO_RTR_FRAME & CAN_TX_PRIORITY_0);
:=
:= Note that the flag are ANDED together and you need to send a pointer to the function, not the data itself
:=
:=- To receive the message :
:= Assume you have a 8 byte buffer (unsigned char Buffer[8])
:= Assume unsigned char DataLen will hold the # of byte in the message
:= Assume unsigned int Flags will hold status of received packet
:= CanReceiveMessage(&[32 bit var],&Buffer[0],&DataLen,&Flags)
:=
:= -Use flag & CAN_RX_xxx constant to find how type of packet etc.
:= CAN_RX_STD_FRAME - 11 bit ID
:= CAN_RX_EXT_FRAME - 29 bit ID
:= CAN_RX_RTR_FRAME - RTR frame (NO DATA)
:= CAN_RX_INV_FRAME - Invalid frame
:= CAN_RX_OVF_FRAME - Overflow (you missed a message)
:= (please check to make sure the spelling is OK...)
:=
:=
:=I have written a CANOpen library and I am using the CAN18xx8.c lib to access the CAN bus. I did not have any problem running it on the PIC18F258
:=
:=Eric Girard
:=
:=:=Hi,
:=:=can anyone help me about can bus in 18F458 ???
:=:=I have just download the library 18XXX8.c and 18XXX8.h.
:=:=I make two board :
:=:=
:=:=in tx board transmit ADC value
:=:=
:=:=in rx board receive :
:=:=
:=:= id correct
:=:= len correct
:=:= data incorrect
:=:=


:=:=If I assign the adc value at id value, RX board receive adc value in id.
:=:=
:=:=Thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 13501
MoofCba



Joined: 08 Mar 2004
Posts: 4

View user's profile Send private message

Re: Example to use can bus with 18f458
PostPosted: Mon Mar 27, 2006 9:19 pm     Reply with quote

Can you share your CanOpen library?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 28, 2006 5:04 pm     Reply with quote

Look at AN945 from Microchip:
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en020605
ozzy
Guest







not for ccs
PostPosted: Wed Apr 16, 2008 7:12 am     Reply with quote

microchip's source not for ccs compiler. Should you share your canopen source?
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