Hello there Im working on a project based on arduino and I would like to get you involved in it.

What I'm trying to do is an arduino reader and writer for spi, i2c and parallel eeproms. When I finish this project I will make it fully open source and I will share it with all of you so because of that I want to hear your opinion what should be done, what to consider as option in software, code look up to see if I missed something and so on.

So far I came up with this:

I already started writing code for SPI and I figure out it will be hard to make it as simple as possible but still easy to adopt to any eeprom. So here I have a question about ready bit in status register. Many of manufacturers calls them RDY but winbond calls it BUSY instead so how give a clue to user when searching the datasheet what to look for?

In the attachment is visual basic code for windows side app and here is an arduino part:

Cant figure out what is the problem so can someone please assist trying to find out solution?

So when I send cs pin number from pc to arduino I get correct replay from arduino. then it goes cs pin active low or high over serial and sure enough arduino replay received data to pc and stores that information i variable.

next data going over serial is write protect pin number and for example I send as string number 3 and arduino replays back number 3 to pc. Then pc sends active low or high for write protect pin and instead receiving number 1 or 2 from arduino Im getting "pin number + active low or high" like 31 or if i define wp pin as 4 as replay I got 41 or 42.

I tried to send integer and string value over serial and Im getting the same results.

Ive find out that sometimes fails on cs in too. seems like it have something to do with the serial buffer ? not really sure whats wrong but I think I will send whole bunch of configuration data as one string and on arduino receive it as char array... should work. Im just not shure what is going to happen when I start receiving eeprom data over the serial. I might encounter same problem again :/

I managed to solve the issue by sending everything as string to the arduino, as backup if that wont work i was planing to send all configuration as one big string and then separate characters on arduino but luckily this worked out

With this modification and with only one function added I managed to shrink code length by almost 500 lines, so it looks nicer and more organized now

For application to be as versatile as possible I will communicate with eeprom by shiftout and shiftin functions so that you can use any pin you want.

At the moment I implemented nano, mega and due in code, any suggestions for any other board?

Ive figure out that I will need to change GUI a bit because there is no need for SCK active low or high same as data in and out and I will remove opcode for read and write status register same as read status bits. I designed it with only basic knowledge about spi communication so as I learn I will edit GUI accordingly

Some update... Well I made it, it seems like Im on the right track but there is still whole bunch of things to do.

Anyway after wasting 3+ hours on debugging why I cant't get any replay from eeprom Ive figure out that I declared miso and mosi on arduino as output pins. Imagine my face after figuring out what mistake I did

anyway so far so good

Ive read BIOS eeprom (4MB) W25X40 and data don't have scene by looking at it with hex editor... Have no idea what decoding I should use to get something useful out of it.

I saved just part of code... maybe that part was post screen image, have no idea but I might consider to implement ability to save code as binary it should be easier to decode it that way.

Ammm yea reading whole eeprom took 2 minutes for arduino not that bad if you ask me but application have some issues when writing to the grid view and reading from grid view to save data file.

So complete read from eeprom took 2min eeprom>arduino>app then app took about 30s to convert raw data to hex and then storing it to grid view took 10 minutes. There must be better way to do it but for now it is ok it works I will do fine tuning at the end

Update ... I decided to save file as binary instead of plain hex text I also added prompt window which asks when memory is greater than 512kb if you would like to show data in grid view because I was unable to speed up populating process and it takes to much time to show data in grid view if eeprom memory is greater than 512kb.

I got it slightly faster but it still takes to much time so now you have an option

Im facing now another problem, somehow im getting to much of bytes from eeprom, I cant get it how. Im trying to debug it but cant find cause. I think that serial communication is to blame..

Write and read from file returns exact value of bytes so it is not issue in reading and writing the file

I was looking what arduino and eeprom talks about and didn't find problems there so it seems that windows application makes all this trouble.

Here is arduino and visual studio part of code used to communicate to each other

From image above it is clear that arduino understood how many bytes should read otherwise it would trigger an error message "Arduino didn't acknowledge sent data packet" and indeed arduino reads epprom exact number of times, verified by analyzer.

Now I see that I misspelled "acknowledge" in code :/

Here is an image of reading the same memory with the same settings

I would understand if they lose some packets while communicating but adding "some" random number of reads extra. I don't get it

Here is visual basic code fully commented "this part is used to receive bytes from arduino"

Dim Magic_Byte As String = "" 'not part of this code Com_port_received_text = "" 'if anithing has been sent over serial get rid of it

Dim DataArray As New ArrayList 'everything sent from arduino goes to this array Dim i As String = "" 'not part of this code Do

If Not Com_port_received_text = "" Then 'if something was received

SaveArray.Add(Com_port_received_text) 'Add received text to array -> it will look like this 'SaveArray(0) = "7h90h17h49h73h96h84h136h86h153h9" 'I can get only one byte over serial but I need to add 'delay(2); to slow down arduino transmission, vb app 'can handle this string without slowing arduino down

Dim newarray As New ArrayList 'here I will save actual data received from serial

For Each Data As String In SaveArray 'Loop trough SaveArray until end, first pass will 'hold '"7h90h17h49h73h96h84h136h86h153h9"

Dim parts1() As String = Split(Data, "h") 'Data will hold "7h90h17h49h73h96h84h136h86h153h9" and 'parts1()is an array and it will be same string but 'without h character like part1(0)= 7, part1(1) = 90 'and so on

For Each Part As String In parts1 'goes trough part1 array and gets string out of it newarray.Add(Part) 'stores that string to new array, it will look same 'as in parts1() array but this array can handle 'strings, integers, longs and is easier to handle 'data in it Next Next SaveArray.Clear() 'Empty SaveArray " for later use"

For Each Part As String In newarray 'read newarray which already holds wrong number of 'bytes If Not Part = "" Then 'used to avoid exception throw

SaveArray.Add((Convert.ToInt16(Part))) 'this array is used to write binary file DataArray.Add(Hex(Convert.ToInt32(Part))) 'and this one is used to populate grid view

Serial.print("h");//Send h over serial to know where to split the string

ii = '\0';// I was thinking that maybe ii buffer hold some data //and I get extra data sent over serial so I tried to //flush ii buffer with '\0' .. . but no help at all

i++;//holds number of addresses readed

} while(i != address_length); //loop until end of eeprom in this case 0x5ffff

Hope that someone can find out what I'm missing here.

I tried also slowing down communication between arduino and computer but didn't get any improvement, also if i read only until 0x1ff or 0xfff everything works fine. it smells like I declared some variable as wrong type but I triple checked that and didn't find any problems there.

Ok so far so god... well not exactly I managed to get this thing to work but It is not clear exactly what's happening.

By the way I tried everything adding delays in various parts of code, increase/ reduce baud rate, no success...

I decided to monitor serial communication between arduino and pc and saw many weird thing happening so to keep it simple I decided to synchronize transmission between arduino and pc.

synchronization is done this way. Arduino reads eeprom 10 times and then replays 10 bytes to pc. Pc responds with ack and arduino continues reading next 10 bytes form eeprom and so on.

Here is the result

For some reason windows side app cant keep up receiving information and processing them.

without any logical explanation for this issue I decided to increase sync rate

and it worked, Im getting what I expect but if you look at the timing at the beginning of reading process application freezes for some reason.

This time arudino reads 9 bytes from eeprom and then sends them over serial. Not sure what is the difference 10 bytes shouldn't be enough to overflow arduino or vb.net serial.

Any way Im happy to see that encoding is ok. In this part of dump I can see motherboard type... gigabyte GA-M56S-S3 ... at least something works as it should

With sync I lost speed so it is something I will deal with... cant really figure out what Im doing wrong and I dont get any support from here and this is the best I can do. maybe later I will try to solve speed issue.

At the moment im still fighting with to many bytes received even with sync but only if i read eeprom over 0x1fff so this first needs to be fixed.

After some time I decided to write complete receive part of code from the beginning and it solved my problem with double sync but this time instead of sending one byte as sync I'm sending complete last received string to arduino for comparison. If transmitted and received data are not the same it will replay last transmitted data. It keeps data integrity if something goes wrong.

I did try to increase the speed of reading data from eeprom by reading more than 8-9 bites before sending them over serial but it failed almost immediately so I thought it cant be computer side problem because I did define SerialPort1.ReadBufferSize = 2000000... Should be enough right?

So I used Due instead of nano and tried to read eeprom again, it failed again as before so what next? I started to suspect that maybe arduino serial library causes the problem and decided to rewrite complete code for STM32F446 with atollic studio and HAL drivers and still I got the same result.

After quite a bit of time spent on vb net looking for patterns in the data when it fails I find out that serial receives everything from arduino but it only saves around 30 characters in variable and it triggers serial receive event twice so I should read it twice and keep the data like so.

If Me.TextBox1.InvokeRequired Then Dim x As New SetTextCallBack(AddressOf ReceivedText)

Me.BeginInvoke(x, New Object() {(text)})

ElseIf Not text = "" Then

If Com_port_received_text = "" Then Com_port_received_text = text 'Read first part Else Com_port_received_text1 = text 'Read the rest of data End If

End If text = ""

End Sub

And it work as it should so now I can read more than 8 bytes from eeprom and send them over serial.As sweet spot I decide to read 16 bytes in total it seems like I'm getting the best results when comparing how long it takes to read complete eeprom.

Also I was careful to write code without delays while receiving the data and I'm receiveing data on another thread so basically I did everything I could to get this thing to go as fast as possible. And results are not so great. max transmission rate is 1kB/s.

If Not Com_port_received_text = "" Then 'if something was received If Not Com_port_received_text.Contains("NOK") Then 'and it does not contain "NOK"

Dim iCnt As Integer = 0 For Each character As Char In Com_port_received_text If character = "h" Then iCnt += 1 'Get number of h characters received from serial Next 'used to count number of bits received from serial

TimerValue = 0 If Not iCnt = 16 And ReceivedBits + 16 <= ReadAddress_Count Then 'if there is less than 16bits received

Do 'wait the rest of the data to be received from serial If TimerValue = 10 Then GoTo NoResponse 'if nothing was received in 1second then exit loop End If Application.DoEvents() Loop While Com_port_received_text1 = ""

Com_port_received_text = Com_port_received_text + Com_port_received_text1 'combine received bits End If

DataArray.RemoveAt(DataArray.Count - 1) 'if arduino says we got wrong data remove it from array Threading.Thread.Sleep(5) 'wait some time for arduino to prepare and send again last bits GoTo Retry 'go to the begining to get last bits again End If

ElseNoResponse: TimerValue = 0 Com_port_received_text = "" Com_port_received_text1 = "" Do If Com_port_received_text1.Contains("NOK") Then 'if arduino replays with NOK Com_port_received_text1 = "" End If If TimerValue > 100 Then 'if arduino stucks after 10 seconds SerialPort1.Write("1") 'write something to get arduino going GoTo Retry End If Application.DoEvents() 'Be there until arduino responds Loop While Com_port_received_text1 = "" And Com_port_received_text = "" End If

Application.DoEvents() Loop Until Com_port_received_text = "X" 'indicates the end of transmission

Here you can see how arduino and pc handles errors

Arduino serial = RXD, pc serial = TXD

it is not visible on the image but computer didn't respond received data and arduino waits for respond. After 10s computer realizes that arduino waits for respond and it sends random bite.Then arduino send NOK because random bite is not what was sent last time and arduino replays last bytes, then communication keeps going. on the image you can see that error occurred twice.

At the moment sometimes I'm getting one byte more than I should over serial. By looking at number of positive clock cycles it is clear that arduino sometimes clocks out 8 clocks extra but it happens only if I read more than 100k addresses. Im still fighting with this issue..

It is close to impossible to track with logic analyzer what causes this problem I made simple progress bar to show number of addresses readed. So if it is a glitch in software or hardware I should be able to see on what address it stuck therefore knowing address I can easily compare data between bin file and logic analyzer.

Hello there, Im back. This time I have some great news, receiving data from eeprom seems to be fail proof.

At least it seems to be. I did some minor code changes and managed to solve all the problems. In fact im done with part of code used to read from eeprom.

I've tried to mess around with arduino's tx and rx lines while they communicate and I wasn't able to get them to fail. In fact you can disconnect tx and rx lines from pc and when you connect them back arduino will synchronize with pc and continue with transmission.

Ive tried to read more than 30 times 4Mb eeprom and it never failed but as last line of defense if it does it is smart enough to pop up error message letting you know that something went wrong.

I'm gonna take some time to clean vb code a bit because it looks like a mess and after that I will continue with coding