TODOPIC
Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: martin12as en 22 de Noviembre de 2014, 23:11:46
-
hola, buen día, tengo este pic y no logro encontrar ningún ejemplo como para empezar a usar el usb, probé descargando algunos códigos para el 18f2550 y otros similares, pero no logro hacer que funcione. no se si el problema esta en el circuito, en el codigo del pic, o en los drivers de windows.
estoy tratando de hacer la conexión en modo CDC, cuando conecto el pic windows lo detecta como "unknown device" y no puedo instalar ningún driver.
para compilar estoy usando ccs versión 4.104.
cuando quiero hacer alguna simulación en proteus me tira una hermosisima BSOD.
en fin, no logro hacer la comunicación y no se por donde empezar, si alguien tuviese algún código de ejemplo le agradecería bastante, y de ser posible que tenga los drivers para windows 7 64 bits.
desde ya muchas gracias, saludos
-
al final ya pude hacer la primera comunicación, borren el post si quieren
-
Hola Martin12as,
Aqui no se borran post!
Si nadie contesto´tu preguntas no es motivo que borremos el post, lo que si seria buenos es saber como tu resolviste el problema, ya que persona como tu y yo que aprendemos de otros tambien tenga la misma oportunidad.
Tambien seria mas interesante si pusiera el codigo siempre que haga preguntas sobre tus dudas asi tendria respuesta segura, nadie es adivino por solo poner sugeria de un codigo si verlo y estudiarlo.
Un gran Saludos
-
Hola Martin12as,
Aqui no se borran post!
Si nadie contesto´tu preguntas no es motivo que borremos el post, lo que si seria buenos es saber como tu resolviste el problema, ya que persona como tu y yo que aprendemos de otros tambien tenga la misma oportunidad.
Tambien seria mas interesante si pusiera el codigo siempre que haga preguntas sobre tus dudas así tendría respuesta segura, nadie es adivino por solo poner sugería de un código si verlo y estudiarlo.
Un gran Saludos
la solución fue mejorar la versión de ccs, la versión 5 trae muchas cosas interesante, entre ellas la de crear proyectos, sin tener ningún código para ese pic el mismo ccs me brindo un código bastante completo. lo códigos que tenia antes solo eran para el 18f2550 o similares, intente modificarlos para que funcionen para el 18f26j50 pero no hubo caso.
aquí dejo los códigos tal cual los genero el ccs, solo le agregue un "hola mundo" y un delay.
prueba.c
#include <prueba.h>
/* TODO: Use usb_cdc_putc() to transmit data to the USB
virtual COM port. Use usb_cdc_kbhit() and usb_cdc_getc() to
receive data from the USB virtual COM port. usb_enumerated()
can be used to see if connected to a host and ready to
communicate. */
void main()
{
usb_init();
while(TRUE)
{
usb_cdc_putc("hola mundo");
delay_ms(500);
}
prueba.h
#include <18F26J50.h>
#device ADC=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOT1DIG //Secondary Oscillator Source may be select if T1CON.3 = 1
#FUSES NOLPT1OSC //Timer1 configured for higher power operation
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES DSWDTOSC_INT //DSWDT uses INTRC as reference clock
#FUSES RTCOSC_T1 //RTCC uses Secondary Oscillator as reference source
#FUSES NODSBOR //BOR disabled in Deep Sleep
#FUSES NODSWDT //Deep Sleep Watchdog Timer disabled
#FUSES DSWDT2147483648 //DSWDT uses 1:2147483648 Postscale
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#FUSES MSSPMSK7 //MSSP uses 7 bit Masking mode
#FUSES WPFP //Write/Erase Protect Page Start/End Location, set to last page or use WPFP=x to set page
#FUSES WPEND //Flash pages WPFP to Configuration Words page are write/erase protected
#FUSES NOWPCFG //Configuration Words page is not erase/write-protected
#FUSES WPDIS //All Flash memory may be erased or written
#use delay(clock=48MHz,crystal=20MHz,USB_FULL)
#define USB_CONFIG_VID 0x0461
#define USB_CONFIG_PID 0x0033
#define USB_CONFIG_BUS_POWER 500
#define USB_STRINGS_OVERWRITTEN
char USB_STRING_DESC_OFFSET[]={0,4,18};
char const USB_STRING_DESC[]={
//string 0 - language
4, //length of string index
0x03, //descriptor type (STRING)
0x09,0x04, //Microsoft Defined for US-English
//string 1 - manufacturer
14, //length of string index
0x03, //descriptor type (STRING)
'M',0,
'a',0,
'r',0,
't',0,
'i',0,
'n',0,
//string 2 - product
14, //length of string index
0x03, //descriptor type (STRING)
'M',0,
'a',0,
'r',0,
't',0,
'i',0,
'n',0
};
#include <usb_cdc.h>
-
bueno, no voy a abrir otro tema, pero ahora tengo otra duda.
hay alguna forma de usar #int_USB?
porque el código que genera ccs ya utiliza esa interrupción, particularmente en la librería pic18_usb.c. como tendría que hacer para leer algún dato que llegue usando la interrupción? hay que agregar un usb_cdc_getc() o algo parecido junto a este código que ya esta hecho?
#if !defined(USB_ISR_POLLING) && !defined(USB_NO_ISR_PREPROCESSOR)
#int_usb NOCLEAR
#endif
void usb_isr(void)
{
unsigned int8 TRNAttempts;
clear_interrupt(INT_USB);
if (usb_state == USB_STATE_DETACHED) return; //should never happen, though
if (UIR)
{
debug_usb(debug_putc,"\r\n\n[%X] ",UIR);
//activity detected. (only enable after sleep)
if (UIR_ACTV && UIE_ACTV) {usb_isr_activity();}
if (UCON_SUSPND) return;
if (UIR_STALL && UIE_STALL) {usb_isr_stall();} //a stall handshake was sent
if (UIR_UERR && UIE_UERR) {usb_isr_uerr();} //error has been detected
if (UIR_URST && UIE_URST) {usb_isr_rst();} //usb reset has been detected
if (UIR_IDLE && UIE_IDLE) {usb_isr_uidle();} //idle time, we can go to sleep
if (UIR_SOF && UIE_SOF) {usb_isr_sof();}
TRNAttempts = 0;
do
{
if (UIR_TRN && UIE_TRN)
{
USTATCopy = U1STAT;
usb_clear_trn();
usb_isr_tok_dne();
}
else
break;
} while (TRNAttempts++ < 4);
#if defined(USB_CDC_ISR)
//has to be done here, can't be done until TRN is empty.
if (usb_cdc_kbhit())
{
USB_CDC_ISR();
}
#endif
}
}