Use Printf for USB

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

Use Printf for USB

206 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Tue Sep 21 16:10:35 MST 2010
Hi all,

In order to use printf to format and output data via USB, I've changed __write function to buffer chars and it's working. I'm not very familiar with printf and so I'm not sure if there is a more elegant solution ?
volatile unsigned int string_counter;
volatile char string_buffer[64];               //max USB buffer size LPC1343
 
int __write (int iFileHandle, uint8_t *pcBuffer, uint8_t iLength)
{
  unsigned char len_count;      //len counter
  unsigned char print=0;       //print flag
  RFID_REL_ON;         //Scope output
  for(len_count=0;len_count< iLength;len_count++)//read loop
 {
  string_buffer[string_counter]= *pcBuffer;  //fill buffer
  if(*pcBuffer == 0x0D)print=1;     //check return
  pcBuffer++;         //inc buffer pointer
  string_counter++;        //inc counter
 }
 if((string_counter>63) || print)    //if max buffer or return
 {
  USB_WriteEP (CDC_DEP_IN, (unsigned char *)&string_buffer[0],string_counter);
  string_counter=0;        //reset counter
 }
 RFID_REL_OFF;         //Scope output
 return iLength;
}

Thanks in advance,
Kayoda
0 Kudos
0 Replies