原创 AVR外部SRAM

2007-3-20 22:17 5661 3 3 分类: MCU/ 嵌入式

在实际AVR应用中很多朋友往往需要扩展external SRAM,首先我声明一点,AVR扩展SRAM的方法和51扩展的方法一样,在此不在累述。


语言写得非常土,高手可以不看。


下面主要讲ATmega162扩展SRAM的特点。


先摘录datasheet里面的一段:


An optional external data SRAM can be used with the ATmega162. This SRAM will
occupy an area in the remaining address locations in the 64K address space. This area
starts at the address following the internal SRAM. The Register File, I/O, Extended I/O
and Internal SRAM uses the occupies the lowest 1280 bytes in Normal mode, and the
lowest 1120 bytes in the ATmega161 compatibility mode (Extended I/O not present), so
when using 64KB (65,536 bytes) of External Memory, 64,256 Bytes of External Memory
are available in Normal mode, and 64,416 Bytes in ATmega161 compatibility mode. See
“External Memory Interface” on page 24 for details on how to take advantage of the
external memory map.


翻译:ATmega162可以选择使用外部SRAM。外部SRAM会占据64K中的一部分地址空间,这个地址紧接在内部SRAM的后面。内部Register,IO,扩展IO和内部SRAM占据了1280字节的空间,(略了161),所以当使用了全部的64KB的外部空间后,外部存储器只有64256Byte有效。



when the addresses accessing the SRAM memory space exceeds the internal data
memory locations, the external data SRAM is accessed using the same instructions as
for the internal data memory access. When the internal data memories are accessed,
the read and write strobe pins (PD7 and PD6) are inactive during the whole access
cycle. External SRAM operation is enabled by setting the SRE bit in the MCUCR
Register.


翻译:当存取SRAM的地址超出了内部数据存储器的地址的范围时,存取外部数据存储器的指令与存取内部数据存储器的指令相同(这点与51不同),当存取内部存储器时,RD和WR在整个存取期间处于非活动状态。如果你想对外部存储器进行操作,应该怎么办?你就要将MCUCR中的SRE位置位。(SRE: External SRAM/XMEM Enable)



Accessing external SRAM takes one additional clock cycle per byte compared to access
of the internal SRAM. This means that the commands LD, ST, LDS, STS, LDD, STD,
PUSH, and POP take one additional clock cycle. If the Stack is placed in external
SRAM, interrupts, subroutine calls and returns take three clock cycles extra because the
2-byte Program Counter is pushed and popped, and external memory access does not
take advantage of the internal pipeline memory access. When external SRAM interface
is used with wait-state, one-byte external access takes two, three, or four additional
clock cycles for one, two, and three wait-states respectively. Interrupt, subroutine calls
and returns will need five, seven, or nine clock cycles more than specified in the instruction
set manual for one, two, and three wait-states.


翻译:存取外部SRAM比存取内部SRAM每个字节要额外多一个时钟周期。这意味这那几个烦人的汇编指令的执行也需要额外的一个时钟周期。如果堆栈设定在外部SRAM,那么中断,子程序调用以及返回将要耗费三个额外的时钟周期,因为2字节的程序计数器必需要入栈和出栈,(加上那个额外的时钟,是不是三个?嘿嘿),所以外部SRAM的存取远没有内部SRAM的流水线操作来得高效。当外部SRAM接口使用的等待功能,每字节的存取将要花去2,3或4个额外的时钟周期。随即中断、子程序调用---大家不看也知道下面什么意思了,嘿嘿!


Using all Locations of
External Memory Smaller than
64 KB


Since the external memory is mapped after the internal memory as shown in Figure 11,
the external memory is not addressed when addressing the first 1,280 bytes of data
space. It may appear that the first 1,280 bytes of the external memory are inaccessible
(external memory addresses 0x0000 to 0x04FF). However, when connecting an external
memory smaller than 64 KB, for example 32 KB, these locations are easily accessed
simply by addressing from address 0x8000 to 0x84FF. Since the External Memory
Address bit A15 is not connected to the external memory, addresses 0x8000 to 0x84FF
will appear as addresses 0x0000 to 0x04FF for the external memory. Addressing above
address 0x84FF is not recommended, since this will address an external memory location
that is already accessed by another (lower) address. To the Application software,
the external 32 KB memory will appear as one linear 32 KB address space from 0x0500
to 0x84FF. This is illustrated in Figure 17. Memory configuration B refers to the
ATmega161 compatibility mode, configuration A to the non-compatible mode.


翻译:因为外部存储器在那个图中的内部存储器之后才被映射,所以呢,在外部存储器的头1280字节的空间是不可以寻址的,这就表现为不能存取外部存储器的0X0000-0X04FF。当然有个特殊的情况,当使用的外部存储器小于64K(典型值32K)时,外部存储器的0X0000-0X04FF范围可以通过访问0x8000 to 0x84FF进行存取(想一想为什么?)。因为高位地址线A15没有接入,外部寻址范围只有0X0000-0X7FFF,当访问0x8000 to 0x84FF时,低14位地址线定位在外部0X0000-0X04FF处(或许大家会疑惑,怎么不是访问的内部0X0000-0X04FF?请注意了,我们现在访问的是外部存储器,因为地址范围为0x8000 to 0x84FF,不是内部存储器,所以自然不是定位在内部0X0000-0X04FF范围)。不推荐大家对0x84FF以外的范围进行访问,因为这将改变0X04FF-0X7FFF的数据,因为低14位地址是重复的。在应用中,地址在0x0500 to 0x84FF范围的存取是连续的线性的,只有0X0000-0X04FF有写特殊。大家可以参考下图。


d30e6687-39d8-43d3-a5c5-bbabb2d9335f.JPG

文章评论0条评论)

登录后参与讨论
我要评论
0
3
关闭 站长推荐上一条 /2 下一条