Lecture 10 - Review of UART, Starting I2C
UART (review)
See Lecture 9 - DAC (Digital to Analog Conversion)#UART for more information, but the idea is that we know SPI sends the clock to different devices to communicate data. UART is asynchronous in that you just have devices agree on a BAUD rate, then send data on TX
and receive data on RX
lines.
UARTs are as old as time (ie: 1950's), but it works.
the first bit is always a start bit (0), last bit always a stop bit (1). We may add parity bits or other error correcting code bits, but the data is still the same. The BAUD Period is the time each bit has to stay active to be read, which is the inverse of the BAUD rate.
Some systems may just start at a really small BAUD rate, then send signals at that slow speed to agree on who has the smallest BAUD rate that works, then adjust the BAUD to that.
But since there is no clock, you must trust your local clock. If 600 BAUD is the rate, but the clocks between devices are mismatched, then one devices 600 BAUD is actually 500, or 700. Mismatches in clock frequency can lead to corruption, limiting to low speeds.
The STM32 registers we care about here are:
CR1 ... CR3
: start, stop parity, enable, ...BRR
: adjusts the baud rateGTPR
: guard time, other settingsRTOR
: if missing bit, end the commsRQR
: flow controlISR
: interruptICR
: interrupt flag clearRDR
: rx registerTDR
: tx register
You can transmit, over the STM32 USB, data from the serial terminal down the USB into the microcontroller, or vice versa.
I2C
It is:
- Multi Master
- Synchronous
- Single data and single clock line (SCL, SDA, plus common ground)
- Max data rate is ~500 kbps