0
\$\begingroup\$

It might sound like a silly question, but somehow I am not able to answer this myself with confidence. Let's say we have a microcontroller (MCU) with a data/address bus and data is moving to and from the bus. "Where" exactly on the MCU is the data arriving on this bus temporarily stored? Is it in some RAM buffer or some IO data register for a particular address?

If it is not a data/address bus (that has addresses) and the data is coming on a random GPIO pin, where is this data temporarily stored in this case?

Thank you.

\$\endgroup\$
  • \$\begingroup\$ How familiar are you with digital design? Have a read of righto.com/2014/10/how-z80s-registers-are-implemented-down.html and see if it answers the question or is over your head. \$\endgroup\$ – pjc50 Jun 3 '16 at 9:59
  • \$\begingroup\$ I do understand quite a bit being an electronics graduate. Thanks for sharing the link. A quick glance at the link suggests that it is something along the lines of what I had in my mind. Need to read it to say that confidently. \$\endgroup\$ – LoveEnigma Jun 3 '16 at 10:56
2
\$\begingroup\$

Here is a block diagram of a 8051 variant. There are probably hundreds of different microcontroller architectures. Most are more complicated than the 8051 (which why I chose it, for its relative simplicity), and may have additional features such as DMA (Direct Memory Access), pipelining, caches, etc., but they all pretty much have to start with the basic components shown here: program memory, data memory (separate in a Harvard architecture, the same in a von Neumann srchitecture), instruction decode, accumulator(s) and/or register file, ALU, interrupt logic, and peripherals. (The 8051 does have a rudimentary instruction cache that can look ahead 6 instructions.)

The 8051 is a accumulator based machine that also has a set of four register files which are actually located in RAM. It is an 8-bit microcontroller, so the data bus is 8 bits wide.

enter image description here

Note that everywhere data must be stored off of the data bus, there are latches. Data can be transferred to and from the accumulator. The ALU (arithmetic logic unit) has two registers for storing its two operands, one of which can come from the accumulator and the other a data bus source (memory or peripheral register, for example), or both from the data bus (in which case the first is held in one of the ALU registers while the second is loaded). The B register is only used for the multiply instruction. Each of the ports has its own latch. The timers implicitly have registers within them.

\$\endgroup\$
  • \$\begingroup\$ Thank you, that was helpful. Could you please explain the general flow of how data is stored in relation and accessibility to software code in the situation I have explained in the comment in the reply to yours? I want to understand the flow of data inside the MCU after it arrives on the physical pins. From the block diagram it looks that the data first gets stored in the latches, from where the internal bus reads it. Right? What happens after that? Sorry and please let me know if my questions are confusing. \$\endgroup\$ – LoveEnigma Jun 7 '16 at 5:59
  • 1
    \$\begingroup\$ @LoveEnigma Generally the flow is going to be from the program memory (e.g. Flash) to the instruction decode, from RAM, register bank or peripheral registers (including timers) to the accumulator or ALU, and from the output of the ALU back to RAM or peripherals registers or register bank. Take a look at the 8051 instruction set and you will see how this fits in. Remember, this example is one I chose for its relative simplicity, there are hundrdes of variations of different architectures out there. \$\endgroup\$ – tcrosley Jun 7 '16 at 6:53
  • \$\begingroup\$ Thank you. I seem to have started understanding this a bit better. The 8051 architecture is really helpful and I am revising it. I will check the linked post and get back with any unclear points. \$\endgroup\$ – LoveEnigma Jun 7 '16 at 12:03
5
\$\begingroup\$

At a very basic level incoming (or out-going for that matter) data is held in a set of latches. This may (or may not) be a "Register" in the view of programming the processor.

And the data may or may not be held in a local cache, again depending the architecture of the processor. Tiny microcontrollers have very basic data handling paths, and high-end microprocessors have much more sophisticated data handling including perhaps megabytes of internal cache RAM.

\$\endgroup\$
  • \$\begingroup\$ Yes, correct. Thank you for the answer. But one new question based on this: If a medium-end 32-bit MCU is interfaced to two different type of memories and have some of address/data lines common between them, how is the flow if the data is to be sent from one memory to the other? As per my understanding the data from one memory has to go to MCU and then MCU only can write that data to other memory. Right? If so, then in this particular situation, how does MCU handle/store the data that is to be transferred between devices? I am asking mainly from the software/program perspective. \$\endgroup\$ – LoveEnigma Jun 3 '16 at 11:54
  • 1
    \$\begingroup\$ @LoveEnigma It would be unusual to have an MCU interfaced to two different writable memories, but if it did transfers between the two would be handled by loading the contents directly into an MCU register (accumulator or register bank) from one memory using a load instruction, and writing that to the other one using a store instruction. A second option would be to use DMA (direct memory access, a device that transfers data between memory and peripherals, or in this case, memory to memory). Transfers between Flash memory and RAM are less common but would use the same principle. \$\endgroup\$ – tcrosley Jun 3 '16 at 13:19
  • 1
    \$\begingroup\$ @LoveEnigma If you had a DMA that could interface with external memories, then it would need to read a word (which may be 1 to 8 bytes, depending on the data bus width) from one memory into an internal buffer, and then switch over to the other one and write it. This would be done independent of software (except for the initial setup). Another way would be to have the DMA read a block of data from one memory, say 512 bytes into internal RAM, and write the block out to the other memory. This would probably require software intervention for each block, via an interrupt generated by the DMA. \$\endgroup\$ – tcrosley Jun 7 '16 at 6:35
  • 1
    \$\begingroup\$ @LoveEnigma Yes, you can certainly have two (or more memories) in different address spaces inside the MCU, or one or more inside and one or more external, with the address and data bus brought out to pins (lots of them when you have a 32-bit microcontroller). To transfer between memories without DMA, you would have to do so one word (data bus width) at a time, loading it from one memory into a register and then writing it back out to the second memory. \$\endgroup\$ – tcrosley Jun 11 '16 at 6:23
  • 1
    \$\begingroup\$ @LoveEnigma If you are writing in C you don't have to worry about registers; the compiler will take care of that for you (as long as the two memories are both mapped as regular memory spaces in the computer). What MCU are you using? \$\endgroup\$ – tcrosley Jun 11 '16 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.