Error writing eeprom data - SOLVED

Greebo
Posts: 63
Joined: Sat Jun 16, 2012 11:12 am
Country: Australia
Location: NSW

Re: Error writing eeprom data

Post by Greebo »

MikeB, attached are three .hex files:

Default_er9x_eeprom.hex
TX formatted after "Bad EEPROM data error, then changed two settings -> Owner name = "Greebo" and stick mode = Mode 1
Read from EEPROM using avrdude

Default_eepe_EEPROM.hex
From within eepe, click "New", changed two settings in the General Settings -> Owner name = "Greebo" and stick mode = Mode 1
Double click on the 1st model slot to create Model01 and then close.
Written to EEPROM using eepe (Verification error encountered after write finished) - this file came from the temp directory and is the one referenced in the avrdude command line within eepe during the write.
*EDIT* This is the only file I can read with eepe... eepe reports "error loading file" for both of the other files.

From_TXwrite_eepe_eeprom.hex
This file was read directly from the TX immediately after writing the "Default_eepe_EEPROM.hex" file above.
The "Bad EEPROM Data" error was showing on the screen at the time avrdude was run.
dvogonen wrote:As others have mentioned earlier you are not using the most common programmer. You might consider ordering another programmer since your problems are very hard to attribute to your software setup. A USBASP is only around 5$ on Ebay and that is the programmer that most people seem to use. If you are lucky the problem lies with the programmer. If you are less lucky the USBASP can still be used to program e.g. the very popular KKcopter multicopter boards.
Many other people have successfully used an arduino running arduinoISP as an AVR programmer with their 9x radios.
I'm well aware that I can get a programmer for around $5, but while I wait the 2 weeks for it to arrive, I should be able to use the arduino I already have... and it does work perfectly well for flashing the firmware to the 9x.

While I understand that some may think my posts are clogging up "their" site (especially since I'm only new here), I'm hoping that I will eventually be able to get to the bottom of this (with any help that can be provided) and these posts will be here for the next person who is stuck where I was, maybe even with their $5 USBASP from ebay. ;)
Attachments
From_TXwrite_eepe_eeprom.hex
Default seetings from eepe file written to TX then read back
(4.83 KiB) Downloaded 763 times
Default_er9x_eeprom.hex
Default TX settings read from TX
(4.83 KiB) Downloaded 744 times
Default_eepe_EEPROM.hex
Default settings from eepe
(4.82 KiB) Downloaded 770 times

User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Error writing eeprom data

Post by jhsa »

Greebo wrote:

While I understand that some may think my posts are clogging up "their" site (especially since I'm only new here),
I really don't believe that. People here like to help as much as they can.. but it is up to the people that are asking for help to follow the advice, or not.. :roll: ;)
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
Greebo
Posts: 63
Joined: Sat Jun 16, 2012 11:12 am
Country: Australia
Location: NSW

Re: Error writing eeprom data

Post by Greebo »

jhsa wrote: I really don't believe that. People here like to help as much as they can.. but it is up to the people that are asking for help to follow the advice, or not.. :roll: ;)
When that advice sounds like "you're doing something we don't normally do, go away and do the same thing we do", you have to wonder how er9x happened in the first place ;)

The 9x has an ATMega 64 which can be programmed using avrdude. The Arduino running ArduinoISP acts exactly like the AVRISP programmer and is very widely used to program ATMega chips.

Surely you can understand my reasons for trying to persist with solving this?
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Error writing eeprom data

Post by jhsa »

Yes I understand.. you want to do it with the arduino no matter what. I think you should, and when you sort it out don't forget to make a little tutorial for the wiki.
And when I say advice, means exactly advice.. means that people say what they think it's right.. and people are free to follow it or not.. This is exactly how it should sound..

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Error writing eeprom data

Post by MikeB »

The two files you have read from the EEPROM are clearly corrupt. In both files they consist of 128 bytes repeated through the file 16 times.
The question is why?
Some possible reasons:
Programmer doesn't handle EEPROM correctly, reading, writing or both (from your last test it might be both).
Fault in EEPROM programmer hardware inside processor.
Fault in EEPROM inside processor.

Best test of the EEPROM I can think of is to accept the bad EEPROM and let it format. Then using the Tx (not eepe), create 16 models. Switch off, then switch back on and test for all 16 models still being correctly present. This could include changing some values in each model.

Clearly, to test the programmer, you either need to try using your programmer to program the EEPROM in a different device, or use a different programmer to program the EEPROM in your Tx. Have you someone else who has a different programmer you could try?

It might be useful if you could post the AVRDUDE command line you are using. It is probably correct, but may be worth a check.

(BTW you are providing good reports of your problems and tests, thanks)

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
Kilrah
Posts: 11108
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Error writing eeprom data

Post by Kilrah »

Well, you did have a full page of advice and suggestions before getting to the (sarcastic, I mention) "Buy an usbasp".

Such a problem has limited possible causes:
- Most likely, eepe/er9x version mismatch. First suggestion, but you said it's OK.
- Avrdude configuration. You played with command line etc to no avail.
- Programmer firmware, you tested different ArduinoISP versions with no help.
- Programmer hardware -> that's where we are.
- Defective radio/ATMega. Next step, but I'm pretty sure you prefer to hear "Buy an usbasp" before "Buy a new radio" ;)

We're simply pretty much running out of advice to give you. Few people use ArduinoISP to flash their 9x (I don't know of any frequent poster who does here, so you won't get helpers with first hand experience), and I've already read about problems from those that do. Most use usbasps, usually without issue. So, as your problem seems tricky, if you get an usbasp you will get a bit closer to the "known good" setup and eliminate a potential source of problems, making it easier for yourself and the others to find where the issue comes from.

That's all. If you don't want to follow that route no problem.

One further suggestion, try the companion9x/open9x combination once instead of eepe/er9x, and see if it behaves the same.
User avatar
dvogonen
Posts: 453
Joined: Tue Jan 31, 2012 9:38 pm
Country: Sweden
Location: Stockholm

Sv: Error writing eeprom data

Post by dvogonen »

I do not think that anyone thinks that you are clogging the site. My comment about considering ordering a spare programmer was just intended for the case that something is actually physically wrong with your current programmer. As far as I understand you have done everything right as far as software setup goes. Writing eeprom data really ought to work by now.
Hardware problems are very rare in comparison to software problems, but they occur from time to time. I have spent a lot of time trying to nail down ghost software problems that turned out not to exist since the problems were caused by broken hardware. The lesson I have learned is that it is a good tactic to pinpoint problems by exchanging component by component in broken systems until they start working.
Greebo
Posts: 63
Joined: Sat Jun 16, 2012 11:12 am
Country: Australia
Location: NSW

Re: Error writing eeprom data

Post by Greebo »

Thanks for all the responses guys.

First up, I understand why people are suggesting another programmer... and I have one on its way. But the Arduino _should_ work.
Until the new programmer turns up, I'm prepared to waste my time trying to make the arduino work as long as people keep making suggestions.
I'll also go looking for help on arduino specific forums... surely someone has written to the eeprom on the atmega's with it before me :)

MikeB,
Adding 16 models... I'll have a go at that when I get home from work.
As for programming a different device or using a different programmer, I can't do either of those until my next order arrives (which includes a programmer and a KK multicopter board) - then I'll be able to try both suggestions...
Here's the avrdude commands I used to generate those hex files (avrisp is what the ArduinioISP sketch is supposed to be) :
Reading the "TX formatted" eeprom:
avrdude.exe -c avrisp -p m64 -b 19200 -P com9 -U eeprom:r:Default_er9x_eeprom.hex:i -v -v

Writing the eepe settings file:
avrdude.exe -c avrisp -p m64 -b 19200 -P com9 -U eeprom:w:Default_eepe_eeprom.hex:i -v -v
(which returned avrdude.exe: verification error, first mismatch at byte 0x0000: 0x04 != 0x79)

Reading the above file back out again:
avrdude.exe -c avrisp -p m64 -b 19200 -P com9 -U eeprom:r:From_TXwrite_eepe_eeprom.hex:i -v -v


Kilrah,
I've also tried most of these steps using companion9x and open9x (and posted that previously in this thread), so its not specific to eepe or the firmware...
ReSt
Posts: 1581
Joined: Tue Dec 27, 2011 11:34 pm
Country: -

Re: Error writing eeprom data

Post by ReSt »

Just to exclude that possibility.
I read about programs that had problems with higher port numbers. Can you rearrange your port to a number of com5 or below and try that.

Not that I really believe that it is the problem but just to exclude it.

Reinhard
Greebo
Posts: 63
Joined: Sat Jun 16, 2012 11:12 am
Country: Australia
Location: NSW

Re: Error writing eeprom data

Post by Greebo »

Update (its sill not working but there is progress)
I've tried a totally different PC on com port 2 and I still get the same read/write errors.

So.... I formatted the eeprom from the radio again, rolled up my sleeves and dived into avrdude -t

I used "dump eeprom xx 32" incrementing xx by 32 each time to read out the bytes of the eeprom to the screen.
I did this until I came across the string "ME" in the eeprom at address 122 and then used "write eeprom 122 71 114 101 101 98 111" to write "Greebo" in what I hoped was the "Pilot name" section of memory. I then closed down avrdude and booted up the radio.

A pilot name of "Greebo" greeted me on the boot screen (yay!). So the arduino with ArduinoISP will successfully write bytes to the eeprom and will successfully read them both while in terminal mode, but there must be a timing issue or something when avrdude does a bulk read/write.

Unfortunately I have to get to work so I can't do any more testing at this stage, but my next step will be to read the default formatted radio settings out 32 bytes at a time and compare them to a known good .hex file.

Can someone please upload an eeprom hex file from a radio that has just had its eeprom formatted by er9x-r762 so I've got something to do my comparison with.

Thanks!
Greebo
Posts: 63
Joined: Sat Jun 16, 2012 11:12 am
Country: Australia
Location: NSW

Re: Error writing eeprom data

Post by Greebo »

Anyone able to oblige?

As above, I'd like someone to please upload an EEPROM .hex file read from a freshly formatted Tx running er9x-r762 so I have a known good hex file to compare things too...
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Error writing eeprom data

Post by MikeB »

Not easy to get a freshly formatted EEPROM to give you, but I have attached the same thing as created as a default by eepe. A freshly formatted EEPROM should match this very closely, may have just a few different bytes. It should be obvious if your read values do not match up.
default.hex
(4.82 KiB) Downloaded 787 times
Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Greebo
Posts: 63
Joined: Sat Jun 16, 2012 11:12 am
Country: Australia
Location: NSW

Re: Error writing eeprom data

Post by Greebo »

Thanks!
Greebo
Posts: 63
Joined: Sat Jun 16, 2012 11:12 am
Country: Australia
Location: NSW

Re: Error writing eeprom data

Post by Greebo »

For the benefit of people searching for my same problem... I've attached a few files of hex data (not quite in the "Intel Hex format" that avrdude expects but easy to compare with the eye)

First is "correct.hex" which is a direct dump of the eeprom immediately after it has been formatted in the Tx.
correct.hex
(9.5 KiB) Downloaded 755 times
Second is "eepe_default.hex" which is the "default" eepe settings
eepe_default.hex
(7 KiB) Downloaded 750 times
Lastly is "bad.hex" which is what gets written to my eeprom using the Arduino when I try to write the "Intel Hex format" version of "eepe_default.hex" using either eepe or avrdude directly.
bad.hex
(9.5 KiB) Downloaded 704 times
What is very interesting though is that it looks like the memory locations being written to by the Arduino are all screwed up.
Blocks ARE always being written correctly, but in the wrong locations (8 bytes out every time and then wrapped from 1024 back to 0)

Here's the top section of the default formatted eeprom:

Code: Select all

0000  04 40 0c 10 04 41 10 09  24 20 00 00 00 00 00 00
0010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
0020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
0030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
0040  05 30 0a 00 02 00 02 00  02 00 02 00 02 00 02 00
0050  06 02 80 01 80 01 80 01  80 01 80 01 80 01 80 01
0060  07 80 01 80 01 80 01 80  01 80 01 80 01 80 01 80
0070  08 15 00 19 5a 94 01 01  8c 0a 4d 45 20 20 20 20
0080  00 20 20 20 20 85 00 00  ff ff ff ff ff ff ff ff
0090  0a 0a 4d 4f 44 45 4c 30  31 20 20 20 90 03 01 01
00a0  0b 64 87 03 02 03 64 87  03 03 02 64 87 03 04 04
00b0  00 64 ff ff ff ff fa 00  ff ff ff ff ff ff ff ff
00c0  0d 00 00 00 00 00 00 00  ff ff ff ff ff ff ff ff 
00d0  0e 00 00 00 00 00 00 00  ff ff ff ff ff ff ff ff
00e0  0f 00 00 00 00 00 00 00  ff ff ff ff ff ff ff ff
00f0  10 00 00 00 00 00 00 00  ff ff ff ff ff ff ff ff
Here's the same section of the eepe default eeprom file:

Code: Select all

0000  04 40 0C 10 04 3F 10 09  24 20 00 00 00 00 00 00
0010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
0020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
0030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
0040  05 30 0A 00 02 00 02 00  02 00 02 00 02 00 02 00
0050  06 02 80 01 80 01 80 01  80 01 80 01 80 01 80 01
0060  07 80 01 80 01 80 01 80  01 80 01 80 01 80 01 80
0070  08 15 00 19 5A A1 0B 47  72 65 65 62 6F 20 20 20
0080  00 20 08 84 20 85 00 00  00 00 00 00 00 00 00 00
0090  0A 0A 4D 4F 44 45 4C 30  31 20 20 20 90 03 01 01
00a0  0B 64 87 03 02 02 64 87  03 03 03 64 87 03 04 04
00b0  00 64 FF FF FF FF EE 00  00 00 00 00 00 00 00 00
00c0  0D 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
00d0  0E 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
00e0  0F 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
00f0  10 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
And here's the section that I read back from the eeprom after writing the eepe default eeprom file:

Code: Select all

0000  41 00 00 00 00 00 00 00  24 20 00 00 00 00 00 00
0010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
0020  42 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
0030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
0040  05 00 00 00 00 00 00 00  02 00 02 00 02 00 02 00
0050  06 00 00 00 00 00 00 00  80 01 80 01 80 01 80 01
0060  07 00 00 00 00 00 00 00  01 80 01 80 01 80 01 80
0070  08 00 00 00 00 00 00 00  8c 0a 4d 45 20 20 20 20
0080  09 00 00 00 00 00 00 00  ff ff ff ff ff ff ff ff
0090  0a 00 00 00 00 00 00 00  31 20 20 20 90 03 01 01
00a0  0b 00 00 00 00 00 00 00  03 03 02 64 87 03 04 04|
00b0  00 00 00 00 00 00 00 00  ff ff ff ff ff ff ff ff
00c0  47 00 00 00 00 00 00 00  ff ff ff ff ff ff ff ff
00d0  00 00 00 00 00 00 00 00  ff ff ff ff ff ff ff ff
00e0  48 00 00 00 00 00 00 00  ff ff ff ff ff ff ff ff
00f0  00 00 00 00 00 00 00 00  ff ff ff ff ff ff ff ff
Hopefully you can quickly see that the second 8 bytes on each line has not been touched by the eeprom write (they still match the "Tx formatted" values), yet the first 8 bytes on each line have, starting with the data in location 0x0000 actually come from location 0x0400 in the file!
So eeprom location 0x000 contains the 8 bytes of data from file location 0x0400, eeprom location 0x0010 contains the 8 bytes from file location 0x0408, etc. I am going to assume that at the start, 0x0000 contained 8 bytes from 0x0000 and then 0x0010 contained the 8 bytes from 0x0008, but eventually it "wrapped" at 1024 and started writing from 0x0400 which is why its so out.

I think ArduinoISP is misinterpreting the location avrdude is specifying so my next step is to figure out where the ArduinoISP sketch is going wrong and hopefully fix it.

If you have an Arduino and a problem writing your 9x eeprom... watch this space ( I hope!)
Romolo
9x Developer
Posts: 1109
Joined: Sat Dec 31, 2011 12:11 am
Country: -
Location: Massa (MS), Tuscany, Italy

Re: Error writing eeprom data

Post by Romolo »

Which ArduinoISP are you using ?
someone told 1.01 should be fixed
i also know that 0.22 is working as well
Romolo
9x Developer
Posts: 1109
Joined: Sat Dec 31, 2011 12:11 am
Country: -
Location: Massa (MS), Tuscany, Italy

Re: Error writing eeprom data

Post by Romolo »

Greebo
Posts: 63
Joined: Sat Jun 16, 2012 11:12 am
Country: Australia
Location: NSW

Re: Error writing eeprom data

Post by Greebo »

Sorry, but I'm not sure what you're saying? That post specifically relates to an out of sync error (A bug specific to arduino 1.0 - Which I have never had).

I have already tried 022 (and 023) and I get exactly the same behaviour... but only when writing the eeprom, not the flash.
Looking at the Arduino sketch, writing flash and eeprom are two totally different functions, which explains why one works and the other doesn't.
Greebo
Posts: 63
Joined: Sat Jun 16, 2012 11:12 am
Country: Australia
Location: NSW

Re: Error writing eeprom data - SOLVED

Post by Greebo »

I've finally gotten to the bottom of it all. eepe and companion9x are happily reading and writing my eeprom via the Arduino with no verification errors or invalid file issues.

It seems that unlike most ATmega chips, the m64 addresses its eeprom by byte instead of by word. Apparently this is handled by most of the AVR programmers out there but NOT by the ArduinoISP sketch.

If you have an Arduino and wish to use it to program your 9x you will need to do this:

Start Arduino IDE 1.01 and load up the Examples -> ArduinoISP sketch, search for the two places (one in the eeprom_write and the other in the eeprom_read) which look like:

Code: Select all

  // here is a word address, get the byte address
  int start = here * 2;
Replace it with:

Code: Select all

  // here is a word address, get the byte address - NOT an an m64!
  int start = here; // * 2; - NA for m64
I just saved the modified sketch as ArduinoISP_m64 so I can still load up the original one if I need to program other devices.

I hope someone else find this useful and thanks to everyone for your input.
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Error writing eeprom data - SOLVED

Post by jhsa »

hey, you did it.. ;) :D
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Error writing eeprom data - SOLVED

Post by MikeB »

I thought *all* the Atmel chips used bytes addressing for the EEPROM. They may well use word addressing for the flash.
I've read and written the EEPROM on a Mega128 the same as a M64.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Greebo
Posts: 63
Joined: Sat Jun 16, 2012 11:12 am
Country: Australia
Location: NSW

Re: Error writing eeprom data - SOLVED

Post by Greebo »

MikeB wrote:I thought *all* the Atmel chips used bytes addressing for the EEPROM. They may well use word addressing for the flash.
I've read and written the EEPROM on a Mega128 the same as a M64.
That could well be the case and maybe nobody has ever written/read an eeprom using ArduinoISP?

I did find (afterwards of course!) references to this in the Arduino bug logs submitted about November last year... but it doesn't seem to have filtered into the release yet. I think the avrdude.conf probably has info about how to address flash/eeprom per device and it probably passes it to the AVR programmer... I'd guess ArduinoISP isn't paying attention to those settings.

If my real job ever lets up, I might have a look through the avrdude source code and see if I can work out what needs to be updated in the sketch to do this properly.
nikitz
Posts: 3
Joined: Sun Jul 08, 2012 5:19 am
Country: -

Re: Error writing eeprom data - SOLVED

Post by nikitz »

Thanks to Greebo.

Now I can read the eeprom of my TX. I am using arduino nano with sw version 101. The only things I have done was to modify the original
ISP sketch as Greebo said.

it works
GlidingFool
Posts: 26
Joined: Mon May 14, 2012 3:16 am
Country: Australia

Re: Error writing eeprom data - SOLVED

Post by GlidingFool »

Greebo

I am in a similar boat to you. I used an Arduino Deumolinove and the Arduino 0022 software to download the original firmware and then install Open9x. Since then I have not been able to get it to work using any version of the Arduino software. I am double, triple and quadruple checking my wiring and have a USBASP on order : (.

The good news is that I am flying with the radio with FrSky modules : ) (no telemetry)

When I try to use Companion9x, the Arduino board crashes and AVRDude tells me that the programmer is not responding.

Verbose mode gives me exactly the same info as yours up to:

Reading | ################################################## | 100% 0.09s

Shame I don't get that.

Cheers from Oz
Greebo
Posts: 63
Joined: Sat Jun 16, 2012 11:12 am
Country: Australia
Location: NSW

Re: Error writing eeprom data - SOLVED

Post by Greebo »

How do you know the arduino crashes? Maybe some photos of your setup?

Try using avrdude directly from a command prompt (assuming Windows here)....
avrdude.exe -c avrisp -p m64 -b 19200 -P com9 -t
(change the com port to match yours)

That puts avrdude into terminal mode, then you can issue commands directly.
Try this:
dump eeprom 00 64

which should dump out the first 64 bytes of the eeprom.... Let me know the results.
geekystar
Posts: 4
Joined: Sun Sep 09, 2012 11:54 pm
Country: -

Re: Error writing eeprom data - SOLVED

Post by geekystar »

Hi Greebo

I cannot say enough "thanks" to you! Your hard work saved me many days of misery.

I programmed my 9x with open9x successfully with ArduinioISP. So I thought it works well and started programming my models. Then tried to use campanion9x to read the model, faced with the same error.

Thought the backup and restore option would work when update the firmware, I bravely did so. And disaster stroke. All my model settings are now lost after the forced formating of EEPROM.

I had to spend many hours browsing through this forum to find your post showing the same issues I had and the solution. Now everything works perfect.

I think the solution deserves to be put in a more published place so many others sharing the same pain would find out the answer easier.
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Error writing eeprom data - SOLVED

Post by ShowMaster »

Just wondering what the solution is?


ShowMaster
Sent from my iPod touch using Tapatalk
geekystar
Posts: 4
Joined: Sun Sep 09, 2012 11:54 pm
Country: -

Re: Error writing eeprom data - SOLVED

Post by geekystar »

As indicated in Greebo's post, need to change 2 places in the Arduino code.

Sent from my Galaxy Note using Tapatalk 2
Greebo
Posts: 63
Joined: Sat Jun 16, 2012 11:12 am
Country: Australia
Location: NSW

Re: Error writing eeprom data - SOLVED

Post by Greebo »

geekystar wrote:Hi Greebo
I cannot say enough "thanks" to you! Your hard work saved me many days of misery.
[...snip...]
I had to spend many hours browsing through this forum to find your post showing the same issues I had and the solution. Now everything works perfect.
I think the solution deserves to be put in a more published place so many others sharing the same pain would find out the answer easier.
Glad it worked for you!

If you search for "Arduino eeprom" on the forum it comes up near (or at) the top in the search results... You can't sticky everything :)
I've edited the first post with a link to the "solution post".... hopefully that will speed the search up for others in future.
geekystar
Posts: 4
Joined: Sun Sep 09, 2012 11:54 pm
Country: -

Re: Error writing eeprom data - SOLVED

Post by geekystar »

Yes looking back it looks obvious enough. But at the time I was not quite sure whether it was the issue with companion9x, the programmer, the firmware or the 9x itself.

Sent from my Galaxy Note using Tapatalk 2
acefx
Posts: 18
Joined: Fri Jan 18, 2013 3:04 am
Country: -

Re: Error writing eeprom data - SOLVED

Post by acefx »

Thanks Greebo
Without your modification i wasn't able to read or write eeprom,
My hardware is Arduino Nano 328 Win7 Arduino 1.5.2 (beta)

First i had a recurent error with Arduino 1.0.1, STK500 error, could write up the program.

Then succeed to write arduinoISP on ARduino 1.5.2 ( great !!! )
The only problem was that i didn't succeed reading and writting the EEprom,
i could only flash the transmiter.
Now with the script mod, everything is great and flawless !!!!

Tutorial for the ARDUINO NANO 328

So the correct way to program 9x / 9xr ( tried both ) with an arduino NANO atmel328 is
Arduino 1.5.2
Specifie the correct board in TOOLS / BOARD ---> NANO
Then in TOOLS / PROCCESSOR --->328
Load this scketch

Code: Select all

// ArduinoISP version 04m3
// Copyright (c) 2008-2011 Randall Bohn
// If you require a license, see 
//     http://www.opensource.org/licenses/bsd-license.php
//
// This sketch turns the Arduino into a AVRISP
// using the following arduino pins:
//
// pin name:    not-mega:         mega(1280 and 2560)
// slave reset: 10:               53 
// MOSI:        11:               51 
// MISO:        12:               50 
// SCK:         13:               52 
//
// Put an LED (with resistor) on the following pins:
// 9: Heartbeat   - shows the programmer is running
// 8: Error       - Lights up if something goes wrong (use red if that makes sense)
// 7: Programming - In communication with the slave
//
// 23 July 2011 Randall Bohn
// -Address Arduino issue 509 :: Portability of ArduinoISP
// http://code.google.com/p/arduino/issues/detail?id=509
//
// October 2010 by Randall Bohn
// - Write to EEPROM > 256 bytes
// - Better use of LEDs:
// -- Flash LED_PMODE on each flash commit
// -- Flash LED_PMODE while writing EEPROM (both give visual feedback of writing progress)
// - Light LED_ERR whenever we hit a STK_NOSYNC. Turn it off when back in sync.
// - Use pins_arduino.h (should also work on Arduino Mega)
//
// October 2009 by David A. Mellis
// - Added support for the read signature command
// 
// February 2009 by Randall Bohn
// - Added support for writing to EEPROM (what took so long?)
// Windows users should consider WinAVR's avrdude instead of the
// avrdude included with Arduino software.
//
// January 2008 by Randall Bohn
// - Thanks to Amplificar for helping me with the STK500 protocol
// - The AVRISP/STK500 (mk I) protocol is used in the arduino bootloader
// - The SPI functions herein were developed for the AVR910_ARD programmer 
// - More information at http://code.google.com/p/mega-isp

#include "pins_arduino.h"
#define RESET     SS

#define LED_HB    9
#define LED_ERR   8
#define LED_PMODE 7
#define PROG_FLICKER true

#define HWVER 2
#define SWMAJ 1
#define SWMIN 18

// STK Definitions
#define STK_OK      0x10
#define STK_FAILED  0x11
#define STK_UNKNOWN 0x12
#define STK_INSYNC  0x14
#define STK_NOSYNC  0x15
#define CRC_EOP     0x20 //ok it is a space...

void pulse(int pin, int times);

void setup() {
  Serial.begin(19200);
  pinMode(LED_PMODE, OUTPUT);
  pulse(LED_PMODE, 2);
  pinMode(LED_ERR, OUTPUT);
  pulse(LED_ERR, 2);
  pinMode(LED_HB, OUTPUT);
  pulse(LED_HB, 2);
}

int error=0;
int pmode=0;
// address for reading and writing, set by 'U' command
int here;
uint8_t buff[256]; // global block storage

#define beget16(addr) (*addr * 256 + *(addr+1) )
typedef struct param {
  uint8_t devicecode;
  uint8_t revision;
  uint8_t progtype;
  uint8_t parmode;
  uint8_t polling;
  uint8_t selftimed;
  uint8_t lockbytes;
  uint8_t fusebytes;
  int flashpoll;
  int eeprompoll;
  int pagesize;
  int eepromsize;
  int flashsize;
} 
parameter;

parameter param;

// this provides a heartbeat on pin 9, so you can tell the software is running.
uint8_t hbval=128;
int8_t hbdelta=8;
void heartbeat() {
  if (hbval > 192) hbdelta = -hbdelta;
  if (hbval < 32) hbdelta = -hbdelta;
  hbval += hbdelta;
  analogWrite(LED_HB, hbval);
  delay(20);
}


void loop(void) {
  // is pmode active?
  if (pmode) digitalWrite(LED_PMODE, HIGH); 
  else digitalWrite(LED_PMODE, LOW);
  // is there an error?
  if (error) digitalWrite(LED_ERR, HIGH); 
  else digitalWrite(LED_ERR, LOW);

  // light the heartbeat LED
  heartbeat();
  if (Serial.available()) {
    avrisp();
  }
}

uint8_t getch() {
  while(!Serial.available());
  return Serial.read();
}
void fill(int n) {
  for (int x = 0; x < n; x++) {
    buff[x] = getch();
  }
}

#define PTIME 30
void pulse(int pin, int times) {
  do {
    digitalWrite(pin, HIGH);
    delay(PTIME);
    digitalWrite(pin, LOW);
    delay(PTIME);
  } 
  while (times--);
}

void prog_lamp(int state) {
  if (PROG_FLICKER)
    digitalWrite(LED_PMODE, state);
}

void spi_init() {
  uint8_t x;
  SPCR = 0x53;
  x=SPSR;
  x=SPDR;
}

void spi_wait() {
  do {
  } 
  while (!(SPSR & (1 << SPIF)));
}

uint8_t spi_send(uint8_t b) {
  uint8_t reply;
  SPDR=b;
  spi_wait();
  reply = SPDR;
  return reply;
}

uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
  uint8_t n;
  spi_send(a); 
  n=spi_send(b);
  //if (n != a) error = -1;
  n=spi_send(c);
  return spi_send(d);
}

void empty_reply() {
  if (CRC_EOP == getch()) {
    Serial.print((char)STK_INSYNC);
    Serial.print((char)STK_OK);
  } 
  else {
    error++;
    Serial.print((char)STK_NOSYNC);
  }
}

void breply(uint8_t b) {
  if (CRC_EOP == getch()) {
    Serial.print((char)STK_INSYNC);
    Serial.print((char)b);
    Serial.print((char)STK_OK);
  } 
  else {
    error++;
    Serial.print((char)STK_NOSYNC);
  }
}

void get_version(uint8_t c) {
  switch(c) {
  case 0x80:
    breply(HWVER);
    break;
  case 0x81:
    breply(SWMAJ);
    break;
  case 0x82:
    breply(SWMIN);
    break;
  case 0x93:
    breply('S'); // serial programmer
    break;
  default:
    breply(0);
  }
}

void set_parameters() {
  // call this after reading paramter packet into buff[]
  param.devicecode = buff[0];
  param.revision   = buff[1];
  param.progtype   = buff[2];
  param.parmode    = buff[3];
  param.polling    = buff[4];
  param.selftimed  = buff[5];
  param.lockbytes  = buff[6];
  param.fusebytes  = buff[7];
  param.flashpoll  = buff[8]; 
  // ignore buff[9] (= buff[8])
  // following are 16 bits (big endian)
  param.eeprompoll = beget16(&buff[10]);
  param.pagesize   = beget16(&buff[12]);
  param.eepromsize = beget16(&buff[14]);

  // 32 bits flashsize (big endian)
  param.flashsize = buff[16] * 0x01000000
    + buff[17] * 0x00010000
    + buff[18] * 0x00000100
    + buff[19];

}

void start_pmode() {
  spi_init();
  // following delays may not work on all targets...
  pinMode(RESET, OUTPUT);
  digitalWrite(RESET, HIGH);
  pinMode(SCK, OUTPUT);
  digitalWrite(SCK, LOW);
  delay(50);
  digitalWrite(RESET, LOW);
  delay(50);
  pinMode(MISO, INPUT);
  pinMode(MOSI, OUTPUT);
  spi_transaction(0xAC, 0x53, 0x00, 0x00);
  pmode = 1;
}

void end_pmode() {
  pinMode(MISO, INPUT);
  pinMode(MOSI, INPUT);
  pinMode(SCK, INPUT);
  pinMode(RESET, INPUT);
  pmode = 0;
}

void universal() {
  int w;
  uint8_t ch;

  fill(4);
  ch = spi_transaction(buff[0], buff[1], buff[2], buff[3]);
  breply(ch);
}

void flash(uint8_t hilo, int addr, uint8_t data) {
  spi_transaction(0x40+8*hilo, 
  addr>>8 & 0xFF, 
  addr & 0xFF,
  data);
}
void commit(int addr) {
  if (PROG_FLICKER) prog_lamp(LOW);
  spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0);
  if (PROG_FLICKER) {
    delay(PTIME);
    prog_lamp(HIGH);
  }
}

//#define _current_page(x) (here & 0xFFFFE0)
int current_page(int addr) {
  if (param.pagesize == 32)  return here & 0xFFFFFFF0;
  if (param.pagesize == 64)  return here & 0xFFFFFFE0;
  if (param.pagesize == 128) return here & 0xFFFFFFC0;
  if (param.pagesize == 256) return here & 0xFFFFFF80;
  return here;
}


void write_flash(int length) {
  fill(length);
  if (CRC_EOP == getch()) {
    Serial.print((char) STK_INSYNC);
    Serial.print((char) write_flash_pages(length));
  } 
  else {
    error++;
    Serial.print((char) STK_NOSYNC);
  }
}

uint8_t write_flash_pages(int length) {
  int x = 0;
  int page = current_page(here);
  while (x < length) {
    if (page != current_page(here)) {
      commit(page);
      page = current_page(here);
    }
    flash(LOW, here, buff[x++]);
    flash(HIGH, here, buff[x++]);
    here++;
  }

  commit(page);

  return STK_OK;
}

#define EECHUNK (32)
uint8_t write_eeprom(int length) {
  // here is a word address, get the byte address
   int start = here; // * 2; - NA for m64
  int remaining = length;
  if (length > param.eepromsize) {
    error++;
    return STK_FAILED;
  }
  while (remaining > EECHUNK) {
    write_eeprom_chunk(start, EECHUNK);
    start += EECHUNK;
    remaining -= EECHUNK;
  }
  write_eeprom_chunk(start, remaining);
  return STK_OK;
}
// write (length) bytes, (start) is a byte address
uint8_t write_eeprom_chunk(int start, int length) {
  // this writes byte-by-byte,
  // page writing may be faster (4 bytes at a time)
  fill(length);
  prog_lamp(LOW);
  for (int x = 0; x < length; x++) {
    int addr = start+x;
    spi_transaction(0xC0, (addr>>8) & 0xFF, addr & 0xFF, buff[x]);
    delay(45);
  }
  prog_lamp(HIGH); 
  return STK_OK;
}

void program_page() {
  char result = (char) STK_FAILED;
  int length = 256 * getch();
  length += getch();
  char memtype = getch();
  // flash memory @here, (length) bytes
  if (memtype == 'F') {
    write_flash(length);
    return;
  }
  if (memtype == 'E') {
    result = (char)write_eeprom(length);
    if (CRC_EOP == getch()) {
      Serial.print((char) STK_INSYNC);
      Serial.print(result);
    } 
    else {
      error++;
      Serial.print((char) STK_NOSYNC);
    }
    return;
  }
  Serial.print((char)STK_FAILED);
  return;
}

uint8_t flash_read(uint8_t hilo, int addr) {
  return spi_transaction(0x20 + hilo * 8,
  (addr >> 8) & 0xFF,
  addr & 0xFF,
  0);
}

char flash_read_page(int length) {
  for (int x = 0; x < length; x+=2) {
    uint8_t low = flash_read(LOW, here);
    Serial.print((char) low);
    uint8_t high = flash_read(HIGH, here);
    Serial.print((char) high);
    here++;
  }
  return STK_OK;
}

char eeprom_read_page(int length) {
  // here again we have a word address
   int start = here; // * 2; - NA for m64
  for (int x = 0; x < length; x++) {
    int addr = start + x;
    uint8_t ee = spi_transaction(0xA0, (addr >> 8) & 0xFF, addr & 0xFF, 0xFF);
    Serial.print((char) ee);
  }
  return STK_OK;
}

void read_page() {
  char result = (char)STK_FAILED;
  int length = 256 * getch();
  length += getch();
  char memtype = getch();
  if (CRC_EOP != getch()) {
    error++;
    Serial.print((char) STK_NOSYNC);
    return;
  }
  Serial.print((char) STK_INSYNC);
  if (memtype == 'F') result = flash_read_page(length);
  if (memtype == 'E') result = eeprom_read_page(length);
  Serial.print(result);
  return;
}

void read_signature() {
  if (CRC_EOP != getch()) {
    error++;
    Serial.print((char) STK_NOSYNC);
    return;
  }
  Serial.print((char) STK_INSYNC);
  uint8_t high = spi_transaction(0x30, 0x00, 0x00, 0x00);
  Serial.print((char) high);
  uint8_t middle = spi_transaction(0x30, 0x00, 0x01, 0x00);
  Serial.print((char) middle);
  uint8_t low = spi_transaction(0x30, 0x00, 0x02, 0x00);
  Serial.print((char) low);
  Serial.print((char) STK_OK);
}
//////////////////////////////////////////
//////////////////////////////////////////


////////////////////////////////////
////////////////////////////////////
int avrisp() { 
  uint8_t data, low, high;
  uint8_t ch = getch();
  switch (ch) {
  case '0': // signon
    error = 0;
    empty_reply();
    break;
  case '1':
    if (getch() == CRC_EOP) {
      Serial.print((char) STK_INSYNC);
      Serial.print("AVR ISP");
      Serial.print((char) STK_OK);
    }
    break;
  case 'A':
    get_version(getch());
    break;
  case 'B':
    fill(20);
    set_parameters();
    empty_reply();
    break;
  case 'E': // extended parameters - ignore for now
    fill(5);
    empty_reply();
    break;

  case 'P':
    start_pmode();
    empty_reply();
    break;
  case 'U': // set address (word)
    here = getch();
    here += 256 * getch();
    empty_reply();
    break;

  case 0x60: //STK_PROG_FLASH
    low = getch();
    high = getch();
    empty_reply();
    break;
  case 0x61: //STK_PROG_DATA
    data = getch();
    empty_reply();
    break;

  case 0x64: //STK_PROG_PAGE
    program_page();
    break;

  case 0x74: //STK_READ_PAGE 't'
    read_page();    
    break;

  case 'V': //0x56
    universal();
    break;
  case 'Q': //0x51
    error=0;
    end_pmode();
    empty_reply();
    break;

  case 0x75: //STK_READ_SIGN 'u'
    read_signature();
    break;

    // expecting a command, not CRC_EOP
    // this is how we can get back in sync
  case CRC_EOP:
    error++;
    Serial.print((char) STK_NOSYNC);
    break;

    // anything else we will return STK_UNKNOWN
  default:
    error++;
    if (CRC_EOP == getch()) 
      Serial.print((char)STK_UNKNOWN);
    else
      Serial.print((char)STK_NOSYNC);
  }
}


The led on Board should blink Bright for 5/7 sec during programing
Then make the correct wiring to the 9x/9xr :
// slave reset: d10:
// MOSI: d11:
// MISO: d12:
// SCK: d13:
and of course 5v/gnd to VCC and GROUND

Open Companion 9X
In AVRDUDE config
AVRISP
M64
COMX ( where X is your comport )
add line -b 19200 at the end

and GOGOGOGOGO

Ps: The 9xR normaly startup when you plug the Arduino nano
stupid thing because sometime the voltage from your arduino is not sufficient to power and program the whole thing.
To help the arduino you can power up the TX itself, and disconnect the 5V pin on the Arduino.

Hope it will help someone.
pin on it

Post Reply

Return to “PROGRAMMERS”