0% found this document useful (0 votes)
7 views7 pages

Understanding Microcontroller Memory and Protocols

The document outlines various technical concepts related to microcontrollers, memory management, and communication protocols such as UART, I2C, and SPI. It discusses memory allocation, stack and heap usage, and details tasks involving reading analog voltages and implementing communication protocols. Additionally, it covers the basics of electronics, GPIO configuration, and the use of FreeRTOS for task management in embedded systems.

Uploaded by

Inam ul Rehman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Understanding Microcontroller Memory and Protocols

The document outlines various technical concepts related to microcontrollers, memory management, and communication protocols such as UART, I2C, and SPI. It discusses memory allocation, stack and heap usage, and details tasks involving reading analog voltages and implementing communication protocols. Additionally, it covers the basics of electronics, GPIO configuration, and the use of FreeRTOS for task management in embedded systems.

Uploaded by

Inam ul Rehman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Stating date of courses: 23-05-2023

[Link] = machine code + stack + heap memory

Stack -> given to the dynamic variable (declared inside the function), as scope goes out{} variable
will be removed from stack memory.

Heap -> given to static/global variable (declared globally), memory will be allocated dynamically in
heap. For example declaring variable in .h file will be accessed in scope.

Memory allocated at compile time normally.

(to do at runtime(dynamic memory allocation))We need to allocate and deallocate the memory
manually of variables.

We need a stack pointer(size increases as the stack memory size increases) to access the value of
variable using the & op to get the address, this will help us to access or change the value of variable
defined in some file.

Serial protocols:

I2c

Spi

Uart -> Tx, Rx pins, 9600(samples per second) . Ardinuo clock is running= 8Mhz. , Time period(T) =
1 ,\ 8*10^6= some time(time to complete one cycle-> on then off)). Delay does allow to do any task
by the running clock during the specified time period. Delay is stoping the ardino clock. UART is async
(sycning with single clock, same baud rate need as there is not common clock) as there are two pins
Tx and Rx

Task: Create the delay with out using the delay function

Fast , consumes more resource in parallel communication.

08-06-2023 (W3)

FTDI Chip -> Converts UsB data to Serial data(uart). This chip is on controller near the usb port

MicroProcessor:

 Memory
 processor
 I/O

are main things rest are for assistance like ADC.

[Link]

Task done: Read analogue voltage using potentiometer


Learned about the I2c IO extender why we use it.

Task To Do: Code the traffic light signal (4-road)

09-06-2023

UART -> async protocol not sync protocol, its efficiency decreases as the length of wire increases as if
length of wire increases due to resistance the voltage decreases to 2.4 or some thing but required is
3.3 voltage

Communication of two mcu on uart protocole

Clock is not sync so there may be chances that data received at Rx of mcu inncurate so to avoid from
that we use 16 times faster clock at Rx than Tx of same controller with the data rate/baud rate 9600
we make 16 times faster 9600 to generate new clock in which we can write logic to ignore the 2 bits
out of total three start bit.

1 Start 8 data 1 stop and 1 parity bits are of uart data packet = 11 bits

RS2C2 -> has Tx and Rx pins(HDMI)

Pointers, pointer arrays, structure + pointer From sir Git

13-06-2023

Master-slave communication using I2c- >Examples Wire in aridinu library

Test api search on google then see the results on wire shark, using postman do request the HTTP

HTTPS: Make new layer in b/w transport layer so called ssl

UDP , TCP are transmission protocols on which we can run mqtt,http protocol

I2c protocol done

14-06-2023
STM 32
Multiple masters send data on same bus.

ARM cortex M cpu:

48 MHZ internal clock.

Microcontroller= Processor, memory, I/o s(i2c, sp, uart)

I/O will be controlled by processor.

Soc unit : cpu is separate ,12 bit ADC , tmer, counter , processing , everything is on chip

Processor of computer: I2c, spi are running, processor should know how to operate procotols

Stm support usb


If 10bit bus then we call it as 10 bit architecture, if 64 bit then 64 bit archi

FPGA manufacturer: Xilix , intel

Interrupt :

15-06-2023
stm32f103c8t6

pin out : [Link]

STM 32 datasheet page-171, ports , explorer the ports of stm32

For using pa2 as digital I/O:

 Pa2 -> digital output : By telling port A register to set pin 2 as digital output
 Mode-> pull down : using some register
 Set/Reset: 1/0 by using register

16-06-2023
Basic of electronics:
As you go high then the more potentional energy stored called gravitational
Voltage/ Potential difference:
If we store +ve charge it means like you are going high more energy is stored, on second side
-ve is stored. Then apply proton(+ve) charge in between the two plates the more potential
difference more speed will be of flow from + to –
V = IR
If resistance in series then add the resistance values and use V = IR to get current.
Pull up resistor /current limiting resistor
By default ground on switch close 5v by attaching resistance to ground (pull down
resistance)
By default 5v on switch(we can use mcu as switch it will control the voltage attched) close
current will be limited(LOW) (to 0v) by attaching resistance to 5v (pull up resistance)
Why pull up / pull down : as initially we do not know the voltage on pin , that is some
random value so to initialize some value we use pull up or down as per requirement of task.
Normally active low is used in industry.

Get data using I/Os -> memory -> Proessor


GPIOs: As it can work as pwm , anlouge , means one pin can work different tasks, one pin
can be used to get different tasks done.
vs I/Os
UseCase: When person in room turn on light when out tur off
How processor will know this is input data not raw wave data we configure whole by using
I/Os configuration. Processor will know by I/o registers that consider voltage on pin as
input/output

21-06-2023

Microcontrller: / Embeded system components


Pheripherals-> to communicate with external world, i2c, spi for fast communication, uart,
sensors, Gyroscope(i2c), Bluthooth->a radio signal(UART), GPIO, ADC. Every Pheripherals has
separate mini controller are connected through bus, to communicate with memory bus used
is AHB(Advance high performance bus) like to read varible from bus, to communicate with
Pheripherals bus used is APB(Advance Pheripherals bus) like to write on some digital pin will
write on small memory of mini gpio controller

Memory: to store data ->, vss(global/static(not accessible to whole code, we want to save
value even after excuting code) variable), da, stack(local variables), heap
Processor: to perform some computation, running code on it.

FreeRtos: to set/define priorty like on running alaram control should excute code. To
resource handling/ shared resources, what task to do first
On OS Make thread(parallel programing), create separate function for each task/function
and give priorities to define which task to first.

GPIO:

Memory CPU GPIO


Memory AHB CPU APB GPIO
GPIO: has registers 1. data register [Link] register and [Link] register
Control register:
Direction register: To input / output, 13 memory locations to write high/low at specific pin 0-
[Link]
For pull up and pull down there are registers , interrupt register to manage interrupt at some
pin.
Data register: gives voltage at that pin low / high, digitalWrite

In UART:
Baud rate , start/stop bit , parity bit
ADC is configurable in some controller like in stm adc can be 8-bit or 10-bit

ESP32 online simulator:

Task:
 Tmp 36 will give analoge data
 Convert to digital using ADC 0-1023(digital) can be done internally by controller at
analogue pin
 Convert From digital to voltage 0-5 using formula,
 Read data sheet to read about formula to convert from voltage to actual temperature

As temp is analogue to big value can not be stored in small ardinu memory so we will
convert that into digital value 0-1023 using ADC then we convert that value to voltage from
0-5. After that we convert that voltage into actual temperature using formula in datasheet of
temperature sensor.
Temperature sensor will basically give voltage/ analogue value at adc pheriphal then digital
value to processor will perform processing.
void setup()
{
[Link](9600);
}
void loop()
{
int res = analogRead(A0);
float voltage = float(res) * (5.0 / 1023.0);
delay(1000);
float temperature= (voltage - 0.5) * 100 ;
[Link](temperature);
}

22-06-2023
Logic analyzer
PWM is used in energy management , power is critical , power should be used less.
Width measured witt respect to time and we want to change it we defined a variable delay
to turn on led. As using delay we are changing width of pulse using delay by
decreasing/varying the delay. We are changing the duty cycle actually.
Turn on led + turn off led = cycle -> ½ on time is called duty cycle, by changing duty cycle we
are saving power, by modulating width we are setting the duty cycle.
Task :
Time period = delay after on and before off = 20ms
User want 25 -> 5 + 15

You might also like