[MSP430]/MSP430F5x2011. 8. 11. 12:03

[MSP430F5510 EVM] USB HID 테스트

[MSP430F5510 EVM] USB HID 테스트



MSP430F5510 을 이용하여 HID테스트를 했다. HID를 이용하면 USB디바이스 드라이버 제작할 필요없이 고속의 USB통신을 할수 있다. 간단히 HID인식해서 데이터 송수신 하는 예제를 작성해 보았다.
저렴하고 소형의 MCU임에도 불구하고 USB데이터 처리는 빠르고 쉽게 처리되었고 상용 제품에 적용하기에 좋은것 같다.

HID테스트용 PC프로그램 제작



MSP430F5510 HID USB데이터 송수신 테스트 소스코드

VOID main(VOID)
{
    //시스템 초기화
 SystemInit();
   
 //init USB
 USB_init();

 Led1Init();
 Led1Off();
 
 Led2Init();
 Led2Off(); 
   
    // Enable various USB event handling routines
    USB_setEnabledEvents(kUSB_VbusOnEvent+kUSB_VbusOffEvent+kUSB_receiveCompletedEvent
                          +kUSB_dataReceivedEvent+kUSB_UsbSuspendEvent+kUSB_UsbResumeEvent+kUSB_UsbResetEvent);
   
    // See if we're already attached physically to USB, and if so, connect to it
    // Normally applications don't invoke the event handlers, but this is an exception. 
    if (USB_connectionInfo() & kUSB_vbusPresent)
      USB_handleVbusOnEvent();

    while(1)
    {
        BYTE i;
        // Check the USB state and directly main loop accordingly
        switch(USB_connectionState())
        {
           case ST_USB_DISCONNECTED:
    // Enter LPM3 w/ interrupts enabled
                 __bis_SR_register(LPM3_bits + GIE);              
                _NOP();                                             
                break;
               
           case ST_USB_CONNECTED_NO_ENUM:
                break;
               
           case ST_ENUM_ACTIVE:
    // Enter LPM0 (can't do LPM3 when active)
                __bis_SR_register(LPM0_bits + GIE);              
                _NOP();

     //------------------------------------------------------------------------------
    //USB데이터 송수신
                // Exit LPM on USB receive and perform a receive operation
                if(bHIDDataReceived_event)                             
                {
      // Holds the new addition to the string                 
      char pieceOfString[MAX_STR_LENGTH] = "";          
                 
                  // Add bytes in USB buffer to theCommand
      // Get the next piece of the string
                  hidReceiveDataInBuffer((BYTE*)pieceOfString,MAX_STR_LENGTH,0);                
                  strcat(wholeString,pieceOfString);    
                  // Add it to the whole
                  hidSendDataInBackground((BYTE*)pieceOfString,strlen(pieceOfString),0,0);     
                 
      
     if(wholeString[0] == CMD_LED2_ON)
     {
       Led2On();
     }
     else if(wholeString[0] == CMD_LED2_OFF)
     {
       Led2Off();
     }     
       else if(wholeString[0] == CMD_LED1_ON)
                    {
                      Led1On();
                    }
     else if(wholeString[0] == CMD_LED1_OFF)
                    {
      Led1Off();
                    }
                    else if(wholeString[0] == CMD_READ_DATA)
                    {                     
                      //USB데이터 전송
       hidSendDataInBackground((BYTE*)outBuffer,63),0,0);
                    }
                  bHIDDataReceived_event = FALSE;
                }
                break;
   //----------------------------------------------------------------------------------
   
           case ST_ENUM_SUSPENDED:
                __bis_SR_register(LPM3_bits + GIE);          // Enter LPM3 w/ interrupts
                break;
               
           case ST_ENUM_IN_PROGRESS:
                break;
               
           case ST_NOENUM_SUSPENDED:
                __bis_SR_register(LPM3_bits + GIE);               
                break;               
               
           case ST_ERROR:
                _NOP();
                break;
               
           default:;
        }
   
    }  // while(1)
} //main()



MSP430F5510 HID테스트 동영상

Posted by nexp

댓글을 달아 주세요