Day 8: Infineon’s Embedded Systems Summer Course (2024)
First, Prakash Sir asked us to flash BareMetalV5 onto the board to get output. We observed that LED 1.6 was not blinking, even though the code was present in main.c
. He then asked us to check the CFLAGS
line in the makefile of both BareMetalV4 and BareMetalV5. We noticed a difference: BareMetalV4 used -O0
and BareMetalV5 used -O2
.
The -O
flag stands for optimization. -O2
tells the compiler to optimize the code, reducing its time and space complexity. Since the delay function had for loops without a body, the compiler thought it was useless and didn't compile it into assembly. On the other hand, -O0
does not perform any optimizations.
If you look into BareMetalV4.lst
, you can see the delay function being converted to assembly, but it is not converted in BareMetalV5.lst
. This is a common mistake in the embedded world due to compiler optimization. The compiler can ignore some functionality we want to execute because it deems it unnecessary and doesn't convert it to assembly.
Now, how can we make the LED blink with -O2
optimization?
Enter the volatile
keyword. This whole example helps us understand why the volatile
keyword is so important. When we put the volatile
keyword inside the delay function's for loop, it tells the compiler, "Hey, I know this for loop doesn't have a body, but still iterate/increment the counter variables and do not ignore me." The volatile
keyword prevents the compiler from optimizing out the loop, and hence the LED blinks once again.
Next, we discussed why the SVC handler is placed in the 11th index of the vector table in main.c
. It's because it is defined like that in the M0+ CPU chip documentation.
Todays Presentation was all about GPIO, Pins, Pads, Ports and a lot of fun!
- Left Image: Shows a simple illustration of a silicon die.
- Middle Image: Illustrates a silicon die with integrated components such as CPU, Memory, and Peripherals.
- Right Image: Depicts the silicon die placed inside a package. The package is the final product that includes the silicon die and is ready for integration into electronic systems.
- Left Image: Shows how external world signals enter and exit the silicon die through pads. The pads serve as the interface between the internal components and the external environment.
- Right Image: Demonstrates how pads are connected to package pins by wires, typically gold wires. These connections are essential for the communication between the silicon die and the external circuits.
This slide illustrates the relationship between pads on a silicon die and the package pins that connect the die to external circuits.
The number of package pins often exceeds the number of pads, enabling greater flexibility in design.
Pads can connect to multiple peripheral signals, and some pins are dedicated to power supplies and ground lines, which are essential for powering the silicon’s internal components.
Not all package pins are connected to pads, allowing for future expansion or specific testing purposes.
This configuration optimizes the functionality and connectivity of silicon dies within their packages, crucial for efficient electronic system design.
- Left Section: A power supply IC with multiple voltage regulators is depicted. This IC converts a 5V input into various required voltages.
- Voltage Regulator-1: Outputs Vcore (1.8V)
- Voltage Regulator-2: Outputs VMem (1.8V)
- Voltage Regulator-3: Outputs Vio (3.3V)
- Voltage Regulator-4: Outputs VPer (1.8V)
- Right Section: Illustrates how these voltages are distributed to different parts of the silicon die (CPU, Memory, Peripherals).
- The power supplies are critical for the operation of core logic, memories, peripherals, and I/O pads.
- The VSS (Ground path) is also shown, providing the necessary return path for the current.
- The advantage of having different power supplies is that we can have flexibility in powering up specific parts of the board and that can lead to more power saving, another advantage is that it prevents the board from overloading.
This slide illustrates how a single pad on a silicon die can be connected to multiple peripherals, highlighting the role of multiplexer (mux) selection.
In this example, the pad is linked to peripherals such as UART TX, SPI MOSI, Timer Status, and GPIO Register.
The pad is also connected to a register that can be configured via software.
As an application developer, you must choose which function the pad will serve among the available options using a mux selector. The specifics of the pad options are detailed in the MCU’s user manual, allowing developers to effectively manage the functionality and connectivity of each pad within the system.
The pad can be connected to different functions (like CAN Tx, SPI MOSI, ADC input, GPIO Register) through a selector called a mux (multiplexer). This lets you choose what the pad should do by controlling the mux with software.
You can decide how the pad behaves, such as:
- Direction: Whether it sends information out or receives information in.
- Strength: How strong the signals are that it sends or receives.
- Output Options: How it outputs signals (e.g., Open Drain or Push-Pull).
- Input Options: How it reads signals (e.g., Pull-Up or Pull-Down).
Input: When configuring a pad as an input, you need to use either a pull-up or pull-down resistor to reduce noise. A pull-up resistor connects the pad to a high voltage (like 1.8V or 3.3V), so if no input is received, the pad reads the high voltage. A pull-down resistor connects the pad to ground (0V), so if no input is received, the pad reads 0V.
output: When configuring a pad as an output in open-drain mode, the pad can either connect to ground (0V) or be left floating (disconnected). If the pad output is set to 0, a transistor conducts and pulls the line to 0V, activating the connected actuator. If the pad output is set to 1, the transistor does not conduct, and the output line is floating, meaning it is not connected to any voltage.
Real-World Applications of Open-Drain Configuration
Open-Drain Mode:
In open-drain mode, the pad can either connect to ground (0V) or be left floating (disconnected). This is useful in situations where multiple devices need to share a single communication line without interfering with each other.
Practical Use Cases:
- I2C Bus Communication:
- Open-drain configuration is commonly used in I2C (Inter-Integrated Circuit) communication. The I2C bus is a multi-master, multi-slave, single-ended, serial computer bus used for attaching lower-speed peripheral ICs to processors and microcontrollers.
2. Multiple Device Signaling:
- Open-drain is also used for signaling between multiple devices where one line needs to be shared, such as in interrupt lines or reset lines where multiple devices can pull the line low to signal an event.
3. LED Driver Circuits:
- Open-drain can be used to drive LEDs where multiple LEDs share the same line and only one LED needs to be turned on at a time. The open-drain configuration allows each LED driver to pull the line low independently.
This slide explains how a pad works when it is set to push-pull mode. In this mode:
- When the pad outputs a logic-0 (low voltage), a PNP transistor conducts and pulls the output line to 0V, making the actuator turn off.
- When the pad outputs a logic-1 (high voltage), an NPN transistor conducts and sets the output line to 1.8V or 3.3V, making the actuator turn on.
Real-World Applications:
- Microcontroller Control:
- Push-pull mode is used in microcontrollers to control devices like LEDs, motors, or other actuators. For example, turning on an LED when the output is high (logic-1) and turning it off when the output is low (logic-0).
2. Signal Transmission:
- It ensures that signals are clearly transmitted without floating states, making it suitable for applications that require reliable on/off control, such as in home automation systems where a microcontroller can control lights or appliances based on sensor inputs.
This slide explains the importance of pad drive strength (slew rate) and how it affects signal transmission between the pad and an output device, like an actuator.
- Transmission Line Effects:
- The path from the pad to the actuator is considered a transmission line. These lines have capacitances that can affect the rise and fall times of the signal. This means the signal can get distorted due to the capacitive effects.
2. Drive Strength (Slew Rate) Adjustment:
- By programming the drive strength or slew rate of the pad, you can mitigate these capacitive effects. Properly adjusting the drive strength ensures that the transmitted signal is a good replica of the original signal, ensuring reliable communication between the pad and the actuator.
Real-World Applications:
- High-Speed Data Communication:
- In high-speed data buses or communication lines, ensuring signal integrity is crucial. Adjusting the drive strength can help maintain signal quality over long distances, reducing errors and improving performance.
- Motor Control:
- In motor control applications, the drive strength of control signals can be adjusted to ensure smooth operation and prevent issues caused by signal distortion, such as unwanted noise or incorrect motor responses.
Practical Example:
Imagine you have a microcontroller controlling a robotic arm. The microcontroller sends signals to the arm’s actuators to move it. If the signals are distorted due to capacitive effects, the arm might not move correctly. By adjusting the drive strength of the control signals, you ensure that the signals are clear and precise, allowing the robotic arm to move accurately and reliably.
This slide explains the scenarios in which you would use open-drain versus push-pull configurations for output pads.
- Open-Drain Mode:
- Use Case: When multiple pads need to drive a single output line, open-drain mode is appropriate. This is because open-drain allows multiple outputs to be connected together in a “wired AND” configuration.
- Example: Two pads (Pad1 and Pad2) are set in open-drain mode and connected to an actuator. A pull-up resistor ensures the line is high when none of the pads are pulling it low. This configuration is suitable for shared signal lines, such as the I2C bus, where multiple devices can pull the line low.
2. Push-Pull Mode:
- Use Case: When a single pad is responsible for driving an output device, push-pull mode is suitable. This configuration provides a strong drive for both high and low states, making it ideal for clear and direct control.
- Example: If only Pad1 is controlling an actuator directly, push-pull mode is used. This provides a strong high (1.8V or 3.3V) and low (0V) signal, ensuring reliable actuation.
Real-World Applications:
- Open-Drain Example:
- I2C Bus Communication: In an I2C setup, multiple devices (like sensors and microcontrollers) share the same data (SDA) and clock (SCL) lines. Each device can pull the line low without causing conflicts, making open-drain configuration ideal.
Push-Pull Example:
- LED Control: For controlling an LED directly from a microcontroller pin, push-pull mode ensures the LED receives clear on/off signals.
This slide explains the concept of a port, which is a collection of pads (pins) grouped together for easier management. Instead of having separate registers for each pad, registers are provided for an entire port, simplifying programming and control.
- Port Registers:
- Each port has a set of registers that control the behavior of all pads within that port. These registers typically include:
- Configuration Register: Defines the configuration of each pad in the port, such as input/output mode and special functions.
- Output Register: Controls the output value (high or low) for each pad when configured as an output.
- Input Register: Reads the input value from each pad when configured as an input.
Example of Ports:
- Port-0:
- Contains pads Port-0 Pad-0 to Port-0 Pad-7.
- Managed by Port-0 configuration, output, and input registers.
- Port-1:
- Contains pads Port-1 Pad-0 to Port-1 Pad-7.
- Managed by Port-1 configuration, output, and input registers.
Practical Explanation:
- Grouping for Efficiency:
- Imagine you have a group of lights (LEDs) controlled by a microcontroller. Instead of controlling each light individually, you can group them into a port. This allows you to control all lights using a single set of commands, making it easier and more efficient.
2. Real-World Example:
- Home Automation System: In a home automation system, a port can represent a group of devices like lights in a single room. Using port registers, you can turn all lights on or off, configure their behavior, and read their status with just a few commands.
Simplified Example:
- Port-0 Management:
- Configuration Register: Sets up how each light should work (e.g., which light should be on or off).
- Output Register: Controls if the lights are on or off.
- Input Register: Checks if the lights are working correctly.
- Port-1 Management:
- Similar to Port-0 but for a different group of lights or devices.
This slide delves into the specifics of how port registers manage individual pads within a port. It highlights the bit-level control provided by configuration and input registers for each pad.
- Configuration Register:
- The configuration register contains bits that correspond to each pad within the port. Each bit in this register configures the respective pad (e.g., setting it as input or output).
- Example:
- The bit for Pad-5 configures Pad-5.
- The bit for Pad-0 configures Pad-0.
2. Input Register:
- The input register also contains bits that correspond to each pad. Each bit stores the input value received by the respective pad.
- Example:
- The bit for Pad-0 stores the input value received on Pad-0.
- The bit for Pad-6 stores the input value received on Pad-6.
Imagine you have a microcontroller managing a set of LEDs. The configuration register decides which LEDs should be on or off, and the input register checks if any of the LEDs are faulty by reading their status.
This slide illustrates the input and output paths of a PSoC (Programmable System on Chip) port structure, highlighting the loop-back feature for outputs.
- Digital Input Path:
- The input path shows how external signals are received through the port pins and processed by the digital input logic.
- Signals enter through the port pins and are routed to the digital input block for processing and further action by the microcontroller.2
2. Digital Output Path:
- The output path shows how signals generated by the microcontroller are sent out through the port pins.
- Signals pass through the digital output logic and buffer before reaching the external pins, allowing the microcontroller to control external devices.
3. Output Loop-Back:
- The output loop-back feature allows the signal sent out from the digital output path to be routed back into the digital input path.
- This loop-back is useful for testing and verification purposes, ensuring that the output signals are correctly generated and received.
Real-World Application:
- Device Control:
- In home automation, the microcontroller might receive signals from sensors (input path) and control devices like lights or alarms (output path). The loop-back can verify that commands are correctly executed.
2. System Testing:
- In automotive systems, the microcontroller might control various functions like indicators or wipers. The loop-back ensures that signals sent to these devices are accurate, improving reliability.
Practical Example:
Imagine you have a smart home system where the microcontroller controls various devices like lights and sensors. The input path reads signals from sensors (e.g., motion detected), and the output path sends commands to control lights (e.g., turn on the light). The loop-back feature allows the system to verify that the commands sent to the lights are correct, ensuring everything works smoothly.
This slide details the registers used for managing ports in a PSoC (Programmable System on Chip) device. It outlines the structure and addresses of these registers for eight ports, with each port managing eight pads.
- Total Ports and Pads:
- There are a total of 8 ports (PORT-0 through PORT-7).
- Each port contains 8 pads, resulting in a total of 64 pads across all ports.
2. Registers per Port:
- Each port has 10 registers, which include:
- DR (Data Register): Manages the output data for the port.
- PS (Port State): Reads the current state of the port pins.
- PC ,PC2(Port Configuration): Configures the port pins (e.g., input/output mode).
- INTR, INTR_CFG (Interrupt Configuration): Configures the interrupt settings for the port.
- DR_SET, DR_CLR, DR_INV: These are specialized registers for setting, clearing, and inverting the data register bits.
- HSIOM_PORT_SEL (High-Speed Input/Output Matrix Selection): Used for MUX selection to route different functions to the port pins.
2. Register Addresses:
- Each register has a specific address for accessing its functions. These addresses are provided for quick reference and programming.
Real-World Application:
- Device Control:
- In a smart home system, each port can control a set of devices. For example, PORT-0 might control lights in the living room, and PORT-1 might control fans in the bedroom. The registers let you manage these devices efficiently.
- Configuration and Monitoring:
- You can configure each pin for different tasks, read their status to monitor if a button is pressed or a sensor is triggered, and control outputs like turning LEDs on or off.
Practical Example:
Imagine you are programming a microcontroller to control a robot. Each port could manage different parts of the robot, like motors, sensors, and LEDs. By using the registers, you can configure how each part works, read sensor data, and control the motors and LEDs, ensuring the robot functions as intended.
The table provides a concise description of the various registers used for managing PSoC ports, detailing their purpose and usage.
- HSIOM_PORT_SELx:
- Description: This register has 4 bits for each pad, allowing the selection of one of 16 signal options. The default option is GPIO (General Purpose Input/Output).
- Usage: Configure each pad to perform a specific function, such as GPIO, UART, SPI, etc.
2. GPIO_PRT_DR:
- Description: This is the output data register, with one bit per pad. Writing ‘0’ or ‘1’ to the relevant bit position sets the output value of the pin.
- Usage: Control the output state of the pads (e.g., turning an LED on or off).
3. GPIO_PRT_PS:
- Description: This is the input data register, with one bit per pad. Reading the relevant bit position provides the input value (0 or 1) appearing at the pin.
- Usage: Read the state of the pads (e.g., checking if a button is pressed).
4. GPIO_PRT_PC:
- Description: This register has 3 bits per pad, offering a total of 8 configuration options per pad.
- Usage: Configure each pad for different functionalities, such as input, output, pull-up, pull-down, etc.
5. GPIO_PRT_PC2:
- Description: This register has 1 bit per pad, used to set the pad for analog inputs when necessary.
- Usage: Configure pads to serve as analog inputs for applications requiring analog signals.
6. GPIO_PRT_DR_SET:
- Description: This register has 1 bit per pad. Writing a ‘1’ to the relevant bit position sets the output to ‘1’.
- Usage: Quickly set specific pads to high without affecting other bits.
7. GPIO_PRT_DR_CLR:
- Description: This register has 1 bit per pad. Writing a ‘1’ to the relevant bit position sets the output to ‘0’.
- Usage: Quickly set specific pads to low without affecting other bits.
8.DR_INV:
- Description: Specialized register for inverting bits in the data register.
- Function: Writing a ‘1’ to a bit in this register toggles the corresponding bit in the DR register.
9. GPIO_PRT_INTR_CFG:
- Description: This register has 2 bits per pad. It is used to configure the interrupt settings for each pad.
- Usage: Generate interrupt events based on specific conditions, such as a change in pin state.
10. INTR_CFG (Interrupt Configuration):
- Description: Configures additional settings for interrupt handling.
- Function: Defines detailed interrupt behaviors and priorities.
Summary:
Simplified Explanation:
- HSIOM_PORT_SELx:
- What it does: Chooses what each pin will do (default is general use). This register allows you to select the function for each pad, such as GPIO, UART, SPI, etc.
2. GPIO_PRT_DR:
- What it does: Sets if a pin should be on or off. This is the output data register, where writing a ‘1’ or ‘0’ to a bit position sets the pin to high or low, respectively.
3. GPIO_PRT_PS:
- What it does: Reads if a pin is on or off. This is the input data register, where reading a bit position tells you the current state (high or low) of the pin.
4. GPIO_PRT_PC:
- What it does: Configures the pin’s behavior (like input or output). This register determines the drive mode of each pin, such as high impedance, pull-up, pull-down, open drain, or push-pull.
5. GPIO_PRT_PC2:
- What it does: Sets the pin for special analog use. This register configures the pin for analog functionality if needed.
6. GPIO_PRT_DR_SET:
- What it does: Turns the pin on quickly. Writing a ‘1’ to a bit in this register sets the corresponding bit in the DR register to ‘1’.
7. GPIO_PRT_DR_CLR:
- What it does: Turns the pin off quickly. Writing a ‘1’ to a bit in this register clears the corresponding bit in the DR register to ‘0’.
8. GPIO_PRT_DR_INV:
- What it does: Toggles the state of a pin. Writing a ‘1’ to a bit in this register inverts the corresponding bit in the DR register, effectively toggling the pin state.
9.GPIO_PRT_INTR:
- What it does: manages interrupt status. This register indicates the interrupt status for each pin, showing whether an interrupt event has occurred.
10 .GPIO_PRT_INTR_CFG:
- What it does: Sets up the pin to alert the system when something changes. This register configures the conditions under which an interrupt is generated for each pin, such as on rising edge, falling edge, or both
Real-World Example with Actual Use of Bits
Let’s consider a smart home controller that controls a light, reads a button press, configures an analog temperature sensor, and sets up an alarm based on a door sensor. We’ll use specific bits in the registers to manage these functionalities.
Scenario: Smart Home Controller
- HSIOM_PORT_SELx:
- Pin 0 (Temperature Sensor): Set to analog input.
HSIOM_PORT_SELx |= (0x1 << 0); // Set bit 0 for Pin 0 to select analog function.
2. GPIO_PRT_DR:
- Pin 1 (Light Control): Turn on the light by setting the pin high.
GPIO_PRT_DR |= (0x1 << 1); // Set bit 1 to turn on the light
3. GPIO_PRT_PS:
- Pin 2 (Button): Read the button state.
int buttonState = (GPIO_PRT_PS & (0x1 << 2)) >> 2; // Read bit 2 to get button state.
4. GPIO_PRT_PC:
- Pin 1 (Light Control): Configure as output.
GPIO_PRT_PC &= ~(0x7 << (1 * 3)); // Clear 3 bits for Pin 1. GPIO_PRT_PC |= (0x1 << (1 * 3)); // Set Pin 1 as output (binary 001).
5 .GPIO_PRT_PC2:
- Pin 0 (Temperature Sensor): Set as analog input.
GPIO_PRT_PC2 |= (0x1 << 0); // Set bit 0 to configure Pin 0 as analog input.
6. GPIO_PRT_DR_SET:
- Pin 3 (Alarm LED): Turn on the LED.
GPIO_PRT_DR_SET |= (0x1 << 3); // Set bit 3 to turn on the alarm LED.
7. GPIO_PRT_DR_CLR:
- Pin 3 (Alarm LED): Turn off the LED.
GPIO_PRT_DR_CLR |= (0x1 << 3); // Set bit 3 to turn off the alarm LED.
8. GPIO_PRT_INTR_CFG
- Pin 4 (Door Sensor): Configure to generate an interrupt on a falling edge (door opened).
GPIO_PRT_INTR_CFG &= ~(0x3 << (4 * 2)); // Clear 2 bits for Pin 4. GPIO_PRT_INTR_CFG |= (0x2 << (4 * 2)); // Set Pin 4 for falling edge interrupt (binary 10).
Summary:
- HSIOM_PORT_SELx: Configures Pin 0 for an analog temperature sensor.
- GPIO_PRT_DR: Turns on the light connected to Pin 1.
- GPIO_PRT_PS: Reads the button state from Pin 2.
- GPIO_PRT_PC: Configures Pin 1 as an output for light control.
- GPIO_PRT_PC2: Sets Pin 0 as an analog input for the temperature sensor.
- GPIO_PRT_DR_SET: Turns on the alarm LED connected to Pin 3.
- GPIO_PRT_DR_CLR: Turns off the alarm LED connected to Pin 3.
- GPIO_PRT_INTR_CFG: Configures Pin 4 to trigger an interrupt when the door sensor is activated.
Explanation:
This slide outlines the various pad drive modes available for configuring GPIO pins in a PSoC. Each mode defines how the pin behaves in terms of input and output characteristics.
Pad Drive Modes:
- High Impedance Analog (Mode 0):
- Description: The pin is configured as an analog input with high impedance, suitable for connecting to analog signals without affecting them.
- Use Case: Connecting to sensors that output analog signals.
2. High Impedance Digital (Mode 1):
- Description: The pin is configured as a pure digital input with high impedance, not affecting the input signal.
- Use Case: Reading digital signals without interfering with them.
3. Digital Input with Pull-Up Resistor (Mode 2):
- Description: The pin is configured as a digital input with an internal pull-up resistor, pulling the input to a high state when not driven.
- Use Case: Reading signals from buttons or switches that need a default high state.
4. Digital Input with Pull-Down Resistor (Mode 3):
- Description: The pin is configured as a digital input with an internal pull-down resistor, pulling the input to a low state when not driven.
- Use Case: Reading signals from buttons or switches that need a default low state.
5. Digital Output — Open Drain, Drives Low (Mode 4):
- Description: The pin is configured as an open drain output that can drive the line to a low state. The output transistor connects the pin to ground when active.
- Use Case: I2C bus lines where multiple devices share the same line.
6. Digital Output — Open Drain, Drives High (Mode 5):
- Description: The pin is configured as an open drain output that can drive the line to a high state. The output transistor connects the pin to Vdd when active.
- Use Case: Driving loads that require high-side switching.
7. Digital Output — Push-Pull (Mode 6):
- Description: The pin is configured as a push-pull output, capable of driving the line to both high and low states. This mode provides strong drive strength in both directions.
- Use Case: General digital outputs, like driving LEDs or other digital devices.
8. Digital Output — Pull-Up/Pull-Down (Mode 7):
- Description: The pin is configured with both pull-up and pull-down resistors for digital output.
- Use Case: Situations where maintaining a defined state when not actively driven is necessary.
Imagine you have a smart home controller that needs to manage various devices like lights, buttons, a temperature sensor, and an alarm. Here’s how you would use the different pad drive modes without getting into the code details:
Devices and Their Modes:
- Temperature Sensor (Analog Mode):
- Mode Used: Analog Mode (High Impedance Analog)
- Description: The pin is set to read analog signals from the temperature sensor without affecting the signal.
- Why: This ensures the temperature readings are accurate.
2. Button (Digital Input with Pull-Up Resistor):
- Mode Used: Digital Input with Pull-Up Resistor
- Description: The pin is set to read digital signals from the button. When the button isn’t pressed, the pin reads high (1). When pressed, it reads low (0).
- Why: The pull-up resistor keeps the pin in a known high state when the button isn’t pressed, preventing it from floating and reading random values.
3. Light Control (Digital Output — Push-Pull):
- Mode Used: Digital Output — Push-Pull
- Description: The pin is set to control the light, providing strong signals to turn it on or off.
- Why: Push-pull mode ensures the light is clearly turned on or off with a strong signal in both directions.
4. Alarm (Digital Output — Open Drain, Drives Low):
- Mode Used: Digital Output — Open Drain, Drives Low
- Description: The pin is set to activate the alarm by pulling the line low.
- Why: Open drain mode allows multiple devices to control the alarm line without interfering with each other.
5. Door Sensor (Digital Input with Pull-Down Resistor):
- Mode Used: Digital Input with Pull-Down Resistor
- Description: The pin reads signals from the door sensor. When the door is closed, the pin reads low (0). When opened, it reads high (1).
- Why: The pull-down resistor keeps the pin in a known low state when the door is closed, ensuring accurate readings
Summary:
- Temperature Sensor: Uses analog mode to accurately read temperature.
- Button: Uses digital input with a pull-up resistor to detect presses reliably.
- Light Control: Uses push-pull output to turn the light on and off with strong signals.
- Alarm: Uses open drain to allow multiple devices to control the alarm line.
- Door Sensor: Uses digital input with a pull-down resistor to accurately detect if the door is open or closed.
Switch Input Configuration (Continued)
Detailed Register Configuration
- GPIO_PRT3_PC (Port Configuration Register):
- Bits 23–21: These bits configure the drive mode for Pad 7.
- Chosen Mode (DM=0x2): Digital Input with Pull-Up.
- Write
010
into bits 23-21 to set Pad 7 to this mode.
2. GPIO_PRT3_DR (Data Register):
- Bit 7: This bit controls the output data for Pad 7.
- Action: Write
1
to Bit 7 to turn on the upper transistor, connecting Vcc to the pull-up resistor.
HSIOM_PORT_SEL3 Configuration
- HSIOM_PORT_SEL3 (High-Speed Input/Output Matrix Selection):
- Bits 31–28: These bits select the function for Pad 7.
- Chosen Function (GPIO): Write
0000
into bits 31-28 to configure Pad 7 as a general-purpose input/output (GPIO). - Tip: GPIO is often the default selection, so this update might not be required if GPIO is already selected.
Final Programming Sequence
- Programming Steps:
- HSIOM_PORT_SEL3 Configuration:
- Program Bits 31–28 to
0000
to set Pad 7 as GPIO. - GPIO_PRT3_PC Configuration:
- Program Bits 23–21 to
010
to configure the drive mode as Input with Pull-Up. - GPIO_PRT3_DR Configuration:
- Program Bit 7 to
1
to turn on the upper transistor, enabling the pull-up resistor.
Result:
- After programming, Pad 7 of Port 3 is configured as an input with an internal pull-up resistor.
Reading the Input Value:
- GPIO_PRT3_PS (Port State Register):
- Bit 7 of this register corresponds to Pad 7.
- Reading Bit 7 will provide the input value of the switch:
0
when the switch is pressed (connected to ground).1
when the switch is not pressed (pull-up resistor pulls the pin high).
If you liked this article please give a clap! Thank you!