Table of Contents
Overview
This article is going to teach you all the steps required by a beginner to interface a Push Button with TMS320F28379D. In this article, you are going to learn about how to make a pin input in TMS320F28379D and how to read a Digital pin in TMS320F28379D. Things you should have before continuing.
Required Hardware Components
Hardware
- Launchxl-f28379d
- Push button
- Led
Software:
- Code Composer Studio
Bill of Materials
S.No | COMPONENTS | DESCRIPTION | QUANTITY | |
1 | Launchxl-f28379d | Launchxl-f28379d | 1 | https://evelta.com/launchxl-f28379d-c2000 |
2 | LED | LED | 1 | https://www.amazon.in/Traffic-Lights-Signal-Module-Digital |
6 | Jumper Wires | Jumper Wires | 40 | https://www.amazon.in/YUVS-Jumper-Wires-female-Pieces |
Introduction
In this project, I am going to control the On-Board LED with a Push Button. By this, you are going to learn about how to read and write a pin digitally.
Circuit Diagram
Gpio Connection
GPIO_34 | OUTPUT_LED |
GPIO_67 | INPUT_PUSH_BUTTON |
Step_1
Configure GPIO Pins For OUT_Put Pin
GPIO_setPinConfig(DEVICE_GPIO_PIN_LED2);
GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED2, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(DEVICE_GPIO_PIN_LED2, GPIO_PIN_TYPE_STD);
GPIO_setMasterCore(DEVICE_GPIO_PIN_LED2, GPIO_CORE_CPU1);
Configure GPIO Pins For OUT_Put Pin
// select input gpio pin
GPIO_setPinConfig(GPIO_67_GPIO67);
GPIO_setDirectionMode(67, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(67, GPIO_PIN_TYPE_PULLUP); // Pull-up enable for input
GPIO_setMasterCore(67, GPIO_CORE_CPU1);
Create function for gpio configurations
{
// select input gpio pin
GPIO_setPinConfig(GPIO_67_GPIO67);
GPIO_setDirectionMode(67, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(67, GPIO_PIN_TYPE_PULLUP); // Pull-up enable for input
GPIO_setMasterCore(67, GPIO_CORE_CPU1);
// select output gpio pin
GPIO_setPinConfig(DEVICE_GPIO_PIN_LED2);
GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED2, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(DEVICE_GPIO_PIN_LED2, GPIO_PIN_TYPE_STD);
GPIO_setMasterCore(DEVICE_GPIO_PIN_LED2, GPIO_CORE_CPU1);
}
Turn ON led Command (Set 1 for ON)
GPIO_writePin(DEVICE_GPIO_PIN_LED2, 1);
Turn OFF Led Command (Set 0 for OFF)
GPIO_writePin(DEVICE_GPIO_PIN_LED2, 0);
Final Code
/*
* main.c
*
* Created on: 26-Nov-2021
* Author: Admin
*/
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "F28x_Project.h"
#include "F2837xD_device.h"
#include "F2837xD_Examples.h"
#include "device.h"
#include "driverlib.h"
void gpio_init();
void main(void)
{
Device_init();
Device_initGPIO();
gpio_init();
while(1)
{
if(GPIO_readPin(67) == 0)
{
GPIO_writePin(DEVICE_GPIO_PIN_LED2, 1);
DEVICE_DELAY_US(10000);
GPIO_writePin(DEVICE_GPIO_PIN_LED2, 0);
DEVICE_DELAY_US(10000);
}
if(GPIO_readPin(67)==1)
{
GPIO_writePin(DEVICE_GPIO_PIN_LED2, 1);
DEVICE_DELAY_US(10000);
}
}
}
void gpio_init()
{
// select input gpio pin
GPIO_setPinConfig(GPIO_67_GPIO67);
GPIO_setDirectionMode(67, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(67, GPIO_PIN_TYPE_PULLUP); // Pull-up enable for input
GPIO_setMasterCore(67, GPIO_CORE_CPU1);
// select output gpio pin
GPIO_setPinConfig(DEVICE_GPIO_PIN_LED2);
GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED2, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(DEVICE_GPIO_PIN_LED2, GPIO_PIN_TYPE_STD);
GPIO_setMasterCore(DEVICE_GPIO_PIN_LED2, GPIO_CORE_CPU1);
}