Hi Tsuneo,
Sorry about bothering you again. It seems like I need to know much more about USB configurations than I know know.
I took the Check_USBBus_Status(); out of the if condition in the main.c for loop and commented the USB_Suspend() in Check_USBBus_Status(void) as you previously said to do. I also defined another input port to check the VBUS and called it USB_PWR.
so in Usb_Drv.c I have:
void Check_USBBus_Status(void)
{
#ifdef SELF_POWER
if(USB_PWR == USB_BUS_ATTACHED) /* Is JM60 attached on USB bus? */
{
#endif
if(CTL_USBEN == 0) /* JM60 module off ? */
{
EPCTL0 = 0x0D;
INTSTAT = 0xBF;
CTL = 0x00;
INTENB = 0x00; /* disable USB interrupt*/
CTL_USBEN = 0x01; /* enable module */
USBCTL0 = UCFG_VAL; /* attach JM60 to USB bus*/
Usb_Device_State = ATTACHED_STATE;
}
#ifdef SELF_POEWER
}
else
{
if(CTL_USBEN == 1) /* JM60 USB on ?*/
{
CTL = 0x00; /* disable module */
INTENB = 0x00; /* mask USB interrupt*/
Usb_Device_State = POWERED_STATE;
}
}
#endif
if(Usb_Device_State == ATTACHED_STATE)
{
INTSTAT = 0xBF; /*clear USB interrupts*/
INTENB = 0xBF;
}
if(Usb_Device_State == USB_ENTER_SUSPEND)
{
// USB_Suspend();
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
and in main.c for loop I have:
for(;
{
/* USB Manager, please keep it in main Loop */
Check_USBBus_Status();
if (ButtonPressed)
{
// Data sent to UI in EP2
// MASEG_proc(SWITCHES_PORT);
EP2_Buffer[0] = MASEG_proc(SWITCHES_PORT);
EndPoint_IN(EP2,8); //send data
ButtonPressed = CLEAR; //clear ButtonPressed flag
KBI_ENABLE(); //enable KBI
}
}
And as I mentioned before I am using "ButtonPressed" event to check my keyboard pressing events, so I cannot use if condition like:
if (Usb_Device_State == CONFIGURED_STATE) // run this contents just when USB connection is established
{
if (ButtonPressed)
{
// If there is any change in the switches, send the status
EP2_Buffer[0] = SWITCHES_PORT; //assign value of the push buttons to EP2 buffer
EndPoint_IN(EP2,8); //send data
ButtonPressed = 0; //clear ButtonPressed flag
KBI_ENABLE(); //enable KBI
}
}
And the keyboard is not working in Self_Powered mode(using external Voltage), if I don't do the following in the main.c:
if(USB_PWR) {
USBATTACHED = TRUE;
}
//
if(USBATTACHED)
{
Check_USBBus_Status();
}
//
If you need more information please let me know and thank you so much for your time and attention.
Regards,
Red