Adc / swdio

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

Adc / swdio

487 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bobi-one on Sun Apr 17 13:31:12 MST 2011
I tried using this pin as ADC but after the upload  several times LPC link wasn't able to connect and program. Is there a way to use ADC function and  still use the debugger, without the need of  grounding FT/GPIO again?
(code hint)
0 Kudos
7 Replies

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Mon Apr 18 04:46:00 MST 2011
As I said, if you are using any of the debug pins for another function, then you will be unable to debug.
0 Kudos

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bobi-one on Mon Apr 18 02:52:02 MST 2011

Quote: Zero
I would suggest to use CON-bit of USB-Device Status (See User manual Chapter 9.11.7)

In Chapter 9.11 a sample shows how to use SIE commands. Unfortunately values for CCEMPTY and CDFULL are wrong there :mad: and therefore I've added a (working) sample here

//returns 1 if USB is powered
int read_usb_power(void)
{
 unsigned int read_val;
 LPC_USB->DevIntClr = 0xC00; // Clear both CCEMPTY & CDFULL
 LPC_USB->CmdCode = 0x00FE0500; // CMD_CODE=0xF5, CMD_PHASE=0x05(Command)
 while (!(LPC_USB->DevIntSt & 0x400)); // Wait for CCEMPTY.
 LPC_USB->DevIntClr = 0x400; // Clear CCEMPTY interrupt bit.
 LPC_USB->CmdCode = 0x00FE0200; // CMD_CODE=0xF5, CMD_PHASE=0x02(Read)
 while (!(LPC_USB->DevIntSt & 0x800)); // Wait for CDFULL.
 LPC_USB->DevIntClr = 0x800; // Clear CDFULL.
 read_val = LPC_USB->CmdData; // Read Frame number LSB byte.
 if(read_val & 0x01)            //CON = connected = power
 {
  return (1);
 }
 else
 {
  return(0);
 }
}


Great code, thanks I'will try to implement it.

@CodeRedSupport,
The thing I'am trying to do is this: my stand alone device have RX/TX connector,  debug connector and USB. My initial idea was to modify the  MSD code so that compiled bin files to be drag and dropped easily via the USB, and the  unused debug connector can be used for peripherals. But since I am having trouble getting  my USB to work, thought that debug connector can be used for both.
0 Kudos

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Sun Apr 17 23:37:16 MST 2011

Quote: bobi-one
Yes, so that means in order to debug I need to switch it back after every ADC read?


This will not work. If you want debug, you cannot re-use any SWD pins (even briefly).
0 Kudos

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Apr 17 18:20:51 MST 2011
I would suggest to use CON-bit of USB-Device Status (See User manual Chapter 9.11.7)

In Chapter 9.11 a sample shows how to use SIE commands. Unfortunately values for CCEMPTY and CDFULL are wrong there :mad: and therefore I've added a (working) sample here

//returns 1 if USB is powered
int read_usb_power(void)
{
 unsigned int read_val;
 LPC_USB->DevIntClr = 0xC00; // Clear both CCEMPTY & CDFULL
 LPC_USB->CmdCode = 0x00FE0500; // CMD_CODE=0xFE, CMD_PHASE=0x05(Command)
 while (!(LPC_USB->DevIntSt & 0x400)); // Wait for CCEMPTY.
 LPC_USB->DevIntClr = 0x400; // Clear CCEMPTY interrupt bit.
 LPC_USB->CmdCode = 0x00FE0200; // CMD_CODE=0xFE, CMD_PHASE=0x02(Read)
 while (!(LPC_USB->DevIntSt & 0x800)); // Wait for CDFULL.
 LPC_USB->DevIntClr = 0x800; // Clear CDFULL.
 read_val = LPC_USB->CmdData; // Read data
 if(read_val & 0x01)            //CON = connected = power
 {
  return (1);
 }
 else
 {
  return(0);
 }
}
0 Kudos

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Apr 17 14:36:24 MST 2011
I think we are still talking about LPC1343 and PIO1_3 (SWDIO/AD4) ?

Of course the simplest solution is to use another pin for ADC. I don't think that switching between functions will work (and this pin is still connected to some kind of input circuit).

USB_VBUS can be switched with IOCON_PIO0_3.
0 Kudos

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bobi-one on Sun Apr 17 14:12:25 MST 2011
Yes, so that means in order to debug I need to switch it back after every ADC read?

btw, @ Zero, DO you know which register is for USB_VBUS to be GPio, because I am trying  to display charging icon when the usb cable is plugged but with no success for now.
0 Kudos

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Apr 17 13:40:03 MST 2011
Did you switch a pin function from SWD to ADC ?

After that your SWD is dead :)
0 Kudos