0

I am reading manuals regarding controlling a device with C,and in general its just playing with addresses; however when we are connected through UART we have the BAUDRATE present.

So how putting a value into some address have to do with baud-rate?

Is it necessary in embedded programming?

Clifford
  • 88,407
  • 13
  • 85
  • 165
rocko445
  • 129
  • 7
  • 1
    I think you're confusing multiple issues and the end result is I can't even make sense of your question. Pointers and baud rate have nothing to relate them. Do you mean "a pointer in a structure" which you're not showing? Code to illustrate the issue would help a lot. – tadman May 14 '20 at 18:32
  • 1
    @tadman I doubt he has code - he says he has just been reading manuals. Presumably the manuals for the micro-controller or whatever he is using. Such manuals are of course not embedded system tutorials and assume prior knowledge and expertise. It seems the issue is a lack of knowledge of the concept of memory-mapped I/O. – Clifford May 14 '20 at 18:59

1 Answers1

3

Those addresses are not memory. They are memory-mapped I/O registers.

The address for your UART's baud rate divisor register is a hardware register. The value in hardware registers directly control the hardware. The value written to baud rate divisor register is typically a counter reload value, and one bit period is the time it takes to count up-to (or down from) the value in the divisor given a specific peripheral clock source. So for exaample if the UART peripheral clock were say 12MHz, and you wanted a baud rate of 19200, you would set the divisor register to 12x106/19200 = 625.

Although you can read and write hardware registers as if they were memory, they do not necessarily behave like memory. Some registers may be read-only, others write only, and some writing may have a different effect than reading, such that if you write a value, the value read back will not be what was written. This often works at the bit level, so that each bit in a register may exhibit different behaviour.

For example on many UART implementations the register to which your write data to be sent, is the same address you read for received data - however they are not the same register, but rather a read-only register and a write-only register mapped to the same address.

It is not specifically an embedded programming thing, but rather an I/O hardware thing; it is simply that outside of embedded systems you are not typically writing directly to the hardware unless you happen to be writing a kernel device driver, where you will encounter the same thing.

As well as the device manuals which necessarily assume existing knowledge and expertise, perhaps you should consult a more general reference. Now you know the key term: "memory-mapped I/O" or MMIO, you are in a better position to Google it. Examples:

Clifford
  • 88,407
  • 13
  • 85
  • 165