A typical driver output voltage swing is ±8V when loaded with a nominal 5-kilo-ohm RS232 receiver and VCC = +5V. Output swing is guaranteed to meet the EIA/TIA-232E and V.28 specifications.
Pins 25 (RC6/TX) and 26 (RC7/RX) of the microcontroller are connected to pins 11 and 12 of MAX232, respectively. Pins 14 and 13 of MAX232 are connected to pins 2 and 3 of DB9 connector, respectively.
Camera. Several camera modules are available in the market. For 5V operation, we chose microCAM (uCAM) serial JPEG camera from 4D Systems (www.4dsystems.com.au) instead of a USB camera to avoid driver-related issues.
The camera is connected to PIC microcontroller through 9-pin DB9 and RS232 level shifter (MAX232). uCAM is a highly integrated serial camera module, which can be attached to any host system that requires a video camera or a JPEG compressed still camera for embedded imaging applications. uCAM comes in a compact form factor with a built-in lens and a 4-wire connector (for 5V, GND, TX and RX) that provides easy access to both power and serial data. It is compatible with C328 JPEG camera. The uCAM used in this project is shown in Fig. 5. You need to connect 5V supply to this camera.
SPI communication. SPI communication with MRF24WBOMA is illustrated in Fig. 6. PIC microcontroller is chosen as master and Wi-Fi as slave. FOSC/64 clock mode is chosen by proper setting of SSPCON1 register of PIC18F4620.
Software for the PIC microcontroller is written in ‘C’ language and compiled using MPLAB IDE. The program flowchart is shown in Fig. 7.
The project is developed using ‘C’ source files such as WF_Spi, ARP, DHCP, ICMP, IP, main, stackTSK, TCPIP, tick, UART, UDP, WF_Config,WF_Eint, WFConnectionAlgorithm, WFConnectionManager, WFConnectionProfile,WFDataTxRx, WFDriverCom, WFDriverRaw, WFEventHandler, WFInit, WFMac, WFMgmtMsg, WFParamMsg, WFPowerSave, WFScan, WFTxPower and xlcd. (All these files are included in this month’s EFY EVD.)
The project is based on communication between the Wi-Fi module, microcontroller, PC and the camera, which are closely controlled through the software. When LED2 starts blinking it indicates that stacking is running and communication is successfully established with remote client PC. This LED2 monitored through timer interrupt is defined in main.c file.
The Wi-Fi driver routines are nothing but routine files from Microchip TCP-IP stack. The ARP, ICMP, UDP and DHCP protocol implementation are all files from Microchip TCP-IP stack. But the TCP protocols are customised routines written in ‘C’ to incorporate camera routines into the memory size of PIC18F4620. The TCP protocol implementation and camera routines are available in IP.c source file only.
Before writing the code note that 10MHz crystal is used as oscillator source and the clock is set at 40 MHz using HSPLL fuse setting through software.
[stextbox id=”grey”]#pragma config OSC=HSPLL, WDT=OFF,
MCLRE=ON, PBADEN=OFF, LVP=OFF[/stextbox]
Below some important source program routines used in this project are explained.
SPI communication. SPI communication between PIC and Wi-Fi is initialised by suitable initiation code before starting communication. These instructions are available in WF_Spi.c file as given below.
[stextbox id=”grey”]WF_SPICON1 = 0x30; // SSPEN bit is
set, SPI in master mode, (0x30 is for
WF_SPISTATbits.CKE = 0; // Transmit
data on falling edge of clock
WF_SPISTATbits.SMP = 1; // Input
sampled at end? of data output time[/stextbox]
After SPI initialisation, Wi-Fi should be initialised for proper network protocol transmission.
Wi-Fi initialisation and other relevant codes are included in the WFMac.c file. The rouines listed below are implemented only after understanding the coding in Microchip TCP-IP Stack.
MACInit () routine. MACInit () routine given below does necessary initialisation of RAW registers in Wi-Fi module.
[stextbox id=”grey”]void MACInit(void)
MACInit() calls WF_Init() and RawInit() as given below.
The WFHardwareInit() in WF_Init() is important for proper initialisation.
WF_Init routine is given below:
[stextbox id=”grey”]void WF_Init(void)
unsigned char LCD1;
WF_ASSERT(version >= EXPECTED_
RAWInit() routine is given below:
[stextbox id=”grey”]void RawInit(void)
RawWindowReady[RAW_RX_ID] = FALSE;
g_encIndex[ENC_RD_PTR_ID] = BASE_
RawWindowReady[RAW_TX_ID] = FALSE;
g_encPtrRAWId[ENC_WT_PTR_ID] = RAW_
g_encIndex[ENC_WT_PTR_ID] = BASE_
g_wasDiscarded = TRUE;
g_rxBufferSize = 0;
g_txPacketLength = 0;
g_txBufferFlushed = TRUE;
g_rxIndexSetBeyondBuffer = FALSE;
Camera interface. The camera should be first connected to PIC microcontroller via serial port. The baud rate can be 14400, 56000, 57600 or 115200, though better synchronisation was obtained at baud rate 56000 during testing. The camera is assigned with dynamic IP address, which is assigned by DHCP client routine rather than fixed IP address. The advantage is that the IP address gets assigned automatically as per local network and we need not assign it manually. DHCP client routine associated with UDP protocol does the necessary task for auto configuration of the IP address.