GPIO Problem

Hi,

I'm trying to configure my tactile switches to send a LOW to the GPIO pins D0, D1, D2, D6(PPI) in PORTB. I started the project in the TalkThrough_BF706Mini project because I wanted to test putting a stereo signal through first and the audio part of the program worked. I have since started adding functionality to the project with a protoboard and adding my own code, have marked my code for your convenience. I have included the schematic and a picture of my protoboard. PLEASE ignore the incorrect data pin assignments on the schematic for the switches. I can assure you the switches are connected to P4 NOT the UNO compatibility headers. Also, I am using the default state of EPPI0_CLK(P4, PIN 11) to supply 3.3V to the switches.  I am not using an Arduino Uno either just a protoboard and the ADSP-BF706 EZ Kit MINI. 

The problem is:

-When I press switches that are connected to D0, D1 and D2 I get a hex value of 0x0000F980.

-When I press the switch connected to D6 I get a value of 0x0000F900.

-When nothing is pressed I get a value of 0x0000F9E2 

Each individual switch press should return a different hex value because the bits would be low in the register! However, this is not the case.

Any help is appreciated thank you!

 

Also If I could get some help initializing the SPI display afterward as well that would be greatly appreciated!

Here is my code.

/*********************************************************************************

Copyright(c) 2015 Analog Devices, Inc. All Rights Reserved.

This software is proprietary and confidential. By using this software you agree
to the terms of the associated Analog Devices License Agreement.

*********************************************************************************/

/*
*
* This example demonstrates how to use the ADAU1761 codec driver to receive audio
* samples from the Line Input and transmit those audio samples to the headphone
* output (talkthrough).
*
 * On the ADSP-BF706 EZ-KIT MiniTm:
* Connect an audio source to the LINE IN jack (J1)
* Connect headphones to the HP jack (J2).
*/

#include <drivers/codec/adau1761/adi_adau1761.h>
#include <services/pwr/adi_pwr.h>
#include <stdio.h>
#include <string.h>
#include <services/gpio/adi_gpio.h>
#include <services/tmr/adi_ctmr.h>

/* SigmaStudio exported file */
#include "SigmaStudio\export\export_IC_1.h"

#include "TalkThrough_BF706Mini.h"

/* ADI initialization header */
#include "system/adi_initialize.h"

/* User Macro - select sample rate */
#define SAMPLE_RATE (ADI_ADAU1761_SAMPLE_RATE_48KHZ)

/* User Macro - select the number of audio samples (stereo) for each buffer */
#define NUM_AUDIO_SAMPLES 64u /* 32 left + 32 right */

/* 32-bits per sample (24-bit audio) */
#define BUFFER_SIZE (NUM_AUDIO_SAMPLES*sizeof(uint32_t))

/* used for exit timeout */
#define MAXCOUNT (500000u)

/*
* SPORT device memory
*/
#pragma align(4)
static uint8_t sportRxMem[ADI_SPORT_DMA_MEMORY_SIZE];

#pragma align(4)
static uint8_t sportTxMem[ADI_SPORT_DMA_MEMORY_SIZE];

/*
* Audio buffers
*/
#pragma align(4)
static uint32_t RxBuffer1[NUM_AUDIO_SAMPLES];

#pragma align(4)
static uint32_t RxBuffer2[NUM_AUDIO_SAMPLES];

#pragma align(4)
static uint32_t TxBuffer1[NUM_AUDIO_SAMPLES];

#pragma align(4)
static uint32_t TxBuffer2[NUM_AUDIO_SAMPLES];


/* audio buffer pointers */
static uint32_t *pRxAudioBuffer;
static uint32_t *pTxAudioBuffer;

/* SPORT info struct */
static ADI_ADAU1761_SPORT_INFO sportRxInfo;
static ADI_ADAU1761_SPORT_INFO sportTxInfo;

typedef enum
{
NONE,
START_TALKTHROUGH,
TALKTHROUGH,
STOP_TALKTHROUGH
} MODE;

static MODE eMode = NONE;

/* Memory required for codec driver - must add PROGRAM_SIZE_IC_1 size for data transfer to codec */
static uint8_t codecMem[ADI_ADAU1761_MEMORY_SIZE + PROGRAM_SIZE_IC_1];

/* adau1761 device handle */
static ADI_ADAU1761_HANDLE hADAU1761;

static bool bError;
static volatile uint32_t count;

/* error check */
static void CheckResult(ADI_ADAU1761_RESULT result)
{
if (result != ADI_ADAU1761_SUCCESS) {
printf("Codec failure\n");
bError = true;
}
}

/* codec record mixer */
static void MixerEnable(bool bEnable)
{
ADI_ADAU1761_RESULT result;
uint8_t value;

if (bEnable)
{
/* enable the record mixer (left) */
result = adi_adau1761_SetRegister (hADAU1761, REC_MIX_LEFT_REG, 0x0B); /* LINP mute, LINN 0 dB */
CheckResult(result);

/* enable the record mixer (right) */
result = adi_adau1761_SetRegister (hADAU1761, REC_MIX_RIGHT_REG, 0x0B); /* RINP mute, RINN 0 dB */
CheckResult(result);
}
else
{
/* disable the record mixer (left) */
result = adi_adau1761_GetRegister (hADAU1761, REC_MIX_LEFT_REG, &value);
result = adi_adau1761_SetRegister (hADAU1761, REC_MIX_LEFT_REG, value & 0xFE);
CheckResult(result);

/* disable the record mixer (right) */
result = adi_adau1761_GetRegister (hADAU1761, REC_MIX_RIGHT_REG, &value);
result = adi_adau1761_SetRegister (hADAU1761, REC_MIX_RIGHT_REG, value & 0xFE);
CheckResult(result);
}
}

/* codec driver configuration */
static void CodecSetup(void)
{
ADI_ADAU1761_RESULT result;

/* Open the codec driver */
result = adi_adau1761_Open(ADAU1761_DEV_NUM,
codecMem,
sizeof(codecMem),
ADI_ADAU1761_COMM_DEV_TWI,
&hADAU1761);
CheckResult(result);

/* Configure TWI - BF706 EZ-Kit MINI version 1.0 uses TWI */
result = adi_adau1761_ConfigTWI(hADAU1761, TWI_DEV_NUM, ADI_ADAU1761_TWI_ADDR0);
CheckResult(result);

/* load Sigma Studio program exported from *_IC_1.h */
result = adi_adau1761_SigmaStudioLoad(hADAU1761, default_download_IC_1);
CheckResult(result);

/* config SPORT for Rx data transfer */
sportRxInfo.nDeviceNum = SPORT_RX_DEVICE;
sportRxInfo.eChannel = ADI_HALF_SPORT_B;
sportRxInfo.eMode = ADI_ADAU1761_SPORT_I2S;
sportRxInfo.hDevice = NULL;
sportRxInfo.pMemory = sportRxMem;
sportRxInfo.bEnableDMA = true;
sportRxInfo.eDataLen = ADI_ADAU1761_SPORT_DATA_24;
sportRxInfo.bEnableStreaming = true;

result = adi_adau1761_ConfigSPORT (hADAU1761,
ADI_ADAU1761_SPORT_INPUT, &sportRxInfo);
CheckResult(result);

/* config SPORT for Tx data transfer */
sportTxInfo.nDeviceNum = SPORT_TX_DEVICE;
sportTxInfo.eChannel = ADI_HALF_SPORT_A;
sportTxInfo.eMode = ADI_ADAU1761_SPORT_I2S;
sportTxInfo.hDevice = NULL;
sportTxInfo.pMemory = sportTxMem;
sportTxInfo.bEnableDMA = true;
sportTxInfo.eDataLen = ADI_ADAU1761_SPORT_DATA_24;
sportTxInfo.bEnableStreaming = true;

result = adi_adau1761_ConfigSPORT (hADAU1761,
ADI_ADAU1761_SPORT_OUTPUT, &sportTxInfo);
CheckResult(result);

result = adi_adau1761_SelectInputSource(hADAU1761, ADI_ADAU1761_INPUT_ADC);
CheckResult(result);

/* disable mixer */
MixerEnable(false);

result = adi_adau1761_SetVolume (hADAU1761,
ADI_ADAU1761_VOL_HEADPHONE,
ADI_ADAU1761_VOL_CHAN_BOTH,
true,
57); /* 0 dB */
CheckResult(result);

result = adi_adau1761_SetSampleRate (hADAU1761, SAMPLE_RATE);
CheckResult(result);
}

/***********************************************************MY CODE****************************************************************************************************************************/
/*GPIO Definitions and Variables*/

uint32_t pin_dir;
uint32_t pin_read;
/****************************************************************************************************************************************************************************************/
int main(void)
{

bool bExit;
bool bRxAvailable;
bool bTxAvailable;
ADI_ADAU1761_RESULT result;
ADI_PWR_RESULT pwrResult;

bExit = false;

/* setup processor mode and frequency */
pwrResult = adi_pwr_Init(0, CLKIN);
pwrResult = adi_pwr_SetPowerMode(0, ADI_PWR_MODE_FULL_ON);
pwrResult = adi_pwr_SetClkControlRegister(0, ADI_PWR_CLK_CTL_MSEL, MSEL);
pwrResult = adi_pwr_SetClkDivideRegister(0, ADI_PWR_CLK_DIV_CSEL, CSEL);
pwrResult = adi_pwr_SetClkDivideRegister(0, ADI_PWR_CLK_DIV_SYSSEL, SYSSEL);

adi_initComponents(); /* auto-generated code */

/* configure the codec driver */
CodecSetup();

count = 0u;
eMode = START_TALKTHROUGH;
/************************************************MY CODE*************************************************************************************************************************/

adi_gpio_SetDirection(ADI_GPIO_PORT_B, ADI_GPIO_PIN_1|ADI_GPIO_PIN_2|ADI_GPIO_PIN_3|ADI_GPIO_PIN_4|ADI_GPIO_PIN_5|ADI_GPIO_PIN_6|ADI_GPIO_PIN_7|ADI_GPIO_PIN_8|ADI_GPIO_PIN_9|ADI_GPIO_PIN_10|ADI_GPIO_PIN_11|ADI_GPIO_PIN_12|ADI_GPIO_PIN_13|ADI_GPIO_PIN_14|ADI_GPIO_PIN_15, ADI_GPIO_DIRECTION_INPUT);
//adi_gpio_Clear(ADI_GPIO_PORT_B, ADI_GPIO_PIN_1|ADI_GPIO_PIN_2|ADI_GPIO_PIN_3|ADI_GPIO_PIN_4|ADI_GPIO_PIN_5|ADI_GPIO_PIN_6|ADI_GPIO_PIN_7|ADI_GPIO_PIN_8|ADI_GPIO_PIN_9|ADI_GPIO_PIN_10|ADI_GPIO_PIN_11|ADI_GPIO_PIN_12|ADI_GPIO_PIN_13|ADI_GPIO_PIN_14|ADI_GPIO_PIN_15);

/*to read pin logic state*/
while(1)
{
adi_gpio_GetData(ADI_GPIO_PORT_B, &pin_read);
}
/*************************************************************************************************************************************************************************/

while(!bExit && !bError)
{
switch(eMode)
{
case START_TALKTHROUGH:

/* stop current input */
result = adi_adau1761_EnableInput (hADAU1761, false);
CheckResult(result);

/* stop current output */
result = adi_adau1761_EnableOutput (hADAU1761, false);
CheckResult(result);

/* submit Rx buffer1 */
result = adi_adau1761_SubmitRxBuffer(hADAU1761, RxBuffer1, BUFFER_SIZE);
CheckResult(result);

/* submit Rx buffer2 */
result = adi_adau1761_SubmitRxBuffer(hADAU1761, RxBuffer2, BUFFER_SIZE);
CheckResult(result);

/* submit Tx buffer1 */
result = adi_adau1761_SubmitTxBuffer(hADAU1761, TxBuffer1, BUFFER_SIZE);
CheckResult(result);

/* submit Tx buffer2 */
result = adi_adau1761_SubmitTxBuffer(hADAU1761, TxBuffer2, BUFFER_SIZE);
CheckResult(result);

result = adi_adau1761_EnableInput (hADAU1761, true);
CheckResult(result);

result = adi_adau1761_EnableOutput (hADAU1761, true);
CheckResult(result);

/* enable record mixer */
MixerEnable(true);

eMode = TALKTHROUGH;
break;
case TALKTHROUGH:
result = adi_adau1761_GetRxBuffer (hADAU1761, (void**)&pRxAudioBuffer);
CheckResult(result);

if (pRxAudioBuffer != NULL)
{
/* re-submit buffer */
result = adi_adau1761_SubmitRxBuffer(hADAU1761, pRxAudioBuffer, BUFFER_SIZE);
CheckResult(result);

/* get an available Tx buffer */
result = adi_adau1761_GetTxBuffer (hADAU1761, (void**)&pTxAudioBuffer);
CheckResult(result);

if (pTxAudioBuffer != NULL)
{
/*
* Insert audio algorithm here
*/

/* talkthrough - copy the audio data from Rx to Tx */
memcpy(&pTxAudioBuffer[0], &pRxAudioBuffer[0], BUFFER_SIZE);

/*
* End audio algorithm
*/

/* re-submit buffer */
result = adi_adau1761_SubmitTxBuffer(hADAU1761, pTxAudioBuffer, BUFFER_SIZE);
CheckResult(result);
}

}
break;
case STOP_TALKTHROUGH:
result = adi_adau1761_EnableInput (hADAU1761, false);
CheckResult(result);

result = adi_adau1761_EnableOutput (hADAU1761, false);
CheckResult(result);

eMode = NONE;
bExit = true;
break;

default:
break;
}

/* exit the loop after a while */
if (count > MAXCOUNT)
{
eMode = STOP_TALKTHROUGH;
}
count++;

}

result = adi_adau1761_Close(hADAU1761);
CheckResult(result);

if (!bError) {
printf("All done\n");
} else {
printf("Audio error\n");
}


return 0;
}