Flashing the AVR-CAN board

My Nissan Leaf Forum

Help Support My Nissan Leaf Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
tomsax said:
I tried, that's not the problem. The erase always happens when you write flash, if you don't ask for it avrdude warns you it's doing it anyway, and you always get a message while the erase is happening. There's definitely something wrong with the JTAG ICE Mark I and the AT90CAN128 (or perhaps the AVR-CAN board).
avrfreaks guys may know something.

Really I just posted to let people know it can be programmed from an ISP programmer since I saw that a number of people bought an ISP programmer.
Hmmm ... I could try that.
 
The AVR-JTAG-ICE ("clone"?) board off ebay ($13 + $5 shipping for Q1) has an RS232 interface and the JTAG interface works well on all nine AVR-CAN boards that we have tried so far. It does REQUIRE a "good" USB-to-RS232 adapter cable.

I have also used AVR-Dragon (more expensive) in JTAG mode, both programmers with AVRdude.

What command line are you using to start AVRdude?
 
#Reset is EXT1-7
Gnd is EXT1-3 and -4
+5v is EXT1-5 and -6

only the "SCK" is on EXT2-33

However, if the AT90CAN128 chip is really using p2 and p3 (instead of p13 and p12) for MISO and MOSI, they might also be using another pin for SCK (instead of p11)?
 
Gary, have you published your firmware (source & compiled) ? If you don't want to publish it now, can you send it to me in PM ...
 
Do you have the hardware for the CAN-Capture, ... or for the SOC-Meter, ... or both?

The Capture can do 1, 2, or 3 channels (takes 1, 2, or 3 AVR-CAN boards), and CAN-Do reads the binary info, adds time stamps, and stores up to 20 million CAN-messages in memory. The stored messages can be written to a CAN-Log file for later viewing and analysis.

The Meter function requires a display to see anything useful.

What flashing software & hardware do you have?

Will you write the hex file (via JTAG) to the AT90CAN128 uP on the AVR-CAN board?

The source is in transition, mostly for the SOC-Meter, but includes both Capture and Meter functions simultaneously. PM me your email address and I can send the .hex, and my "main" .c if you wish. But, at this point, please consider it to be for your personal use only.

However, I am open to suggestions.
 
garygid said:
Will you write the hex file (via JTAG) to the AT90CAN128 uP on the AVR-CAN board?

The source is in transition, mostly for the SOC-Meter, but includes both Capture and Meter functions simultaneously. PM me your email address and I can send the .hex, and my "main" .c if you wish. But, at this point, please consider it to be for your personal use only.

See my PM to you.

I bought Olimax AVR-USB-JTAG programmer on e-bay. So, now I'm all set to flash AVR-CAN.
 
What eBay "auction" for the USB AVR JTAG Programmer, please?

I will email the hex file to you, at this point for your use only, please.

A. Powering the board:

About 8v is good for the board.
12v is high, and 14v is worse, and the on-board 5v regulator gets very hot, especially when also powering the LED display.

So:
1. For testing and programming, I connect ground and 8v DC to the white 2-pin Power-In header.

2. For real use in the car, I connect a 5v 1watt zener diode between the OBD 12v (always ON 12v is on OBD pin 16, or "switched" 12v, ON during Ready mode or Acc2 mode, is on OBD pin 8) and the AVR-CAN board's Power-In on the "D" pin 9. Optionally, one can add an On-Off-On SPDT sub-mini toggle switch to chose between the always-on 12v and the switched 12v.

3. Ground is OBD pin 5 and pin 4 is "shield". I connect one to "D" pin 3 and the other to pin 6 (as I recall), which are both grounds. Or, I might have connected OBD 4 and 5 both to "D" pin 3.

B. Connecting the CAN buss:

1. This is not necessary for programming or testing, but one finds EV-CAN "high" on OBD 13 and "low" on OBD pin 12.

2. Optionally, one can choose to wire a DPDT sub-mini toggle switch (can be On-On or On-Off-On) to select between the EV and the "Car" CAN buss. The Car-CAN has its high on OBD pin 6 and low on pin 14.

3. The (selected) CAN-high input goes to "D" pin 7, and the low goes to "D" pin 2.


C. Connecting the LED serial Display:

1. Ground (GND on the Display card) goes to EXT2 pin 8. I use a 1x4 or 2x4 header-connector (0.1" centers) for the connection, a black wire for Ground. A 1x2 connector could be used instead, but one is less likely to make a mistake plugging in the 4x2 connector.

2. The 5v power (VCC on the Display card) connects to EXT2 pin 6, right next to the black Ground wire (#1 above), using a red "Power" wire.

3. The Serial Data Input to control the Display. The "RX" connection hole is at the other end of the 8-hole "interface" on the Display card. It connects to EXT2 pin 23, and I use a green wire to a 1x6 header-connector (but a 1x1 connector would be sufficient).


D. If the programming is successful:

1. The board's LED should come on for 2 seconds. Then, after a few seconds OFF, start to flash fast (10x per sec) while the board waits for a CAN-buss signal.

2. If the Display is attached, it will display "junk" because its default is only 9600 baud and the AVR-CAN is using 57600 baud. Unfortunately we cannot detect the Display's speed, but the SOC-Meter can try every speed to "set" the Display to 57600 baud.

3. In THIS version of the firmware (might change) ... To force this one-time setting of the display, have the "BUT" button (on the AVR-CAN board), held down (ON) at the 2-second mark after Reset/Reboot, and the LED will flash quickly 3 times, and the Display will "twich" while 6 baud rates are tried, issuing the "Set Baud Rate to 57600" command at each speed. After the one-time setting, this Display-Init should not be needed again.

4. Then, at any power-on or reset/reboot, one should see the firmware version number briefly (currently as "F1.05"), and the Display should show "----" while waiting for the CAN buss. Then it will show " GO " (or possibly "999.9") while waiting for the first "SOC" message.

5. For now, one sees the "SOC Percentage", for example " 98.9" might appear after a full charge.

NOTE: We are exploring the workings of the car, and this MIGHT NOT be an accurate SOC. It is just a number (I chose 281 as 100%) that the LEAF generates. It seems to go up when we charge (over 6 hours), and down when we drive. BUT, just because it indicates 21.3% ond the "Guess-O-Meter" ESTIMATES hat you MIGHT have 15 miles remaining (IF you keep driving as you have done in the "recent" past, does NOT mean that you actually have ANY guaranteed miles left. USE AT YOUR OWN RISK.

Right now I use it to gather data, and understand the LEAF's behavior better.

We believe that the "Low Battery Warning" usually comes at about 17%, and the "Very Low Battery Warning" at ... maybe ??? 10 to 8%? ... and that Turtle may occur around 5%, MAYBE. Some have experienced "very few miles" after the Warnings, and a VERY short Turtle mode (100 yards compared to other's perhaps 1 mile experience).

SO, DO NOT DEPEND on much mileage after the "VERY LOW" Battery Warning. It is not fun to wait for a tow ... and it "looks bad" for all LEAFs (and EVs) to see them on the backs of tow trucks!
 
Good write up Gary, thanks for all your help in getting this going. BTW, guessing this is what you send in the "instructions" of the kit ?

I got the cable yesterday - so I can start on the SOC meter, after getting some crimp pins etc.

BTW, the ebay was a one-off slightly-used piece someone was selling for a good price. It is the same one sparkfun sells for $57.

http://www.sparkfun.com/products/12

I will email the hex file to you, at this point for your use only, please.
Will wait for that, and yes it will remain with me. Also do send me the source so I can figure out what is happening and start working on enhancements.
 
I realize that I need to put the above instructions in the SOC-Meter thread.

Also, I need to add the instructions for wiring the two "User-Input" buttons (Red left, Black right), but I will probably change how they were connected in my experimental version 1.05 of the Firmware.

Another Note: The SAME firmware SHOULD support CAN-Capture at this point, though it has not been sufficiently tested since I added the SOC-Meter parts of the code.

Assuming it works, just add an RS232 connection (115200 baud) to a the PC that is running ny CAN-Do program.

The CAN-message comes in 11-byte binary records from the AVR-CAN to the PC.
 
BTW, I got a 8V Zener Diode and a 6V Zener Diode. Which one should I use - I'm thinking of 8V (since they expect 7 to 12V) - but your 5.1V seems to be working fine ...
 
The "Mini USB AVR JTAG Programmer for Atmel ..." is found on Ebay
by searching for "Mini USB AVR JTAG":
http://shop.ebay.com/i.html?_from=R...w=Mini+USB+AVR+JTAG&_sacat=See-All-Categories

for $26 from a domestic source:
http://cgi.ebay.com/380328122863 (where I got mine, for quick delivery)

down to about $17 from overseas
http://cgi.ebay.com/250597883758 (untried source)

It comes with a "long" JTAG cable and can plug directly into a PC's
USB port (or one can use a USB A-to-A extension cable).

It seems to work well, though there were no instructions.
It seems to power the target board through the JTAG cable.
It has one jumper that MIGHT pass 5v or 3.3v to the target board,
but I have not yet measured the passed voltage.

Using AVRdude, I called it a "jtag1" device, on the appropriate COM port.

Of all I have tried, this seems to be the easiest to use with the
AVR-CAN board, as it provides power to the board as well,
presumably safely enough for the AVR-CAN board's regulator.

With this programer, it seems that one should NOT supply power
to the AVR-CAN board, or at least it is not necessary.
 
garygid said:
The 5.1v Zener is in SERIES with the input,
to drop the 12-14 volts ... so 14 - 5 = 9 and
12 - 5 = 7 volts.
That's right - somehow I kept thinking about the usual parallel z.diode use ...
 
garygid said:
The "Mini USB AVR JTAG Programmer for Atmel ..." is found on Ebay
by searching for "Mini USB AVR JTAG":
http://shop.ebay.com/i.html?_from=R...w=Mini+USB+AVR+JTAG&_sacat=See-All-Categories

for $26 from a domestic source:
http://cgi.ebay.com/380328122863 (where I got mine, for quick delivery)

down to about $17 from overseas
http://cgi.ebay.com/250597883758 (untried source)

It comes with a "long" JTAG cable and can plug directly into a PC's
USB port (or one can use a USB A-to-A extension cable).

It seems to work well, though there were no instructions.
It seems to power the target board through the JTAG cable.
It has one jumper that MIGHT pass 5v or 3.3v to the target board,
but I have not yet measured the passed voltage.

Using AVRdude, I called it a "jtag1" device, on the appropriate COM port.

Of all I have tried, this seems to be the easiest to use with the
AVR-CAN board, as it provides power to the board as well,
presumably safely enough for the AVR-CAN board's regulator.

With this programer, it seems that one should NOT supply power
to the AVR-CAN board, or at least it is not necessary.

OK, great, I just ordered one of these yesterday. I'm interested in the debugging capabilities, which you don't get with ICSP programmers like my USBtinyISP. Have you gotten anywhere with debugging and this board? It's supposed to be JTAG-ICE compatible.

It supplies regulated +5V via pins 4 & 7 on the JTAG connector. Make sure that you power your board from only 1 source at a time. Don't apply power to the voltage regulator input of the AVR-CAN while using this programmer, unless it has a jumper to cut off the +5V to the JTAG conector. My USBtinyISP has a PWR jumper that can be removed when I use it to program a board that already has 5V going into it. Also, the AT90CAN128 board has an EPWR jumper to disconnect the onboard regulated power when using a powered programmer.
 
BTW, I successfully connected my avr-can to Leaf - it was showing 62.6% and as I charged, kept going up. So things are working fine. I still need to get the 5v ZD and connect the power VIN from CAN to the board. I'm still using the 9V battery to power the board. I've the blue LED - looks nice with the Blue Leaf :lol: Yet to find a decent project box, though.

Yes, we can connect just the ev-can L & H - and it works. Only thing is, I had to switch on the car (didn't press brake) in the beginning to make the board recognize the CAN. Until then LED just showed dashes. Once this happenned, I could switch off the car and the avr-can continued to work.

Next step is to get the source to compile in avr-studio 4. If not I'll just use avr-win command line. BTW, I flashed the hex file using avr-studio 4 and it worked fine. I'm using the Olimax made JTAG programmer - that doesn't power the baord when connected.
 
The "----" stays until some CAN buss messages start being received.

The present code does nothing special if no messages occur for a while.

I tried AVR Studio 5, not 4!!
Maybe 4 is a lot easier to use?
 
garygid said:
The "----" stays until some CAN buss messages start being received.
So, when the car is switched off - and not charging - are there any messages that Leaf sends ?

I tried AVR Studio 5, not 4!!
Maybe 4 is a lot easier to use?
4 is much more "primitive" and not based on Visual Studio. But it works with the Olimex programmer I got. That was the reason I was trying it.

BTW, does ths ource compile with AVRS 5 ? Is that what you used ? May be we should start a separate thread on software.
 
Back
Top