Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC 18F4550 USB Issue Pls Help!

Status
Not open for further replies.

Wilksey

Member
Hi,

I have created an application in CCS C for the 18f4550 chip, which works very well in simulated mode (Proteus 7) and on my own demo board.

I have been porting it across to C18, the simulated version works fine in Proteus, however, the "real" version doesn't seem happy, it will create a COM port and when I connect to Hyperterminal, none of the commands are accepted, I have debugged the application and it appears for some reason to constantly be recieving '6' into the input buffer of the USB.

I reflashed with my CCS C app and it works absolutely perfectly, reflash with C18 app, and it goes wrong.

I am sure the code is correct, as it is a port from the CCS C and it works in the SIM.

There is a define which sets the OSC speed between 4 and 48MHz, and I checked this was correct, the board is using a 20MHz crystal.

Is there any reason why the USB would be constantly receving '6' on the buffer? The Chip is working fine, I use the Microchip FS USB demo code as a base, not checked the code yet, but it also worked in simulator setting freq to 4MHz, the crystal is fine as the CCS C app works, RS232 works fine through the MAX 232 CPE chip.


Any ideas anyone? It's really bugging me now.

Kind Regards

Wilksey
 
Mike,

Thanks for replying, I have checked the CCS C config fuses against the C18 fuses, and they appear the same, I will post them below, I haven't modified them from the MCHIP FS USB demo.


/**FUSES AND CONFIGURATION******************************************/
#pragma config PLLDIV = 5 // 20 MHz crystal
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2 // Clock source from 96MHz PLL/2
#pragma config FOSC = HSPLL_HS
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOR = ON
#pragma config BORV = 3
#pragma config VREGEN = ON //USB Voltage Regulator
#pragma config WDT = OFF
#pragma config WDTPS = 32768
#pragma config MCLRE = ON
#pragma config LPT1OSC = OFF
#pragma config PBADEN = OFF
#pragma config STVREN = ON
#pragma config LVP = OFF
#pragma config XINST = OFF // Extended Instruction Set
#pragma config CP0 = OFF
#pragma config CP1 = OFF
#pragma config CPB = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
#pragma config WRTB = OFF // Boot Block Write Protection
#pragma config WRTC = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
#pragma config EBTRB = OFF

Thanks

Wilksey
 
C18 isn't 100% ANSI compliant. An example of this from the manual:
Given the following example:
unsigned char a, b;
unsigned int i;
a = b = 0x80;
i = a + b;
ANSI/ISO expects i to be equal to 0x100, but MPLAB C18 sets i equal to 0x00.
By default, MPLAB C18 will perform arithmetic at the size of the largest operand, even
if both operands are smaller than an int. To enable the ISO mandated behavior that
all arithmetic be performed at int precision or greater, use the -Oi command-line
option. To enable in the MPLAB IDE, select Project>Build options…>Project, click the
MPLAB C18 tab and select Enable integer promotions.
 
Hmm, I would have thought it would be compliant as it was Microchip's original base code and project files.

However, I will try and do as you suggest as it is currently not enabled, so it may be as simple.

Thanks for the reply.

Wilksey
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top