LPC1343, How to use ADC channels shared with JTAG

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

LPC1343, How to use ADC channels shared with JTAG

1,898 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Riggox on Wed Apr 25 11:06:06 MST 2012
Hi,
I have a project where im able to poll AD channels 5-7 and get their values but I can not manage to get the first 5 channels to work. Im aware that my problem depends on the fact that these pins are used for the JTAG during the debugging.

I have tried to use the program flash button instead of debugging but without success. Do I have to manually set some other register (except the iocon register for the pins) for the processor to understand that these ADC pins will be used for ADC?

Any help would be really appreciated.

//Riggox
0 Kudos
Reply
13 Replies

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Apr 26 09:45:51 MST 2012
Also I don't know what's the result of  your ANDing and ORing IOCON registers :confused:

Sooner or later they should end in something like:

//use AD0-3 and AD5-7, don't use AD4(SWDIO)
 LPC_IOCON->R_PIO0_11= (1<<6)|(2<<0);      //select AD0
 LPC_IOCON->R_PIO1_0 = (1<<6)|(2<<0);      //select AD1
 LPC_IOCON->R_PIO1_1 = (1<<6)|(2<<0);      //select AD2
 LPC_IOCON->R_PIO1_2 = (1<<6)|(2<<0);      //select AD3
 LPC_IOCON->PIO1_4   = (1<<6)|(1<<0);      //select AD5
 LPC_IOCON->PIO1_10  = (1<<6)|(1<<0);      //select AD6
 LPC_IOCON->PIO1_11  = (1<<6)|(1<<0);      //select AD7
0 Kudos
Reply

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Apr 26 07:12:19 MST 2012
You should clean, export and post your project.

No one knows if things like '__JTAG_DISABLED' are defined or not and which project settings you are running :confused:


Quote:
...hardware is simply the LPC1343

What is 'simply the LPC1343'? A custom board or LPCXpresso1343 target board :confused:
0 Kudos
Reply

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Riggox on Thu Apr 26 06:56:12 MST 2012
My hardware is simply the LPC1343 and a DC power supply to test the ADC.

I have tried to copy the relevant parts of the code. If something is missing please say so and Ill add it.
The relevant code:

Main.c
LEDs works and the declarations are taken from the Blinky example project.
int main(void) {
    SysTick_Config( SystemCoreClock/1000 );
    SysTick->CTRL &= (0 << 1);
    ADCInit( ADC_CLK );
    GPIOSetDir( LED_PORT, LED_BIT, 1 );
    GPIOSetValue( LED_PORT, LED_BIT, LED_ON );

    while(1)
    {
        if(reflexRead())
        {
            GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );
        }
        else
        {
            GPIOSetValue( LED_PORT, LED_BIT, LED_ON );
        }
    }
    return 0 ;
}
The reflexRead function
uint16_t reflexRead()
{
    uint32_t i = 4;
    for ( i = 4; i <= 5; i++ )
    {
        reflexValue = ADCRead( i );
        if( reflexValue >= 500 )
        {
            return 1;
        }
    }
    return 0;
}
adc.c
I have used code from the example project adc and tried to change it to work for polling instead of interrupts.
Using GPIOSetDir from the example project GPIO
#include "LPC13xx.h"            /* LPC13xx Peripheral Registers */
#include "adc.h"

void ADCInit( uint32_t ADC_Clk )
{
  /* Disable Power down bit to the ADC block. */
  LPC_SYSCON->PDRUNCFG &= ~(0x1<<4);

  /* Enable AHB clock to the ADC. */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<13);
  GPIOSetDir( 1, 3, 0 ); //AD4 input
  GPIOSetDir( 1, 4, 0 ); //AD5 input
  GPIOSetDir( 1, 10, 0 );//AD6 input
  GPIOSetDir( 1, 11, 0 );//AD7 input

#ifdef __JTAG_DISABLED
#ifdef __SWD_DISABLED
  LPC_IOCON->ARM_SWDIO_PIO1_3   &= ~0x8F;
  LPC_IOCON->ARM_SWDIO_PIO1_3   |= 0x02;  /* ADC IN4 */
#endif
#endif
  LPC_IOCON->PIO1_4 &= ~0x8F; 
  LPC_IOCON->PIO1_4 |= 0x01; /* ADC IN5 */
  LPC_IOCON->PIO1_10 &= ~0x8F; 
  LPC_IOCON->PIO1_10 |= 0x01; /* ADC IN6 */
  LPC_IOCON->PIO1_11 &= ~0x8F; 
  LPC_IOCON->PIO1_11 |= 0x01; /* ADC IN7 */

  LPC_ADC->CR = ((SystemCoreClock/LPC_SYSCON->SYSAHBCLKDIV)/ADC_Clk-1)<<8;
  return;
}

/*****************************************************************************
** Function name:        ADCRead
**
** Descriptions:        Read ADC channel
**
** parameters:            Channel number
** Returned value:        Value read, if interrupt driven, return channel #
**
*****************************************************************************/
uint32_t ADCRead( uint8_t channelNum )
{
#if !ADC_INTERRUPT_FLAG
  uint32_t regVal, ADC_Data;
#endif

  /* channel number is 0 through 7 */
  if ( channelNum >= ADC_NUM )
  {
    channelNum = 0;        /* reset channel number to 0 */
  }
  LPC_ADC->CR &= 0xFFFFFF00; // clear channel selection
  LPC_ADC->CR |= (1 << 24) | (1 << channelNum);
                /* switch channel,start A/D convert */
#if !ADC_INTERRUPT_FLAG
  while ( 1 )            /* wait until end of A/D convert */
  {
    regVal = *(volatile unsigned long *)(LPC_ADC_BASE
            + ADC_OFFSET + ADC_INDEX * channelNum);
    /* read result of A/D conversion */
    if ( regVal & ADC_DONE )
    {
      break;
    }
  }

  LPC_ADC->CR &= 0xF8FFFFFF;    /* stop ADC now */
  if ( regVal & ADC_OVERRUN )    /* save data when it's not overrun, otherwise, return zero */
  {
    return ( 0 );
  }
  ADC_Data = ( regVal >> 6 ) & 0x3FF;
  return ( ADC_Data );    /* return A/D conversion value */
#else
  return ( channelNum );    /* if it's interrupt driven, the ADC reading is
                            done inside the handler. so, return channel number */
#endif
}
and adc.h

#ifndef ADC_H_
#define ADC_H_/*****************************************************************************
 *   adc.h:  Header file for NXP LPC134x Family Microprocessors
 *
 *   Copyright(C) 2008, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2008.07.19  ver 1.00    Preliminary version, first Release
 *
******************************************************************************/
#ifndef __ADC_H
#define __ADC_H

#include "gpio.h"
#define ADC_INTERRUPT_FLAG    0    /* 1 is interrupt driven, 0 is polling */
#define BURST_MODE            0   /* Burst mode works in interrupt driven mode only. */
#define ADC_DEBUG            1

#define ADC_OFFSET        0x10
#define ADC_INDEX        4

#define ADC_DONE        0x80000000
#define ADC_OVERRUN        0x40000000
#define ADC_ADINT        0x00010000

#define ADC_NUM            8            /* for LPC13xx */
#define ADC_CLK            4500000        /* set to 4.5Mhz */

extern void ADC_IRQHandler( void );
extern void ADCInit( uint32_t ADC_Clk );
extern uint32_t ADCRead( uint8_t channelNum );
extern void ADCBurstRead( void );
#endif /* end __ADC_H */
/*****************************************************************************
**                            End Of File
******************************************************************************/

#endif /* ADC_H_ */
0 Kudos
Reply

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by daan-ter-horst on Thu Apr 26 06:48:32 MST 2012

Quote: Zero
So the answer is easy again: If you have switched off your SWD, ADC is not working automatically :(

Since I'm no clairvoyant I don't know which hardware you are using and what you have done already to avoid problems with SWD hardware :confused:

Also I don't know you code :)



maybe you could post your code that your using trying to get the ADC pins working. please mention to use the code tags arround your code
0 Kudos
Reply

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Apr 26 06:12:46 MST 2012

Quote: Riggox
...but why is it not working as a ADC instead?



So the answer is easy again: If you have switched off your SWD, ADC is not working automatically :(

Since I'm no clairvoyant I don't know which hardware you are using and what you have done already to avoid problems with SWD hardware :confused:

Also I don't know you code :)
0 Kudos
Reply

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Riggox on Thu Apr 26 05:58:23 MST 2012

Quote: Zero
:confused:

If you change SWD pin functions, SWD is not working any longer :eek:

What's unclear there :confused:

To reprogram your chip you have to switch to ISP (and use SWD again) or use ISP bootloader via UART or USB (at LPC1343) .



I was abit unclear there. I understand why I get the status wire error but I dont understand why the pin is not able to work as a ADC even after I have reprogrammed the pin to work as one. Obviously I change something on the pin since it is not keeping its SWD function, but why is it not working as a ADC instead?
0 Kudos
Reply

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vinod on Thu Apr 26 05:25:17 MST 2012
i am getting this problem on lpc1114 controller..so pls can u tel in details that which pin should be ground..

Quote:

Quote: Riggox
Sounds like you are having the same problem I am. From what i have been able to understand this error is because you are programming the SWDIO pin to do something else than its SWDIO duties. To be able to program the processor again, ground the isp pin (Pin 0.1 on LPC1343), reset the processor and then try to flash program a working code.

Im hoping someone else can explain how this problem can be avoided tho', since that is probably why my code isnt working.

0 Kudos
Reply

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vinod on Thu Apr 26 05:24:45 MST 2012
i am getting this problem on lpc1114 controller..so pls can u tel in details that which pin should be ground..

Quote: Zero
:confused:

If you change SWD pin functions, SWD is not working any longer :eek:

What's unclear there :confused:

To reprogram your chip you have to switch to ISP (and use SWD again) or use ISP bootloader via UART or USB (at LPC1343) .

0 Kudos
Reply

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Apr 26 05:10:19 MST 2012

Quote: Riggox
...can explain how this problem can be avoided tho',

:confused:

If you change SWD pin functions, SWD is not working any longer :eek:

What's unclear there :confused:

To reprogram your chip you have to switch to ISP (and use SWD again) or use ISP bootloader via UART or USB (at LPC1343) .
0 Kudos
Reply

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Riggox on Thu Apr 26 04:56:19 MST 2012

Quote: vinod
sir while doing debug & run I am getting the error like
failedon connect Ee(07) bad ack return from status-wire error



Sounds like you are having the same problem I am. From what i have been able to understand this error is because you are programming the SWDIO pin to do something else than its SWDIO duties. To be able to program the processor again, ground the isp pin (Pin 0.1 on LPC1343), reset the processor and then try to flash program a working code.

Im hoping someone else can explain how this problem can be avoided tho', since that is probably why my code isnt working.
0 Kudos
Reply

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vinod on Thu Apr 26 04:50:04 MST 2012
sir while doing debug & run I am getting the error like
failedon connect Ee(07) bad ack return from status-wire error
sir while doing debug & run I am getting the error like
failedon connect Ee(07) bad ack return from status-wire error
0 Kudos
Reply

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Riggox on Thu Apr 26 04:42:35 MST 2012

Quote: daan-ter-horst
Did you mention to enable the clock for the ADC??
If not in the clock register  (SYSAHBCLKCTRL, address 0x4004 8080) you'll have to set bit 13 for the ADC to 1.



The clock is enabled. As I mentioned I got 3 AD pins working, im just having some problems with the remaining 5. When I try to program these I mess up the JTAG pins so that I have to reset the processor by grounding the ISP pin before I reprogram it but the pins does not appear to behave as AD pins instead so Im not sure what i am missing.
0 Kudos
Reply

1,798 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by daan-ter-horst on Wed Apr 25 13:32:49 MST 2012
Did you mention to enable the clock for the ADC??
If not in the clock register  (SYSAHBCLKCTRL, address 0x4004 8080) you'll have to set bit 13 for the ADC to 1.
0 Kudos
Reply