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 support@ccsinfo.com

reading both 29bit ID and 11bit ID on the Canbus

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



Joined: 18 Dec 2009
Posts: 2

View user's profile Send private message

reading both 29bit ID and 11bit ID on the Canbus
PostPosted: Mon Apr 14, 2014 5:47 am     Reply with quote

Hello every body,
I can send data 11 or 29 ID the canbus llink But I cant read data both of the 11 and 29 bit ID.
I woud like it Because I have got 2 sensor onthe canbus link. its one sensor 11 bit one snsor 29 bit.
if At the beginning of the code "#define CAN_USE_EXTENDED_ID FALSE"
Only read 11 bit ID.
if At the beginning of the code "#define CAN_USE_EXTENDED_ID TRUE"
Only read 29 bit ID.
Probably I can set the #include <can-18xxx8250kpbs.c>
Please Help me.
IDE Version 5.013
PCB Version 5.013
PCM Version 5.013
PCH Version 5.013
Code:
#include <18F458.h>
#fuses HS,NOPROTECT,NOLVP,NOWDT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define CAN_USE_EXTENDED_ID   FALSE
#define CAN_DO_DEBUG FALSE

#include <max7912a.c>
#include <max7912b.c>
#include <can-18xxx8250kpbs.c>
/////////////////////////////////////////////
#define id_valf_sag    0x18252500
#define id_valf_sol    0x102
#define sag_on_basinc_ID 0x185
#define sol_on_basinc_ID 0x186
#define sag_arka_basinc_ID 0x187
#define sol_arka_basinc_ID 0x188
/////////////////////////////////////////////
#define drc1  PIN_C5
#define drc5  PIN_C4
#define clk_595    PIN_D2
#define datax_595  PIN_D4
#define datay_595  PIN_D3
#define write_595  PIN_D5
#define zct245   0x18FA0250
#define derece1_aktif output_low(drc1)
#define derece5_aktif output_low(drc5)
#define derece1_pasif  output_high(drc1)
#define derece5_pasif  output_high(drc5)
#define basinc_sensorleri_start can_putd(0, &basinc_start[0], 2, 1, 0, 0)
#define sag_on_basinc_sens_bar   can_putd(0x605, &basinc_barset[0], 8, 1, 0, 0)
#define sol_on_basinc_sens_bar   can_putd(0x606, &basinc_barset[0], 8, 1, 0, 0)
#define sag_arka_basinc_sens_bar can_putd(0x607, &basinc_barset[0], 8, 1, 0, 0)
#define sol_arka_basinc_sens_bar can_putd(0x608, &basinc_barset[0], 8, 1, 0, 0)
//////////////////////////////////////////////////
//!int16 digitx[22]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int16 digitx[13]={0xffff, 0x7fff,0x3fff, 0x1fff, 0x0fff, 0x07ff, 0xffff, 0xff7f, 0xff3f, 0xff1f, 0xff0f, 0xff07};
int16 digity[13]={0xffff, 0xff7f, 0xff3f, 0xff1f, 0xff0f, 0xff07, 0xffff, 0x7fff,0x3fff, 0x1fff, 0x0fff, 0x07ff, };
int rakamlar[10]={126, 96, 91, 115, 101, 55, 63, 98, 127, 119};
int birler=0, onlar=0, yuzler=0, sayi=0, kalan=0;

char i=0,j=0;  // Karakter tipinde değişken tanımlaması yapılıyor
char tus=0; //Tuş takımı için
int16 ms;
unsigned long int bilgix=0;
unsigned long int bilgiy=0;
float xaci;
float yaci;
int ix=0;
int iy=0;
unsigned int16   bzr_sure=0, tus_toggle=0, tus_takip=0, for_tus=0;//max 4294967295
int hata_78=0;//key_pad ilk enerjilendiğinde şaşırmaması için 500. döngüden sonra can bus ı devreye alıyor.
int8 kerim[8];
int1 basinc_sens_ayari_yapildi=0;
int8 basinc_start[2]={1,0};
int8 basinc_stop[2]={2,0};
int8 basinc_barset[8]={0x22, 0x31, 0x61, 0x01, 0x00, 0x00, 0x4E, 0x03};// basınç değerini bar olarak alamak için ayar parametresi
int8 basinc_clctime[8]={0x22, 0x00, 0x18, 0x02, 0x64, 0x00, 0x00, 0x00};//Basınç sensörünün 100ms aralıkla göndermesi için ayar parametresi
int8 valf=0;
int default_led_derece=5;
int debdebe=1;

#int_timer2
void isr_timer2(void) {
   ms++; //keep a running timer that increments every milli-second
}
///////////////////////////////////////////////////////////////////////////////
void main() {
   struct rx_stat rxstat;
   int32 rx_id;
   unsigned int8 buffer[8];
   int rx_len;

   for(i=0;i<8;i++) {
      buffer[i]=0;
   }

   can_init();
   init7219a();
   init7219b();
While(1)
{
if ( can_kbhit() )
{
   if(can_getd(rx_id, &buffer[0], rx_len, rxstat))
   {
   
   if (rx_id == sol_arka_basinc_ID)
         {
            can_putd(sol_arka_basinc_ID, &buffer[0], 8, 1, 1, 0);
            if(buffer[0]<10){sayi=1;birler=buffer[0];}
            if(buffer[0]<100 && buffer[0]>9){sayi=2;onlar=buffer[0];}
            if(buffer[0]<500 && buffer[0]>99){sayi=3;yuzler=buffer[0];}
            switch(sayi)
            {
               case 1:write7219a(4,rakamlar[birler]);write7219a(3,rakamlar[0]);write7219a(2,rakamlar[0]);write7219a(1,79);
               break;
               case 2:birler=onlar%10; onlar=onlar/10;
                      write7219a(4,rakamlar[birler]);write7219a(3,rakamlar[onlar]);write7219a(2,rakamlar[0]);write7219a(1,79);
               break;
               case 3:onlar=yuzler%100; birler=onlar%10; onlar=onlar/10; yuzler=yuzler/100;
                      write7219a(4,rakamlar[birler]);write7219a(3,rakamlar[onlar]);write7219a(2,rakamlar[yuzler]);write7219a(1,79);
               break;
               
               default:write7219a(4,rakamlar[0]);write7219a(3,rakamlar[0]);write7219a(2,rakamlar[0]);write7219a(1,79);
               break;
   
            }       
         }
   if (rx_id == zct245)
      { 
         can_putd(0x20, &kerim[0], 8, 1, 1, 0);
         bilgix=buffer[3];
         bilgiy=buffer[5];           
         ix=xaci=(bilgix*255+buffer[2])*0.01;if(ix>5){ix=5;}
         if(xaci>100){xaci=xaci-652.75;ix=-1*(-6+xaci);if(ix>11){ix=11;}}
         iy=yaci=(bilgiy*255+buffer[4])*0.01;if(iy>5){iy=5;}
         if(yaci>100){yaci=yaci-652.75;iy=-1*(-6+yaci);if(iy>11){iy=11;}}
         if(xaci<1 && xaci>0){ix=0;}if(yaci<1 && yaci>0){iy=0;}
////!               printf("\r\nxaci=%f ix=%d  yaci=%f iy=%d",xaci,ix,yaci,iy);
////!               printf("\r\nxaci=%f   yaci=%f ---------xaci=%f   yaci=%f ",xaci,yaci,xaci-652.75,yaci-652.75);
         shutdown7219a(0);
         shutdown7219b(0);
         for(j=0;j<16;j++) // Gönderilecek verinin bit bit gönderilmesi için oluşturulan döngü
         {
            output_low(clk_595); // Clock sinyali lojik-1 yapılıyor
            output_bit(datax_595,bit_test(digitx[ix],j)); // Bit değeri data pinine gönderiliyor
            output_bit(datay_595,bit_test(digity[iy],j)); // Bit değeri data pinine gönderiliyor
            output_high(clk_595);  // Clock sinyali lojik-0 yapılıyor
         }
         output_low(write_595);
         output_high(write_595);
         shutdown7219a(1);
         shutdown7219b(1);
      }
   }
}
       
}
}
[/code]

Last edited by kerim42 on Wed Apr 16, 2014 11:01 am; edited 1 time in total
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Mon Apr 14, 2014 7:03 am     Reply with quote

You can send standard (11bit) ID or extended (29bit) ID messages at any time. However, the hardware can only receive in one mode at a time.

It is possible to switch from receiving one to the other, but you have to shut down the CAN peripheral, re-configure it and then restart it. I use code as below, after calling can_init(), to override the setting defined by CAN_USE_EXTENDED_ID I tried having one receiver channel set to standard and one to extended, but I tried that and couldn't get it to work. It might be worth a try.

Code:

   // Take the CAN module off-line.
   can_set_mode(CAN_OP_CONFIG);
                 
   // We set up the filters to receive on all messages in extended ID mode.
   //Note the filters have to be set differently in each of the two Id modes.
   can_set_id(RX0MASK, CAN_MASK_ACCEPT_ALL, 1);   //set mask 0
   can_set_id(RX0FILTER0, 0, 1);//set filter 0 of mask 0
   can_set_id(RX0FILTER1, 0, 1);//set filter 1 of mask 0
   can_set_id(RX1MASK, CAN_MASK_ACCEPT_ALL, 1);   //set mask 1
   can_set_id(RX1FILTER2, 0, 1);   //set filter 0 of mask 1
   can_set_id(RX1FILTER3, 0, 1);   //set filter 1 of mask 1
   can_set_id(RX1FILTER4, 0, 1);   //set filter 2 of mask 1
   can_set_id(RX1FILTER5, 0, 1);   //set filter 3 of mask 1
    // Bring the CAN back on line, now in extended ID mode.
    can_set_mode(CAN_OP_NORMAL);


Generally its best to use only one type of ID on a CAN net, with all devices using the same version of the CAN protocol. The two can exist on the same CAN bus hardware - I have tried it: they don't seem to interfere - but they effectively form two independent logical buses operating over the same hardware.
kerim42



Joined: 18 Dec 2009
Posts: 2

View user's profile Send private message

PostPosted: Wed Apr 16, 2014 12:07 am     Reply with quote

Firstly thank RF_Developer
I tried your code. it has worked smoothly. then I add the following
Code:
if(gavs==1)
{
   gavs=0;
   // Take the CAN module off-line.
   can_set_mode(CAN_OP_CONFIG);
                 
   // We set up the filters to receive on all messages in extended ID mode.
   //Note the filters have to be set differently in each of the two Id modes.
   can_set_id(RX0MASK, CAN_MASK_ACCEPT_ALL, 1);   //set mask 0
   can_set_id(RX0FILTER0, 0, 1);//set filter 0 of mask 0
   can_set_id(RX0FILTER1, 0, 1);//set filter 1 of mask 0
   can_set_id(RX1MASK, CAN_MASK_ACCEPT_ALL, 1);   //set mask 1
   can_set_id(RX1FILTER2, 0, 1);   //set filter 0 of mask 1
   can_set_id(RX1FILTER3, 0, 1);   //set filter 1 of mask 1
   can_set_id(RX1FILTER4, 0, 1);   //set filter 2 of mask 1
   can_set_id(RX1FILTER5, 0, 1);   //set filter 3 of mask 1
    // Bring the CAN back on line, now in extended ID mode.
    can_set_mode(CAN_OP_NORMAL);
}else
{
   gavs=1;
   // Take the CAN module off-line.
   can_set_mode(CAN_OP_CONFIG);
                 
   // We set up the filters to receive on all messages in extended ID mode.
   //Note the filters have to be set differently in each of the two Id modes.
   can_set_id(RX0MASK, CAN_MASK_ACCEPT_ALL, 0);   //set mask 0
   can_set_id(RX0FILTER0, 0, 0);//set filter 0 of mask 0
   can_set_id(RX0FILTER1, 0, 0);//set filter 1 of mask 0
   can_set_id(RX1MASK, CAN_MASK_ACCEPT_ALL, 0);   //set mask 1
   can_set_id(RX1FILTER2, 0, 0);   //set filter 0 of mask 1
   can_set_id(RX1FILTER3, 0, 0);   //set filter 1 of mask 1
   can_set_id(RX1FILTER4, 0, 0);   //set filter 2 of mask 1
   can_set_id(RX1FILTER5, 0, 0);   //set filter 3 of mask 1
    // Bring the CAN back on line, now in extended ID mode.
    can_set_mode(CAN_OP_NORMAL);
}

This code worked but in every cycle has changed standard extended ID So 18f458 are tried and the delay occurs. We solved it that
in the system has got 3 Node.
1. Node set the 11 bit it send data 29 bit ID
2. Node set the 11 bit it send data 29 bit ID
3. Node set the 29 bit on the link this converted 11 bit
This worked not delay time. The only problem 1 and 2 node not worked if 3.Node disconnect.
Alright, Microchip has got 2 channel Can bus Microcontroller for example ds33PIC33FJ128MC708A. I wonder one channel 29 bit ID other channel 11 bit ID. is it possible? was that uses?
thanks your helps.


Last edited by kerim42 on Wed Apr 16, 2014 10:59 am; edited 2 times in total
newguy



Joined: 24 Jun 2004
Posts: 1904

View user's profile Send private message

PostPosted: Wed Apr 16, 2014 9:06 am     Reply with quote

RF_Developer wrote:
However, the hardware can only receive in one mode at a time.


On the dsPICs this is not true (functionally verified by code I've cut on devices working in a commercial system). I've not personally cut extended/standard co-mingled CAN ID code on an 18-series PIC, but I have a strong suspicion that it is indeed possible.

The big mental leap to make is that you must drop the CCS-supplied CAN code to realize the full potential of the CAN bus (and an increase in speed/performance). It's been a while since I've used their stock drivers, but I suspect that you are correct - they only support one mode or another. However, I'm pretty sure that the CAN hardware itself supports simultaneous standard/extended CAN frames.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed Apr 16, 2014 9:22 am     Reply with quote

newguy wrote:

On the dsPICs this is not true (functionally verified by code I've cut on devices working in a commercial system). I've not personally cut extended/standard co-mingled CAN ID code on an 18-series PIC, but I have a strong suspicion that it is indeed possible.


I'm recounting my practical experience. I couldn't get it to work on a PIC18F2580, but then I didn't need it to work in both modes at once. I needed it in switchable from one mode to the other. You'd need to have one RX channel set to 29 bit, the other to 11bit, which sounds like it should work, as indeed you've proved on the dsPICs. Its certainly possible, easy even, to send messages in both formats. May be I just didn't try hard enough :-(

Sure for ultimate performance ditching CCS CAN support, or doing your own based on it, is the way to go. Again, I've not had to go there, but I have had to reconfigure it, as the support provided by the CCS code is of the "configure using defines and set up once only" type, which is not particularly flexible. But, it works, which overall is a very good thing, which my code wouldn't, at least not at first, and it would take me a fair time to write my own code. Long enough, indeed, for me using the CCS code to be a no-brainer development time wise.
newguy



Joined: 24 Jun 2004
Posts: 1904

View user's profile Send private message

PostPosted: Wed Apr 16, 2014 10:17 am     Reply with quote

I had to abandon the CCS drivers out of necessity. I needed to come up with code to use DMA to pass through messages from one CAN port to another (I'm speaking of a two CAN port dsPIC). The dsPIC had to act as a completely transparent "break" between 2 CAN networks. Between compiler bugs and the particular device (dsPIC) I chose not being 100% supported by PCD, I quickly discovered that the built-in functions didn't work at all for the device so that's why I had to start from scratch.

Our standard suite of products only* uses standard IDs, so I initially only coded for standard ID passthrough functionality and extended ID packets would be discarded. *I say only, but there are remnants of ancient and impossible to track down extended IDs in some of our products....not documented of course. Some functions of our suite then didn't work, so I added in the support for extended ID passthrough as well. Those features that didn't initially work then worked fine.

Since I was able to do this with a dsPIC, that's what makes me certain that an 18-series PIC would be capable of it as well.

The nice thing about the CCS compiler is that it's very easy to do common tasks, like serial, i2c, spi, CAN, etc. The bad thing about the compiler is that it's easy to do common tasks. I say this in the sense that it removes the low level nitty-gritty register-level manipulations from you. Sometimes the CCS drivers aren't written in the most efficient or wise manner and it's better to completely understand everything in order to come up with a better way of doing things. One of my stock sayings here is "never trust anything you didn't write yourself." I've noticed in some instances that this also applies to the CCS drivers.
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