Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

CANbus interrupt fails with 29 bit ID on 500 kb/s OK with 11

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
lander72

Bascom Member



Joined: 29 Jul 2007
Posts: 25
Location: Fraser Valley BC

canada.gif
PostPosted: Sun Nov 09, 2014 9:02 pm    Post subject: CANbus interrupt fails with 29 bit ID on 500 kb/s OK with 11 Reply with quote

Hello Forum,

I have reached my limit of understanding on why my code fails to work with a 29 Bit ID but is OK if the first CANbus frame is
from an 11 bit ID. I have reviewed the datasheet for the m16m1 (Atmega16m1) family and the help with bascom.
I have changed many of the values that are within the Config CANmob like bitlen and msglen without success.

I have been able to get code working correctly with 29 bit ID and 125,000 Baud.

Even when the speed is slowed down to only < 5 CANbus frames per second, the same issue is unchanged.

Any suggestions or guidance would be appreciated.

Regards Larry

(BASCOM-AVR version : 2.0.7.7 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5093
Location: Holland

blank.gif
PostPosted: Mon Nov 10, 2014 10:54 am    Post subject: Reply with quote

i have no idea what this sample is?
is that the code you want to work? or code that works but not as you want it?

i can only comment on :
Quote:
Config Canmob = 0 , Bitlen = 29 , Idtag = &H0000 , Idmask = &H1FBF , Msgobject = Receive , Msglen = 1 , Autoreply = Disabled 'first mob is used for receiving data
Config Canmob = 1 , Bitlen = 11 , Idtag = &H0120 , Msgobject = Disabled , Msglen = 1 ' this mob is used for sending data


while in the int :

Config Canmob = -1 , Bitlen = 11 , Msgobject = Receive , Msglen = 1 , Autoreply = Disabled , Clearmob = no
Config Canmob = -1 , Bitlen = 11 , Msgobject = Disabled , Msglen = 1 , Clearmob = no

you use 11 bit length. and you make no distinct for the MOB.

It is always best to show code that does not work, and describe in comment what it is you want to do.

_________________
Mark
Back to top
View user's profile Visit poster's website
lander72

Bascom Member



Joined: 29 Jul 2007
Posts: 25
Location: Fraser Valley BC

canada.gif
PostPosted: Tue Nov 11, 2014 11:17 pm    Post subject: Reply with quote

Hello,

Thank-you for your response and my apologizes for not being clear enough.

This is working code with one main problem, it will not respond to 29 bit ID CANbus frames after power up or reset.

11 Bit is OK. Since it is OK, I'm surprised that the 29 bit ID is so elusive.

IF the first CANbus frame is 11 bit and the next one to 10,000 are 29 bit ID's then it works fine.

When I send a CANbus frame that is 29 bit after power up, the CAN interrupt fails to trigger and the yellow LED Does not flash or turn on.

Quote:
[you use 11 bit length. and you make no distinct for the MOB. ]

The comment from the example says to use -1 to reconfig the current MOB, so I'm not sure I understand your point?

The interrupt routine example as I understand it is for receiving both 11 bit and 29 bit ID's?

If it would help, I can add comments to show which lines of code are from the CANbus example.

Thank-you for your time and guidance.

Regards Larry
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5093
Location: Holland

blank.gif
PostPosted: Wed Nov 12, 2014 10:03 am    Post subject: Reply with quote

Quote:
The comment from the example says to use -1 to reconfig the current MOB, so I'm not sure I understand your point?

Did you also read the help?
When you use a value of -1 , the configuration is done on the current selected MOB (or CANPAGE). A reconfigure does not need to set the IDTAG and IDMASK again.
This means that you must specify the other parameters, just as in the original sample.
And even then : the 11 bit you specify in the interrupt would overrule the first 29 bit setting.
So my point is : you configure this :

Code:
Config Canmob = 0 , Bitlen = 29 , Idtag = &H0000 , Idmask = &H1FBF , Msgobject = Receive , Msglen = 1 , Autoreply = Disabled       'first mob  is used for receiving data
Config Canmob = 1 , Bitlen = 11 , Idtag = &H0120 , Msgobject = Disabled , Msglen = 1       ' this mob is used for sending data
 


But in the ISR you set bitlen to 11. I think you need to check the _can_int_idx and act according its value :
Code:
select case _can_int_idx
  case 0 : config canmob ....   bitlen 29
  case 1 : config canmob ....   bitlen 11
end select
 


you can best dump the can register value in hex after each config and show them here : CANIDT1 , CANIDT2, CANIDT3, CANIDT4 ,CANIDM1,CANIDM2,CANIDM3,CANIDM4, CANCDMOB

_________________
Mark
Back to top
View user's profile Visit poster's website
lander72

Bascom Member



Joined: 29 Jul 2007
Posts: 25
Location: Fraser Valley BC

canada.gif
PostPosted: Tue Dec 02, 2014 5:53 pm    Post subject: Reply with quote

Hi Mark,

Thank-you very much for your help, guidance, and patience.
Once I changed the Config CANmob correctly, I was able to read both 29 and 11 bit frames with the same code.
Config CANmob = 0 , Bitlen = 29 , Idtag = &H0000000 , Idmask = &H0000000 Msgobject = Receive , Msglen = 1 , Autoreply = disabled
The Bitlen in the ISR was also changed to 29

When you suggested that I look at : you can best dump the can register value in hex after each config and show them here : CANIDT1 , CANIDT2, CANIDT3, CANIDT4 ,CANIDM1,CANIDM2,CANIDM3,CANIDM4, CANCDMOB

I found that it was not working as expected and that I didn't under stand how to correctly set the range with IDmask.

After reading the help for IDmask again and looking at the examples, the light came on Shocked

Merry Christmas, Larry
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5093
Location: Holland

blank.gif
PostPosted: Tue Dec 02, 2014 8:22 pm    Post subject: Reply with quote

i had to read the datasheet a lot of times too before i figured it out since it worked indeed very different than i was expecting. i think the help contains some info about it ?
_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
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
You cannot attach files in this forum
You cannot download files in this forum