Пытаюсь запустить USB.
Очень помогла статья. Всё доступно.
http://www.remexpert.com/ipb/topic1953s0.html
Но у меня PIC24FJ128GB106. Хотя всё очень похоже. В общем, после прошивки МК вижу в винде ukwnown device. D+ c D- не перепутаны, т.к. иначе комп ваще ничего не видит. Конденсаторы 0.1мкФ присутствуют на Vusb и Vbus.
Взял демо-проект.
Конфиг для моего МК+кварц 4Мгц. Т.е. 4Мгц тактовая
PLLDIV_NODIV. Получаем для периферии тоже 4Мгц. Интуиция подсказывает, что грабли именно с синхронизацией...
Код:
_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)
_CONFIG2( 0xF7FF & IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRIPLL & [b]PLLDIV_NODIV[/b] & IOL1WAY_ON)
_CONFIG3( WPCFG_WPCFGDIS & WPDIS_WPDIS) //Disable erase/write protect of all memory regions.
Строки, которые определяют детект питания закоментил. Ноги А2 и B5 не подключены.
Код:
//#define USE_SELF_POWER_SENSE_IO
#define tris_self_power TRISAbits.TRISA2 // Input
#define self_power 1
//#define USE_USB_BUS_SENSE_IO
#define tris_usb_bus_sense U1OTGSTATbits.SESVD //TRISBbits.TRISB5 // Input
#define USB_BUS_SENSE U1OTGSTATbits.SESVD
главная
Код:
int main(void)
#endif
{
InitializeSystem();
#if defined(USB_INTERRUPT)
USBDeviceAttach();
#endif
while(1)
{
#if defined(USB_POLLING)
// Check bus status and service USB interrupts.
USBDeviceTasks(); // Interrupt or polling method. If using polling, must call
// this function periodically. This function will take care
// of processing and responding to SETUP transactions
// (such as during the enumeration process when you first
// plug in). USB hosts require that USB devices should accept
// and process SETUP packets in a timely fashion. Therefore,
// when using polling, this function should be called
// regularly (such as once every 1.8ms or faster** [see
// inline code comments in usb_device.c for explanation when
// "or faster" applies]) In most cases, the USBDeviceTasks()
// function does not take very long to execute (ex: <100
// instruction cycles) before it returns.
#endif
// Application-specific tasks.
// Application related code may be added here, or in the ProcessIO() function.
ProcessIO();
}//end while
}//end main
Проект в приложении.