THE BOTTOM LINE ... DOES IT WORK?
When I plugged that USB cable into the MCP2200 USB-to-UART converter, I was confronted by the usual “let’s install
a new USB device” jargon. After the driver automatons did
their thing, I was granted access to a VCP (Virtual Comm Port)
and a HID device in the guise of our MCP2200 converter.
The easiest way to put some test code together is to
call out the CCS C compiler. I whipped out the CCS C
compiler 16-bit Project Wizard and quickly built a code
shell for the PIC24FJ128GA006. Here are the
Configuration Fuse settings which the Project Wizard
generated and placed in the nv-ccs-mcp2200-project.h file:
#include<24FJ128GA006.h>
#FUSES NOWDT
#FUSES NOJTAG
#FUSES NOPROTECT
#FUSES NOWRT
#FUSES NODEBUG
#FUSES ICSP2
#FUSES NOWINDIS
#FUSES WPRES128
#FUSES WPOSTS16
#FUSES NOIESO
#FUSES PR_PLL
#FUSES NOCKSFSM
#FUSES NOOSCIO
#FUSES XT
//No Watch Dog Timer
//JTAG disabled
//Code not protected from
//reading
//Program memory not write
//protected
//No Debug mode for ICD
//ICD uses PGC2/PGD2 pins
//Watch Dog Timer in Window
//mode
//Watch Dog Timer PreScalar
//1:128
//Watch Dog Timer PostScalar
//1:32768
//Internal External Switch
//Over mode disabled
//Primary Oscillator with PLL
//Clock Switching is
//disabled, fail Safe clock
//monitor is disabled
//OSC2 is clock output
//Crystal osc <= 4mhz for
//PCM/PCH , 3mhz to 10 mhz
//for PCD
#use delay(clock=32000000)
The CCS C compiler is a wonderful PIC compiler.
I was able to put together this simple converter test
program in less than 15 minutes:
#include “C:\nv-ccs-16bit\nv-ccs-mcp2200-
project.h”
#use rs232(UART2,baud=9600,parity=N,bits=8)
void main()
{
setup_spi( FALSE );
setup_spi2( FALSE );
setup_wdt(WDT_OFF);
setup_timer1(TMR_DISABLED);
do{
printf(“THE MCP2200 IS NOW PART OF
YOUR DESIGN CYCLE!!\r\n”);
delay_ms(500);
}while(1);
}
The converter allows us to code our applications just
as if they were using that SP3232 we replaced in the
design. The proof is in the pudding and the pie crust is
filled with Screenshot 4.
NO PORKY PIG QUITE JUST YET
As Jason Aldean says about all night redneck parties ...
“We ain’t done yet.” I’ve got a Scooby-Doo ending for
you. I’m going to leave you with some C30 source code
that will address the LCD and make the RX LED on your
converter blink with joy:
void initUART(void)
{
U2BRG = 104; //9600 bps
U2MODE = 0x8000; //enable the UART
U2STAbits.UTXEN = 1; //enable TX
}
■ SCREENSHOT 2. To quote Joe Friday, “All we want
are the facts, ma’am.” That’s pretty much all that the
MCP2200 Configuration Utility really wants too.
The little initUART code snippet is all that’s needed to
configure the PIC24FJ128GA006’s UART to drive at 9600 bps.
If you’re wondering why
the MCP2200’s RX LED
would flash instead of
its TX LED, the
MCP2200 is on the
USB side of things. As
far as the MCP2200
is concerned, the
PIC24FJ128GA006 is
transmitting and it is
receiving. The receive/
transmit status
reported by the
MCP2200’s RX and
TX LEDS is not the
PIC24FJ128GA006’s
status but its own status.
■ SCREENSHOT 3. The
only value I changed
for our design was
the baud rate which
defaults to 19200 bps.
62
July 2010