{"id":321,"date":"2008-03-02T13:49:08","date_gmt":"2008-03-02T12:49:08","guid":{"rendered":"http:\/\/www.evertdekker.com\/wp\/?p=321"},"modified":"2015-08-03T16:01:19","modified_gmt":"2015-08-03T15:01:19","slug":"i2c-eeprom-programmer","status":"publish","type":"post","link":"https:\/\/evertdekker.com\/wp\/?p=321","title":{"rendered":"I2C Eeprom programmer"},"content":{"rendered":"<hr \/>\n<p><strong>What is it?<\/strong><br \/>\nIt\u2019s an Eeprom programmer controlled by Bascom Avr and is capable of programming in circuit Eeprom\u2019s up to 512Kb. Standard Intel Hex8 file is required.<br \/>\nExtended Linear Address Records for Eeprom\u2019s bigger then 16bits addresses is not (yet) supported, but easy to implant.<br \/>\nI wrote it primary for my other application note <a href=\"http:\/\/www.evertdekker.com\/wp\/?p=323\">RC2 sound \/ voice playback<\/a> to upload the sound files to the i2c Eeprom.<br \/>\nSpecial thanks to Mark from <a href=\"http:\/\/mcselec.com\">Mcselec<\/a> how has added in the vb6 an asm to intelhex routine so Atmel studio is not needed anymore.<\/p>\n<p><strong>Required tools<\/strong><br \/>\nFor the Pc side there\u2019s an <a href=\"http:\/\/evertdekker.com\/Joomla\/images\/stories\/Downloads\/EEpromprog_Setup.zip\">upload program<\/a> that sends the Intel Hex file to the AVR.<br \/>\nProgram is written in VB6-Sp6, <a href=\"http:\/\/evertdekker.com\/Joomla\/images\/stories\/Downloads\/EEpromProg_sourceVB6.zip\">source code<\/a> is also available.<\/p>\n<p><strong>The code<\/strong><br \/>\nCode is written and tested in Bascom 1.11.9.0.001 license.<br \/>\nDownload the Bascom source code <a href=\"http:\/\/evertdekker.com\/Joomla\/images\/stories\/CodeVault\/i2cEepromProgrammer\/i2c_eeprom_programmer.bas\">here<\/a><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: vb; gutter: true\">&#039;--------------------------------------------------------------------\r\n&#039;                       I2C Eeprom programmer\r\n&#039;Upload your Eeprom files through serial connection in the I2c Eeprom\r\n&#039;       No extended address supported, so max 512K Eeprom\r\n&#039;     By Evert Dekker 2008 i2cprogrammer@Evertdekker dotje com\r\n&#039;                Created with Bascom-Avr: 1.11.9.0.100\r\n&#039;--------------------------------------------------------------------\r\n\r\n$regfile = &quot;m128def.DAT&quot;\r\n$crystal = 16000000\r\n$baud = 19200\r\n$hwstack = 70\r\n$swstack = 70\r\n$framesize = 60\r\n\r\n$lib &quot;I2C_TWI.LBX&quot;                                          &#039;Setting up i2c hardware bus\r\nConfig Twi = 400000                                         &#039;Hardware i2c bus speed\r\nConfig Scl = Portd.0                                        &#039;TWI (i2c) ports on the Mega128\r\nConfig Sda = Portd.1\r\nConst Addressw = &amp;B10100000                                 &#039;slave write address eeprom\r\nConst Addressr = &amp;B10100001                                 &#039;slave read address eeprom\r\n\r\n\r\nDim Startbyte As Byte , Instring As String * 45 , Complete As Bit\r\nDim Temp As Byte , Temps As String * 3\r\nDim Bytecount As Byte , Addresshigh As Byte , Addresslow As Byte , Recordtype As Byte , Databyte(16) As Byte , Checksm As Byte\r\nDim Lus As Byte , Pos As Byte , Checksum_calc As Byte , Checksum_error As Bit\r\n\r\nEnable Urxc\r\nEnable Interrupts\r\nOn Urxc Bytereceived_isr\r\n\r\n\r\n&#039;=== Main  ===\r\nDo\r\nIf Complete = 1 Then                                        &#039;Wait until the buffer is filled with one line\r\n  Gosub Process_buffer                                      &#039;Process the buffer\r\n  Gosub Calculate_checksum                                  &#039;Calculate the cheksum\r\n     If Recordtype = &amp;H01 Then                              &#039;EOF finished, send a ACK and return\r\n      Print &quot;Y&quot;;\r\n     Else\r\n       If Checksum_error = 0 Then                           &#039;If there&#039;s no error continue\r\n         Select Case Recordtype                             &#039;do something with the recordtype\r\n            Case &amp;H00                                       &#039;Data byte\r\n                Gosub Prog_eeprom                           &#039;Recordtype &amp;H00 = databyte, so lets programm the Eeprom\r\n            Case &amp;H02                                       &#039;Extended Linear Address Records, not (yet) supported\r\n               nop\r\n         End Select\r\n       Print &quot;Y&quot;;                                           &#039;Checksum ok, send a ACK\r\n      Else\r\n       Print &quot;Z&quot;;                                           &#039;Checksum error send a Nack\r\n     End If\r\n    End If\r\n  Complete = 0 : Instring = &quot;&quot;                              &#039;Reset the variable\r\nEnd If\r\nLoop\r\nEnd\r\n\r\n\r\n&#039;=== Subroutines ===\r\nProg_eeprom:\r\n    I2cstart                                                &#039;start condition\r\n    I2cwbyte Addressw                                       &#039;slave address\r\n    I2cwbyte Addresshigh                                    &#039;Highaddress of EEPROM\r\n    I2cwbyte Addresslow                                     &#039;Lowaddress of EEPROM\r\n       For Lus = 1 To Bytecount\r\n         I2cwbyte Databyte(lus)                             &#039;value to write\r\n       Next Lus\r\n    I2cstop                                                 &#039;stop condition\r\n    Waitms 10                                               &#039;wait for 10 milliseconds\r\nReturn\r\n\r\n\r\nProcess_buffer:\r\nTemps = Mid(instring , 1 , 2) : Bytecount = Hexval(temps)   &#039;Read the numbers of bytes\r\nTemps = Mid(instring , 3 , 2) : Addresshigh = Hexval(temps) &#039;Read the high adress\r\nTemps = Mid(instring , 5 , 2) : Addresslow = Hexval(temps)  &#039;Read the low adress\r\nTemps = Mid(instring , 7 , 2) : Recordtype = Hexval(temps)  &#039;Read the recordtype\r\nFor Lus = 1 To Bytecount                                    &#039;Process the number of data bytes\r\n      Pos = Lus * 2\r\n      Pos = Pos + 7\r\n      Temps = Mid(instring , Pos , 2) : Databyte(lus) = Hexval(temps)       &#039;Read the databytes\r\nNext Lus\r\nPos = Pos + 2                                               &#039;read the last byte\r\nTemps = Mid(instring , Pos , 2) : Checksm = Hexval(temps)   &#039;Read checksum\r\nReturn\r\n\r\n\r\nCalculate_checksum:\r\nTemp = 0                                                    &#039;Add up all the databytes\r\nTemp = Temp + Bytecount\r\nTemp = Temp + Addresshigh\r\nTemp = Temp + Addresslow\r\nTemp = Temp + Recordtype\r\n   For Lus = 1 To Bytecount\r\n    Temp = Temp + Databyte(lus)\r\n   Next Lus\r\nChecksum_calc = 256 - Temp                                  &#039;taking its two&#039;s complement\r\n   If Checksum_calc &lt;&gt; Checksm Then                         &#039;Compare it with the readed value\r\n    Checksum_error = 1\r\n   Else\r\n    Checksum_error = 0\r\n   End If\r\nReturn\r\n\r\nBytereceived_isr:\r\nTemp = Udr                                                  &#039;get the binary value that came across\r\nIf Temp = &amp;H0D Then                                         &#039;Received CR = end of line, line complete\r\n If Len(instring) &lt; 8 Then                                  &#039;To short, startover again\r\n   Complete = 0\r\n   Instring = &quot;&quot;\r\n Else\r\n   Complete = 1                                             &#039;String is complete set the flag\r\n End If\r\nEnd If\r\n\r\nIf Startbyte = &amp;H3A Then                                    &#039;we have previously received the start byte and this is now data\r\n  If Temp &gt; &amp;H0F Then                                       &#039;Add incoming data to buffer\r\n     Instring = Instring + Chr(temp)\r\n    If Len(instring) &gt; 45 Then Instring = &quot;&quot;                &#039;String is to long, reset and startover again\r\n End If\r\nEnd If\r\n\r\nIf Temp = &amp;H3A Then                                         &#039;if we received an : then its the beginning of an new line.\r\n   Startbyte = Temp\r\n   Complete = 0\r\n   Instring = &quot;&quot;\r\nEnd If\r\nReturn<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>What is it? It\u2019s an Eeprom programmer controlled by Bascom Avr and is capable of programming in circuit Eeprom\u2019s up to 512Kb. Standard Intel Hex8 file is required. Extended Linear Address Records for Eeprom\u2019s bigger then 16bits addresses is not (yet) supported, but easy to implant. I wrote it primary for my other application note [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[26,37,38,39],"class_list":["post-321","post","type-post","status-publish","format-standard","hentry","category-bascom","tag-bascom","tag-eeprom","tag-i2c","tag-programmer"],"_links":{"self":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=321"}],"version-history":[{"count":5,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions"}],"predecessor-version":[{"id":337,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions\/337"}],"wp:attachment":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}