Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CDC USB Interrupt
29-09-2012, 03:31 AM,
#1
CDC USB Interrupt
Hi. I'm new to pinguino (MX220 board).
I want to use the cdc/usb/serial port emulation while doing other tasks.
As a first intent I want a mix of the blink and the GetKey examples.
Bellow is my code (at least my last intent). The problem is that the board echoes the characters only sometimes and I lost a lot of characters.
There is some way to use the usb with interrupts and something like a circular buffer so there are no lost characters?
From where the libcdc220.a is comming ?

Best Regards,
Andres.


int s = 0;
u8 buffer[2]; // always get a full packet

void setup()
{
pinMode(13, OUTPUT);
pinMode(9, OUTPUT);
CDC.printf("Press a Key ...\r\n");
}


void loop()
{
USB_Service();
if ( CDCgets( &buffer ) > 0 ) {
if ( mUSBUSARTIsTxTrfReady() ) {
CDC.printf("You pressed key [%c], code ASCII is \"%d\"\r\n", buffer[0], buffer[0]);
}
}
if ( s == 0 ) {
digitalWrite(13, HIGH); // set the green LED on
digitalWrite(9, LOW); // set the red LED off
} else if ( s == 0x8FFF ) {
digitalWrite(9, HIGH); // set the red LED on
digitalWrite(13, LOW); // set the green LED off
}

if ( s == 0xFFFF ) {
s = 0;
} else {
s++;
}
}
Reply
03-10-2012, 03:13 AM,
#2
RE: CDC USB Interrupt
Here is my best solution till now.
Where can I find the source code of: USB_Service_CDC_GetString and USB_Service.

Somebody has any idea of way the call to USB_Service is so strange...



void loop();
int sx = 0;

void setup()
{
pinMode(13, OUTPUT);
pinMode(9, OUTPUT);
while( 1 ) {
loop();
// Strange: to low == lost chars, to high slow response.
if ( sx == 0x3FF ) {
USB_Service();
sx = 0;
}
sx++;
}
// To avoid linking problem.
CDC.printf("");
}




void MinePrintf(const u8 *fmt, ...)
{
u8 MineBuffer[65];
u8 MineLength;
va_list args;
va_start(args, fmt);
MineLength = psprintf2(MineBuffer, fmt, args);
va_end(args);
putUSBUSART( MineBuffer,MineLength );
CDCTxService();
}

int s = 0;
u8 cc = 0;
u8 b[65];
u8 c=0;
int i;

void loop()
{

c = USB_Service_CDC_GetString( b );
if ( c > 0 ) {
if ( cc < 80 ) {
MinePrintf("%c", b[0] );
} else {
MinePrintf("%c\r\n", b[0] );
cc = 0;
}
cc++;
c = 0;
}


if ( s == 0 ) {
digitalWrite(13, HIGH); // set the green LED on
digitalWrite(9, LOW); // set the red LED off
} else if ( s == 0x8FFF ) {
digitalWrite(9, HIGH); // set the red LED on
digitalWrite(13, LOW); // set the green LED off
}

if ( s == 0xFFFF ) {
s = 0;
} else {
s++;
}
}
Reply
03-10-2012, 08:09 AM, (This post was last modified: 03-10-2012, 08:15 AM by pingotg.)
#3
RE: CDC USB Interrupt
A quick search (*) finds at least some of them used in __cdc.c

hmm, so will now look further...

Looks like they're in libcdc.a so maybe its source is online?
At least file usb_function_cdc.c or the like looks to be wanted.

(*) easy on Linux using tools such as find and grep

John
Reply
03-10-2012, 02:05 PM,
#4
RE: CDC USB Interrupt
Thank for the response. I already did that.
Most of the code for the usb part came from the microchip libraries. I didn't managed to understand/build the examples.
Reading the microchip code I tried to call directly some functions, but the best solution was calling: USB_Service_CDC_GetString and USB_Service. Those aren't from the microchip library (at least the release I downloaded).


(03-10-2012, 08:09 AM)pingotg Wrote: A quick search (*) finds at least some of them used in __cdc.c

hmm, so will now look further...

Looks like they're in libcdc.a so maybe its source is online?
At least file usb_function_cdc.c or the like looks to be wanted.

(*) easy on Linux using tools such as find and grep

John
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)