Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18F4550 CDC communication with C18

Status
Not open for further replies.

Matheus_Carvalho

Newbie level 6
Joined
May 6, 2010
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,356
Hi,
I'm trying to make a code for Pic serial communication with Labview by serial RS-232. I'm using bootloader together, this is the code:
**************************************************************************************************************
#INCLUDES
**************************************************************************************************************/
#include <p18f4550.h>
#include <stdio.h>
#include <delays.h>
#include <timers.h>
#include <adc.h>
#include <GenericTypeDefs.h>
#include <usb_config.h>
#include <usb_descriptors.c>
#include <usb_device.h>
#include <usb.h>
#include <usb_function_cdc.h>
#include <HardwareProfile.h>

/**************************************************************************************************************
#Desvio das funções de reset e interrupções para a posição acima de 0x1000 (MODO BOOTLOADER)
**************************************************************************************************************/
extern void _startup (void);
void ISR_alta_prioridade (void);
#pragma code _RESET_INTERRUPT_VECTOR = 0x1000
void _reset (void)
{
_asm
goto _startup
_endasm
}
#pragma code

void ISR_alta_prioridade (void);
#pragma code _HIGH_INTERRUPT_VECTOR = 0x1008
void _high_ISR (void)
{
_asm
goto ISR_alta_prioridade
_endasm
}
#pragma code
#pragma interrupt ISR_alta_prioridade

void ISR_alta_prioridade (void)
{
USBDeviceTasks();
}
/**************************************************************************************************************
Função Necessária quando o USB_INTERRUPT está ativado
**************************************************************************************************************/
BOOL USER_USB_CALLBACK_EVENT_HANDLER(USB_EVENT event, void *pdata, WORD size)
{
switch(event)
{
/* Este evento é disparado quando o dispositivo recebe uma solicitação */
/* SET_CONFIGURATION enviada pelo host (wValue = 0) */
case EVENT_CONFIGURED:
/* Inicia os endpoints para o uso do dispositivo de acordo com a configuraçao atual (CDC) */
/* Seta o baud rate, bit parity, stop bit e o número de bits de dado */
/* A configuração padrão está indicada a seguir */
/* Baud rate: 19.200 bps */
/* Bit de parada: 1 */
/* Bit de paridade: sem */
/* Número de bits do dado: 8 bits */
/* Para modificar esta configuração, basta abrir o arquivo usb_function_cdc.c e modificar os campos de função CDCInitEP() */
CDCInitEP();
break;

/* Este evento é disparado quando o dispositivo recebe um pacote de SETUP enviado pelo host e devem responder para complementar a solicitação */
case EVENT_EP0_REQUEST:
USBCheckCDCRequest(); /* Verifica e trata a solicitação */
break;

case EVENT_TRANSFER:
Nop();
break;

default:
break;
}
return 1;
}
#define led PORTDbits.RD0
#define botao PORTBbits.RB4
void main()
{
TRISB = 0xFF;
TRISD = 0x00;
USBDeviceInit();
USBDeviceAttach();
PIR2bits.USBIF=0; //Limpa o flag de interrupção do USB
IPR2bits.USBIP=1; //Interrupção USB - Alta Prioridade
RCONbits.IPEN=1; //Habilita interrupção com nivel de prioridade
INTCONbits.GIEH=1; //Habilita todas as interrupções de alta prioridade
INTCONbits.GIEL=1; //Habilita todas as interrupções de baixa prioridade

while (1)
{
if (!botao)
led = 1;
else
led = 0;
if (USBUSARTIsTxTrfReady())
putrsUSBUSART("USP");
CDCTxService();
Delay10KTCYx(50);
USBDeviceTasks();
}
}
When I plug it in my computer (Windows 7 64bits), it appears a serial port (com4), but when I didn't receive any data by serial. I'm trying to send 'USP', but it doesn't work. Could anyone help me with this code?
Thanks a lot.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top