{"id":1179,"date":"2024-06-24T13:53:31","date_gmt":"2024-06-24T13:53:31","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=1179"},"modified":"2024-08-11T15:10:17","modified_gmt":"2024-08-11T15:10:17","slug":"memory-access","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=1179","title":{"rendered":"Memory access"},"content":{"rendered":"\n<p class=\"has-upper-heading-font-size wp-block-paragraph\"><strong>Atmel AVR microcontroller has typically three memories<\/strong><\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"541\" height=\"471\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/image-1.png\" alt=\"\" class=\"wp-image-1180\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/image-1.png 541w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/image-1-300x261.png 300w\" sizes=\"(max-width: 541px) 100vw, 541px\" \/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<ol class=\"wp-block-list\">\n<li><strong>RAM (Random Access Memory):-<\/strong> In RAM i.e. static RAM\/CRAM by the GCC compiler place for variables is reserved; also the stack is in the RAM. This memory is volatile, means contents of the variable are lost with switching off a collapse of voltage supply.<\/li>\n\n\n\n<li><strong>Program memory:- <\/strong>Implementedas Flash memory, again- record ably by page. In it the application program is put down.<\/li>\n\n\n\n<li><strong>EEPROM:- <\/strong>Not volatile memory i.e. once written contents remain without current supply. Bytes by bytes write\/ read ably. In the EEPROM typically device-specific values are put down like calibration values of sensor.<\/li>\n<\/ol>\n<\/div>\n<\/div>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"284\" height=\"52\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/c-structure-1.jpg\" alt=\"\" class=\"wp-image-603\" style=\"width:158px;height:auto\"\/><\/figure>\n\n\n\n<p class=\"has-upper-heading-font-size wp-block-paragraph\"><strong>Pointer:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Whenever we declare a variable, the system allocates somewhere in the memory, an appropriate location to hold the value of the variable. Every byte has a unique address number. The location will have its own address number<\/p>\n\n\n\n<p class=\"has-upper-heading-font-size wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>Example:- uint8_t myByte=8;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s us assume that the system has chosen the address location 0x00f for myByte. Then the concept is<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"94\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/8-bit-type-1024x94.jpg\" alt=\"\" class=\"wp-image-1191\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/8-bit-type-1024x94.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/8-bit-type-300x27.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/8-bit-type-768x70.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/8-bit-type.jpg 1060w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A pointer variable is nothing but a variable that contains an address, which is a location of another variable in memory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Declaration of pointer variable<\/p>\n\n\n\n<p class=\"has-upper-heading-font-size wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>data_type *pointer_name;<\/strong><\/p>\n\n\n\n<p class=\"has-upper-heading-font-size wp-block-paragraph\"><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i.e. uint8_t *p; \/** unsigned 8 bit integer **\/<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This tells the compiler three things about the variable pointer_name-<\/p>\n\n\n\n<ol style=\"list-style-type:lower-roman\" class=\"wp-block-list\">\n<li>The asterisk(*) tells that the variable pointer_name is a pointer variable<\/li>\n\n\n\n<li>pointer_name needs a memory location<\/li>\n\n\n\n<li>pointer_name points to a variable of data type<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Declaration style<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">style1 &#8212;-&gt; int* p;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">style2 &#8212;-&gt; int *p;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">style1 &#8212;-&gt; int * p;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"152\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/pointer-1024x152.jpg\" alt=\"\" class=\"wp-image-1194\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/pointer-1024x152.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/pointer-300x44.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/pointer-768x114.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/pointer.jpg 1316w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-upper-heading-font-size wp-block-paragraph\"><strong>Pointers and arrays<\/strong><\/p>\n\n\n\n<p class=\"has-upper-heading-font-size wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>C:\/&gt; int Data[4]={1,2,3,4,5};<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let the address begin with 0x0000H, than<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If we declare p as an integer pointer, than we can make the pointer p to point to the array data by<\/p>\n\n\n\n<p class=\"has-upper-heading-font-size wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>p=x;&nbsp; \/\/ equivalent to p=&amp;x[0]<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;Now we can access every value of Data variable using p++ to move from one element to another.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"275\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/AVR-flash-memory-1024x275.jpg\" alt=\"\" class=\"wp-image-1201\" style=\"width:800px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/AVR-flash-memory-1024x275.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/AVR-flash-memory-300x81.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/AVR-flash-memory-768x207.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/AVR-flash-memory.jpg 1164w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">There is necessary special function in order to read\/write data from this memory. The Header file to access this memory is<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;avr\/pgmspace.h&gt;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Write data to flash memory<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nconst data_type variable_name &#x5B;] PROGMEM\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Read data from flash memory<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nvariable=pgm_read_X(&amp; variable_name&#x5B;++]);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">where X represents the variable data type<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"152\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/byte-word-1024x152.jpg\" alt=\"\" class=\"wp-image-1205\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/byte-word-1024x152.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/byte-word-300x44.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/byte-word-768x114.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/byte-word.jpg 1099w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"590\" height=\"110\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/sounds.png\" alt=\"\" class=\"wp-image-1207\" style=\"width:343px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/sounds.png 590w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/sounds-300x56.png 300w\" sizes=\"(max-width: 590px) 100vw, 590px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s build a wave to run a buzzer. Just connect the buzzer + terminal to PB0 pin of ATtiny13A and \u2013 terminal to ground. Here we store the value in Flash memory and read the data. It\u2019s a simple program as follow-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/************************************************************************************************\n*************************************************************************************************\nThis program will genarate a sound wave\n*************************************************************************************************\n\t\tSubeer Kumar Sarkar\n\t\tElectrical &amp; Electronic Engineer\n************************************************************************************************\n************************************************************************************************\n***********************************************************************************************\/\n#include&lt;avr\/io.h&gt;\n#include&lt;util\/delay.h&gt;\n#include&lt;avr\/pgmspace.h&gt;\nconst uint8_t sound&#x5B;512] PROGMEM ={\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,\n0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff\n};\nint main(void)\n{\nuint8_t generarion;\nDDRB|=(1&lt;&lt;DDB0);\nwhile(1)\n\t{\nfor(int i=0;i&lt;512;i++)\n\t\t{\n\t\t\tgenerarion=(uint8_t*)pgm_read_word(&amp;sound&#x5B;i]);\n\t\t\tgenerarion ? (PORTB|=(1&lt;&lt;PB0)) : (PORTB&amp;=~(1&lt;&lt;PB0));\n\t\t\t_delay_ms(1);\n\t\t}\t\n\t}\nreturn 0;\n}\n<\/pre><\/div>\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Sound-Wave.rar\" style=\"border-style:none;border-width:0px;border-radius:10px;padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--40)\">download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-upper-heading-font-size wp-block-paragraph\"><strong><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Sound-Wave.rar\">Download the full program with proteus simulation<\/a><\/strong><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Atmel AVR microcontroller has typically three memories Pointer: Whenever we declare a variable, the system allocates somewhere in the memory, an appropriate location to hold the value of the variable. Every byte has a unique address number. The location will have its own address number &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Example:- uint8_t myByte=8; Let\u2019s us assume that the system [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-1179","post","type-post","status-publish","format-standard","hentry","category-flash-memory"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/1179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1179"}],"version-history":[{"count":20,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/1179\/revisions"}],"predecessor-version":[{"id":2556,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/1179\/revisions\/2556"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}