GPIO.c - Using the GPIO as output

David Valencia January 31, 20114 comments Coded in C for the TI C67x

Please see the laboratory guide in the following link:

SPANISH: http://www.box.net/shared/kauqx5i8nd

ENGLISH: Coming soon!

// GPIO.c	UPIITA-IPN 
// JOSE DAVID VALENCIA PESQUEIRA
//
// THIS PROGRAM ALLOWS THE DSP TO SEND A BIT THROUGH A GPIO PIN (PIN 7 IN THIS EXAMPLE)
// TO TURN ON A LED ON

#include <stdio.h>
#include <stdlib.h>
#include <csl_gpio.h>
#include <csl_gpiohal.h>
#include <csl_irq.h>

// GLOBAL VARIABLES
volatile int flag = 1;
volatile int pulse_flag = 1;

// CODE TO DEFINE GPIO HANDLE
GPIO_Handle gpio_handle; 

// GPIO REGISTER CONFIGURATION
GPIO_Config gpio_config = {         
    0x00000000, // gpgc = Interruption passthrough mode
    0x0000FFFF, // gpen = All GPIO 0-15 pins enabled
    0x0000FFFF, // gdir = All GPIO pins as outputs
    0x00000000, // gpval = Saves the logical states of pins
    0x00000000, // gphm All interrupts disabled for IO pins
    0x00000000, // gplm All interrupts for CPU EDMA disabled
    0x00000000  // gppol -- default state */
};

// Function prototypes
void send_edge();
void delay();

// Function definitions
void delay()
{
	// Delay function
	int count, count2;
	for(count = 0; count < 200; count++)
	{
		for(count2 = 0; count2 < 50000; count2++);
	}
}

void send_edge()
{	
    DSK6713_init();  
    // Open and configure the GPIO
    gpio_handle = GPIO_open( GPIO_DEV0, GPIO_OPEN_RESET );
    GPIO_config(gpio_handle,&gpio_config);
    // Send values through the pins
	
    GPIO_pinWrite(gpio_handle,GPIO_PIN7,0);
    delay();
    GPIO_pinWrite(gpio_handle,GPIO_PIN7,1);
    delay();
    GPIO_pinWrite(gpio_handle,GPIO_PIN7,0);
}

main()
{     
	send_edge(); // Configures the pins and sends a rising edge
	printf(“ ¡Felicidades! ¡Has logrado encender el led! ”);
	
}
// End of program>>

Comments:

David VP
Said:
UPDATE: Code comments translated to English.
8 years ago
0
Reply
Sorry, you need javascript enabled to post any comments.
27dk
Said:
hello pl. tell how to connect 20pin dio on t2pc board thanks 27dksingh@gmail.com
7 years ago
0
Reply
Sorry, you need javascript enabled to post any comments.
David VP
Said:
Dear 27dk, First of all I don't know what are you refering to with "t2pc" board. Please give us more information so we are able to help you.
7 years ago
0
Reply
Sorry, you need javascript enabled to post any comments.
navaneethkarthi
Said:
HI Guys,

I was successfully able to write data using this code. Can i know what modification i need to make to read the data from GPIO Port.
4 years ago
0
Reply
Sorry, you need javascript enabled to post any comments.
Sorry, you need javascript enabled to post any comments.