View previous topic :: View next topic |
Author |
Message |
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Thu Jan 19, 2017 7:22 am Post subject: Need Help (AT90CAN32) |
|
|
Greetings,
Want to say thet I'm new in coding in bascom and in electronics in general, im studing bascom around a week, By passed week i did a lot of homework with my development board Atmega8A, and already understood a plenty useful stuff. I dont have any information about bascom on my native language, basicly im studing only with help of your site.
So, what im trying now, its to get CAN BUS work with my AT90CAN32, all information i found its from your site's wiki - http://avrhelp.mcselec.com/index.html?config_canbusmode.htm
All i need is a simple code exmaple how to send a data from AT90CAN32 with CAN BUS , Im cheking it with my power supply uint, so i receive nothing , i just want to know how to make chip sending a data.
i Guess i can do it with cansend()
but how , i didnt get it even with ur wiki help
Code: | $regfile = "m32can.dat"
$crystal = 12000000
$hwstack = 64
$swstack = 32
$framesize = 40
'$prog &HFF , &HCF , &HD9 , &HFF
Config Porta = Output
Config Portc = Input
Portc = 255
Config Com2 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "COM2:" For Binary As #2
Config Canbusmode = Enabled
Config Canmob = 1 , Bitlen = 11 , Idtag = &H0120 , Msgobject = Disabled , Msglen = 1
Dim _canpage As Byte , _canid As Dword , _can_int_idx As Byte , _can_mobints As Word
Dim Breceived As Byte , Bok As Byte , Bdil As Byte
_canpage = 0
Declare Sub Cansend()
Sub Cansend()
Do
Decr _canpage
Loop
End Sub |
|
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Thu Jan 19, 2017 10:54 pm Post subject: |
|
|
hi
I have not try CAN yet but you can't use Cansend() as a sub name its a CMD ( it's blue)
Try use the forum search function, search for : canbus _________________ / Kim |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Fri Jan 20, 2017 4:28 am Post subject: |
|
|
kimmi wrote: | hi
I have not try CAN yet but you can't use Cansend() as a sub name its a CMD ( it's blue)
Try use the forum search function, search for : canbus |
Thx for reply,
BTW do you know, where people take this "&H0121" for idtag and " &H0120" for Idmask? No info on datasheet, and on wiki, confused
Code: | Config Canmob = 1 , Bitlen = 11 , Idtag = &H0121 , Msgobject = Disabled , Msglen = 2 ' this mob is used for sending data |
Code: | Config Canmob = 0 , Bitlen = 11 , Idtag = &H0120 , Idmask = &H0120 , Msgobject = Receive , Msglen = 1 , Autoreply = Disabled 'first mob is used for receiving data |
|
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Fri Jan 20, 2017 8:06 am Post subject: |
|
|
I'm trying to send any message and receive it on my can hacker, i did everything and stucked,
here is a code im using, any help appreciate it plz
Code: | $regfile = "m32can.dat" ' processor we use
$crystal = 16000000 ' Crystal 16 MHz
$hwstack = 64
$swstack = 32
$framesize = 40
$prog &HFF , &HFF , &HB9 , &HFF
Dim _can_page As Byte , _canid As Dword , _can_int_idx As Byte , _can_mobints As Word
Dim Breceived As Byte , Bok As Byte , Bdil As Byte , Senddata As Byte
senddata = 5
Config Canmob = 1 , Bitlen = 11 , Idtag = &H0220, Msgobject = Disabled , Msglen = 1
do
Bok = Cansend(1 , Senddata )
loop |
|
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Fri Jan 20, 2017 8:07 am Post subject: |
|
|
I'm trying to send any message and receive it on my can hacker, i did everything and stucked,
I dunno where is a mistake, i guessed its in $prog, wrong fuses or something
here is a code im using, any help appreciate it plz
Code: | $regfile = "m32can.dat" ' processor we use
$crystal = 16000000 ' Crystal 16 MHz
$hwstack = 64
$swstack = 32
$framesize = 40
$prog &HFF , &HFF , &HB9 , &HFF
Dim _can_page As Byte , _canid As Dword , _can_int_idx As Byte , _can_mobints As Word
Dim Breceived As Byte , Bok As Byte , Bdil As Byte , Senddata As Byte
senddata = 5
Config Canmob = 1 , Bitlen = 11 , Idtag = &H0220, Msgobject = Disabled , Msglen = 1
do
Bok = Cansend(1 , Senddata )
loop |
|
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Fri Jan 20, 2017 9:12 am Post subject: |
|
|
Hi,
Maybe have a look at the sample code "CAN-Elektor.bas", it's in the sample Directory.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Fri Jan 20, 2017 9:26 am Post subject: |
|
|
Thx for ur reply, but i already checked the sample file, it doesnt work. I dont send any data.
I also thoght that it is not working because this sample for AT90can128 and my chip is AT90can32, but if its not like that,
therefore im out of any ideas why it doest work |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Fri Jan 20, 2017 9:51 am Post subject: |
|
|
I checked my devices with test program in .hex file, it was writen some guy in AVR BASCOM, im getting data from it, so it means my devices are working and connected properly.
So it means that mistakes in code, there are my can hacker cabel, can hacker program shows that im not sending data and code im using.
http://imgur.com/a/vOABO
http://imgur.com/a/cJpE9 |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Fri Jan 20, 2017 10:03 am Post subject: |
|
|
Hi,
I've never used CAN, but are you sure this is correct
Cansit1 = 0 : Cansit2 = 0 : Cangit = Cangit
Your Setting Cangit to itself rather than 0?
You you sure you Setting the correct Interrupt enable bits?
Cangie = &B10111000
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Fri Jan 20, 2017 10:21 am Post subject: |
|
|
i.dobson wrote: | Hi,
I've never used CAN, but are you sure this is correct
Cansit1 = 0 : Cansit2 = 0 : Cangit = Cangit
Your Setting Cangit to itself rather than 0?
You you sure you Setting the correct Interrupt enable bits?
Cangie = &B10111000
Regards
Ian Dobson |
thx for fast reply,but sorry, i didnt get it,
what interrupt do in this sample? Because from my point of view interrupt means that you can interrupt main procces of a program by pressing a button for example, and i dont need it, im not pressing button, all i need is be able to send a data.
Sorry if im wrong
Also, Cangie = &B10111000, what does it do, and how to get right value of it? I cheked it on datasheet, but its nothing, can someone explain it?
i just took it from sample |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Jan 20, 2017 11:03 am Post subject: |
|
|
jeezywonder wrote: | i guessed its in $prog, wrong fuses or something
Code: | $regfile = "m32can.dat" ' processor we use
$prog &HFF , &HFF , &HB9 , &HFF |
|
If you guess already, why do you use then the $prog directive at all, especially as it looks you don't know what it's doing?
$prog is useful for doing series programming of controllers in virgin condition, where programming and flashing is done then in one go.
But your approach is to poke around by trial and error and there $prog makes no sense.
Some explanation: The second &hFF from left writes the low fuse bits, this low fuse controls system clock, startup time and clock output, table 25-5 in the current data sheet.
&hFF looks like an invalid option, don't know how the controller swallows that.
Interestingly in your opening post the low fuse bit is set to an useful value, however the $prog directive is commented out, while in the following posts it's active but wrong.
Why don't you use the programmer's dialog and there the lock and fuse bits tab to actually set it right?
You need to set to external crystal oscillator for 8-16MHz and startup time upon your taste, respectively how noisy the electrical environment is.
Don't set to external clock btw., as then you have temporarily fried the controller. If you did not already do.
But as long as you still can program it, it looks ok.
For reference of fusebits, look here: http://www.engbedded.com/fusecalc
And btw. code.bas.txt uses ATM128can and uses the same $prog nonsense-setting. If you got it from a guy, maybe said guy does not like you very much
Edit: checked the data sheet once again, CKSEL0 = 1, CKSEL3..1 = 111 and SUT 1..0 = 11 is a valid option there, only engbedded did not list it.
Check out the fuse tab offered by Bascom anyway, to see what you got offered there, set the fuses right and remove the $prog from your code untill you actually need it.
Last edited by MWS on Fri Jan 20, 2017 11:27 am; edited 1 time in total |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Fri Jan 20, 2017 11:11 am Post subject: |
|
|
MWS wrote: | jeezywonder wrote: | i guessed its in $prog, wrong fuses or something
Code: | $regfile = "m32can.dat" ' processor we use
$prog &HFF , &HFF , &HB9 , &HFF |
|
If you guess already, why do you use then the $prog directive at all, especially as it looks you don't know what it's doing?
$prog is useful for doing series programming of controllers in virgin condition, where programming and flashing is done then in one go.
But your approach is to poke around by trial and error and there $prog makes no sense.
Some explanation: The second &hFF from left writes the low fuse bits, this low fuse controls system clock, startup time and clock output, table 25-5 in the current data sheet.
&hFF looks like an invalid option, don't know how the controller swallows that.
Interestingly in your opening post the low fuse bit is set to an useful value, however the $prog directive is commented out, while in the following posts it's active but wrong.
Why don't you use the programmer's dialog and there the lock and fuse bits tab to actually set it right?
You need to set to external crystal oscillator for 8-16MHz and startup time upon your taste, respectively how noisy the electrical environment is.
Don't set to external clock btw., as then you have temporarily fried the controller. If you did not already do.
But as long as you still can program it, it looks ok.
For reference of fusebits, look here: http://www.engbedded.com/fusecalc
And btw. code.bas.txt uses ATM128can and uses the same $prog nonsense-setting. If you got it from a guy, maybe said guy does not like you very much |
Really apreciate your useful reply.
As i understood i should remove, $prog settings.
but if problem isnt on fuses, why cant send data?
Is a code correct? besides $prog of cause
Thanks in further |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Jan 20, 2017 11:38 am Post subject: |
|
|
jeezywonder wrote: | Is a code correct? |
What code? There are some in the meantime.
What happens if code.bas.txt is adapted, controller set to m32can.dat, compiled and flashed?
Have no experience with CAN, only saw $prog can be a nasty thing, with the wrong values the wrong fuses get set.
In this case it may be, that only engbedded, one of my preferred sites to look it up, did not list the option all bits to 1.
Anyway I would set the fuses one time and otherwise don't touch it.
Edit: maybe post the working hex and I'll try to have a look into. |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Fri Jan 20, 2017 12:06 pm Post subject: |
|
|
MWS wrote: | jeezywonder wrote: | Is a code correct? |
What code? There are some in the meantime.
What happens if code.bas.txt is adapted, controller set to m32can.dat, compiled and flashed?
Have no experience with CAN, only saw $prog can be a nasty thing, with the wrong values the wrong fuses get set.
In this case it may be, that only engbedded, one of my preferred sites to look it up, did not list the option all bits to 1.
Anyway I would set the fuses one time and otherwise don't touch it.
Edit: maybe post the working hex and I'll try to have a look into. |
I attached a code in previous post. this code i trying to get worked.
Here the .hex, mate
I apreciate your help |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Jan 20, 2017 12:43 pm Post subject: |
|
|
Quote: | Thx for ur reply, but i already checked the sample file, it doesnt work. I dont send any data. |
It does work but did you pay attention to this :
Code: | Do
If PINC <> Bdil Then ' if the switch changed
Bdil = PINC ' save the value
Bok = CANsend(1 , PINC) ' send one byte using MOB 1
Print #2 , "OK:" ; Bok ' should be 0 if it was send OK
End If
Loop
|
you have to change the DIP switch in order the sample sends any data.
you could also rewrite it :
Code: | Do
Bok = CANsend(1 , PINC) ' send one byte using MOB 1
waitms 100
Loop
|
If i were you i would start with much simpler things. And then study the sample made for elektor CAN board.
It is a tested sample that works. _________________ Mark |
|
Back to top |
|
|
|
|
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
|
|