Trouble with GPIO on LPC810, pin 0_5

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trouble with GPIO on LPC810, pin 0_5

459 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vsluiter on Tue Aug 06 07:34:07 MST 2013
Hello All,

I'm having trouble reading the pin status (high or low) from pin 0_5 on the minikit. I'm trying to make a persistence of vision gadget where I've hooked up an SPI shift register to 8 LEDs and the LPC810, and use the multirate timer to write to the LED array. That is all working, but somehow the simple reading of an IO pin fails. It keeps reading as 'zero' while I can verify that the pin's input voltage changes state (checked with oscilloscope). Could anyone please take a look at my code and suggest me what I'm doing wrong? I'm using the LPCxpresso toolchain.

/*
===============================================================================
 Name        : main.c
 Author      : $(author)
 Version     :
 Copyright   : $(copyright)
 Description : main definition
===============================================================================
*/

#ifdef __USE_CMSIS
#include "LPC8xx.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>



// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

// TODO: insert other include files here
#include "lpc8xx_spi.h"
#include "lpc8xx_gpio.h"
//#include "lpc8xx_mrt.h" //functions not used; only used for defines
#include "font.h"
// TODO: insert other definitions and declarations here

/* MRT Control register bit definition. */
#define MRT_INT_ENA(0x1<<0)
#define MRT_REPEATED_MODE(0x00<<1)
#define MRT_ONE_SHOT_INT(0x01<<1)
#define MRT_ONE_SHOT_STALL(0x02<<1)

/* MRT Status register bit definition */
#define MRT_STAT_IRQ_FLAG(0x1<<0)
#define MRT_STAT_RUN(0x1<<1)
void MRT_IRQHandler(void);
void mrt_set_timer(uint8_t, uint32_t);
void init__mrt(void);
void SwitchMatrix_Init(void);
void IOCON_Init();

volatile uint8_t PoVnextLine = 0;
volatile uint8_t next_charrow = 0;

int main(void) {
const uint8_t PoVstring[]="<<GOGBOT 2014>>";
uint8_t PoVstring_index = 0;
uint8_t PoVstring_charrow = 0;
    // TODO: insert code here

GPIOInit();
SwitchMatrix_Init();
IOCON_Init();

init__mrt();
mrt_set_timer(0,12000); //1kHz timer
mrt_set_timer(1,100000); //10 Hz timer
mrt_set_timer(2,24000);   //500 Hz timer
SPI_Init(LPC_SPI0,19,(CFG_ENABLE|/*CFG_CPHA|CFG_CPOL|*/CFG_MASTER|CFG_MOSIDRV),0);

//GPIOSetDir(PORT0,5,0);

    while(1)
    {
    if(PoVnextLine)
    {
    PoVnextLine = 0;
        for(PoVstring_index = 0; PoVstring_index < sizeof(PoVstring); PoVstring_index++)
        {
        //if(!GPIOGetPinValue(0,5))
        //{
               for(PoVstring_charrow = 0; PoVstring_charrow < 8 ; PoVstring_charrow++)
{
               static uint8_t pinvalue;
while(!next_charrow);
pinvalue = GPIOGetPinValue(PORT0,5);
next_charrow = 0;
SPI_Send(LPC_SPI0 \
,0 \
,&pinvalue/*&font_8x8[PoVstring[PoVstring_index]-0x20][PoVstring_charrow]*/ \
,1);
}
        //}
        //else
        //{
        //while(GPIOGetPinValue(0,5));
        //}
        }
    }

    }
    return 0 ;
}

void IOCON_Init() {

    /* Enable UART clock */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<18);

    /* Pin I/O Configuration */
    LPC_IOCON->PIO0_0 = 0x80;
    LPC_IOCON->PIO0_1 = 0x80;
    /* LPC_IOCON->PIO0_2 = 0x90; */
    /* LPC_IOCON->PIO0_3 = 0x90; */
    /* LPC_IOCON->PIO0_4 = 0x90; */
    LPC_IOCON->PIO0_5 = 0x90;
}


void SwitchMatrix_Init()
{
    /* Enable SWM clock */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);

    /* Pin Assign 8 bit Configuration */
    /* SPI0_SCK */
    LPC_SWM->PINASSIGN3 = 0x02ffffffUL;
    /* SPI0_MOSI */
    /* SPI0_SSEL */
    LPC_SWM->PINASSIGN4 = 0xff04ff03UL;

    /* Pin Assign 1 bit Configuration */
    /* ACMP_I1 */
    /* ACMP_I2 */
    LPC_SWM->PINENABLE0 = 0xfffffffcUL;
}


/******************************************************************************
** Function name:MRT_IRQHandler
**
** Descriptions:MRT interrupt handler
**
** parameters:None
** Returned value:None
**
******************************************************************************/
void MRT_IRQHandler(void)
{
  if ( LPC_MRT->Channel[0].STAT & MRT_STAT_IRQ_FLAG )
  {
LPC_MRT->Channel[0].STAT = MRT_STAT_IRQ_FLAG;/* clear interrupt flag */
//mrt_counter++;
  }
  if ( LPC_MRT->Channel[1].STAT & MRT_STAT_IRQ_FLAG )
  {
LPC_MRT->Channel[1].STAT = MRT_STAT_IRQ_FLAG;/* clear interrupt flag */
PoVnextLine = 1;
  }
  if ( LPC_MRT->Channel[2].STAT & MRT_STAT_IRQ_FLAG )
  {
LPC_MRT->Channel[2].STAT = MRT_STAT_IRQ_FLAG;/* clear interrupt flag */
next_charrow = 1;
  }
  return;
}

void mrt_set_timer(uint8_t channel, uint32_t TimerInterval )
{
//mrt_counter = 0;
LPC_MRT->Channel[channel].INTVAL = TimerInterval;
LPC_MRT->Channel[channel].INTVAL |= 0x1UL<<31;
LPC_MRT->Channel[channel].CTRL = MRT_REPEATED_MODE|MRT_INT_ENA;
}

/******************************************************************************
** Function name:init_timer
**
** Descriptions:Initialize timer, set timer interval, reset timer,
**install timer interrupt handler
**
** parameters:none
** Returned value:None
**
******************************************************************************/
void init__mrt(void)
{
  /* Enable clock to MRT and reset the MRT peripheral */
  LPC_SYSCON->SYSAHBCLKCTRL |= (0x1<<10);
LPC_SYSCON->PRESETCTRL &= ~(0x1<<7);
LPC_SYSCON->PRESETCTRL |= (0x1<<7);



  /* Enable the MRT Interrupt */
#if NMI_ENABLED
NVIC_DisableIRQ( MRT_IRQn );
NMI_Init( MRT_IRQn );
#else
  NVIC_EnableIRQ(MRT_IRQn);
#endif
  return;
}


Greetings,
Victor
Labels (1)
0 Kudos
1 Reply

345 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vsluiter on Wed Aug 07 04:29:26 MST 2013
Found the problem, it was in hardware and not in software; When soldering the input I inadvertently also shorted one of the LED array control wires, thus disabling the display...  The input was fine, the wiring not. Glad I found it....
0 Kudos