This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Simplest CC2531 USB example.

Other Parts Discussed in Thread: CC2531

We have built a small board using a CC2531 and tested it with the swrc088c.zip examples -- they appear to be working.  However we would like to build a custom application with a different tool chain.  So far, timers, the radio, and SPI communication are working fine.  However the USB has not worked, despite the successful use of USB in the swrc088c examples -- so we know the hardware is good.  We made a very simple test, see below.  In this test, the USB reset interrupt occurs and is serviced -- we can see an Led for that event.  But after that, we don't get any EP0 interrupts as we had expected.  Is there some other step needed to complete the USB setup?  

Thank you,

Ted

(example that follows uses SDCC dialect, but we know that is OK;  also, P0_0 and P1_1 are the two LEDs) 

typedef unsigned char uint8_t;
__sbit __at (0x80) P0_0;
__sfr __at (0x87) PCON;
__sfr __at (0x8B) P2IFG;
__sbit __at (0x91) P1_1;
__sfr __at (0x95) ST0;
__sfr __at (0x96) ST1;
__sfr __at (0x97) ST2;
__sfr __at (0x9A) IEN2;
__sfr __at (0x9E) CLKCONSTA;
__sbit __at (0xAF) EA;
__sfr __at (0xAC) P2IEN;
__sfr __at (0xBE) SLEEPCMD;
__sfr __at (0xC6) CLKCONCMD;
__sbit __at (0xE8) P2IF;
__sfr __at (0xF4) P1SEL;
__sfr __at (0xFD) P0DIR;
__sfr __at (0xFE) P1DIR;
volatile __xdata __at (0x6202) uint8_t USBIIF;
volatile __xdata __at (0x6204) uint8_t USBOIF;
volatile __xdata __at (0x6206) uint8_t USBCIF;
volatile __xdata __at (0x6207) uint8_t USBIIE;
volatile __xdata __at (0x6209) uint8_t USBOIE;
volatile __xdata __at (0x620B) uint8_t USBCIE;
volatile __xdata __at (0x620F) uint8_t USBCTRL;
volatile __xdata __at (0x6211) uint8_t USBCS0;
int main(void) {
EA = 0; // interrupts off
SLEEPCMD = 0x04; // ensure PM0 (active)
P1DIR = P1DIR | 0x02; // led1
P0DIR = P0DIR | 0x01; // led0
P1_1 = 0; // turn off led1
P0_0 = 1; // turn off led0 (it's inverted)
CLKCONCMD &= ~0x40; // select XOSC as system clock
while (CLKCONSTA & 0x40);
// now CLKCONSTA.OSC = 0 => 32MHz XOSC
USBCTRL |= 0x01; // turn on USB
USBCTRL |= 0x02; // turn on 48MHz PLL
while (!(USBCTRL & 0x80)); // trap until 48MHz PLL locked
P2IFG = 0; // turn off any P2 pin interrupt flags
P2IF = 0; // turn off main P2 interrupt flag
IEN2 |= 0x02; // but P2 enabled, for USB
EA = 1; // main interrupt enabled
while (1) if (USBCS0) P1_1 = 1; // spin
}

void __vector_6(void) __interrupt (6) {
uint8_t locCIF, locIIF, locOIF;
locCIF = USBCIF;
locIIF = USBIIF;
locOIF = USBOIF;
if (locCIF & 0x04) {
USBCIE = 0x06;
USBIIE = 0x01;
USBOIE = 0x00;
P0_0 = P0_0 ? 0 : 1;
}
locCIF &= ~0x04;
if (((locCIF | locIIF) | locOIF | P2IFG) != 0) {
P1_1 = 1;
}
if (P2IFG & 0x20) { P2IFG = ~0x20; }
P2IF = 0;
}