chipKIT USB for Serial with Windows Embedded

The following is a conversation between Jacob Christ and Brian Schmalz with resolutions regarding using chipKIT boards that use USB for serial (Fubarino SD, PONTECH Quick240, PONTECH UAV100, ect) with Windows Embedded. Jacob: FYI, The USB.inf file does not work on XP Embedded.  It’s probably due to missing sys or inf files (since XP Embedded is a subset of XP Pro).  We are working on a fix and will post when we figure it out.   Brian: This is an issue that has come up before with my EiBotBoard I believe. It is due to a lack of the usbser.sys file. Note that when an OEM of XPE generates a build, they can choose to not include many of the files that normal XP ships with  (to save space and make the system easier to manage). So some XPE systems may have usbser.sys and many don’t. Here’s a nice thread asking if it’s OK to re-distribute usbser.sys, the takeaway being that I think it is. Now, which version to use? http://www.winvistatips.com/distributing-usbser-sys-our-customers-t195889.html Note this same problem exists with all versions of “Windows Embedded” (XP, Win7, etc.)   Jacob: The Stk500v2.inf file includes the mdmcpq.inf which is not present in Windows XP Embedded.   We just copied the inf file from XP: c:\windows\inf\mdmcpq.inf to the corresponding location in XP Embedded and re-installed the driver and it worked. What I think the Stk500v2.inf file is picking up from the mdmcpq.inf file are the following two sections:   [LowerFilter_Service_Inst] DisplayName=”USB Modem Driver” ServiceType= 1 StartType  = 3 ErrorControl = 0 ServiceBinary = %12%\usbser.sys   [FakeModemCopyFileSection] usbser.sys,,,0x20   We may just be able to included this directly into the Stk500v2.inf file and this would not be an issue since the usbser.sys IS part of XP Embedded. I’m no inf expert and I’m doing my best to not become one (thank you Brian Schmalz for getting the driver signed for Windows 8).  And I don’t know how important it is for anyone here to have the USB drivers work out of the box in XP Embedded.  For us, its no big deal to copy over the inf file to an XP Embedded installation.   Brian: One thing to note: using mdmcpq.inf is the correct way to reference usbser.sys according to Microchip and Microsoft. I believe this is because usbser.sys may be called different things (?!?!) or located in different spots on various systems, and the mdmcpq.inf file will always point to the ‘right’ spot for usbser.sys as it is generated during install or something? I’m not an INF expert, but the latest MLA from Microchip has a fantastic help file that describes all of this stuff and how to sign drivers and a lot of other really good things to know.   Jacob: Cool, thanks… I guess Stk500v2.inf is right then.  I’m glad you knew this.  
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Serial Communication – I2C EEPROM using MPLAB X IDE

Overview:

In this project you will learn to use a basic functionality of chipKIT board, which is to use serial communication I2C bus to read and write values from EEPROM memory. I2C bus is a master slave bus, which communicates data from the processor on chipKIT board to other peripherals. More description on I2C communication can be found on the Wikipedia website and on EEPROM can be found here. The configuration is done though MPLAB X IDE.

Hardware Used:

To do the serial communication project, you require the following hardware devices.
  • chipKIT Uno 32
  • chipKIT Basic IO shield
  • PICkit® 3 In-Circuit Debugger/Programmer
  • USB cable
  • 6 pin header to connect chipKIT board and PICkit® 3

Reference:

The reference guide for each board, schematics and other resources are available on their individual homepages:

Procedure:

  1. Connect the hardware devices. The PICkit® 3 should be connected to the chipKIT Uno32 board through a suitable header and use the USB cable to connect the PICkit® 3 to your PC.
  2. Make sure that the jumper settings for JP4 on chipKIT Uno32 board is configured as SPI Slave Select input mode. You can find the jumper settings in chipKIT Uno32 board reference manual from the Digilent website. Also, ensure that the jumpers JP6/JP8 are configured to be used as I2C communication lines.
  3. Place the IO shield on top of the Uno32 board with a bit of a firm press.
  4. Once the hardware setup is made and the device drivers are updated for PICkit® 3 on your computer, launch MPLAB X (Start>All Programs>Microchip>MPLAB X IDE>MPLAB X IDE vx.xx on Window® Machines).
  5. Create a new project through File>New Project. In the pop up new project window, select Standalone Project  under Projects  and click Next. Under Family scroll and select 32-bit MCUs (PIC32). Note the processor number from the chipKIT board’s reference manual and enter it under the Device  option. Click Next.
  6. Select PICkit3 in the Hardware Tools, click Next. Select XC32 (v1.20) under Compiler Toolchains, click Next. Give a project name to create the project.
  7. In the Project tab on the left side of the MPLAB X IDE, right click on Source Files > New > C Main File.. and give a file name for main source code. Once the dot c file opens, select all the codes in the file and replace it with the codes below.
    #include 
    
    #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
    #pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1
    #define SYS_FREQ (80000000L)
    
    #define GetSystemClock()           (SYS_FREQ)
    #define GetPeripheralClock()       (SYS_FREQ/1)
    #define GetInstructionClock()      (SYS_FREQ)
    #define I2C_CLOCK_FREQ             5000
    
    // EEPROM Constants
    #define EEPROM_I2C_BUS              I2C1
    #define EEPROM_ADDRESS              0x50        // 0b1010000 Serial EEPROM address
    
    /*******************************************************************************
      Function:
        BOOL StartTransfer( BOOL restart )
    
      Summary:
        Starts (or restarts) a transfer to/from the EEPROM.
    
      Description:
        This routine starts (or restarts) a transfer to/from the EEPROM, waiting (in
        a blocking loop) until the start (or re-start) condition has completed.
    
      Precondition:
        The I2C module must have been initialized.
    
      Parameters:
        restart - If FALSE, send a "Start" condition
                - If TRUE, send a "Restart" condition
    
      Returns:
        TRUE    - If successful
        FALSE   - If a collision occured during Start signaling
    
      Example:
        
        StartTransfer(FALSE);
        
    
      Remarks:
        This is a blocking routine that waits for the bus to be idle and the Start
        (or Restart) signal to complete.
      *****************************************************************************/
    
    BOOL StartTransfer( BOOL restart )
    {
        I2C_STATUS  status;
    
        // Send the Start (or Restart) signal
        if(restart)
        {
            I2CRepeatStart(EEPROM_I2C_BUS);
        }
        else
        {
            // Wait for the bus to be idle, then start the transfer
            while( !I2CBusIsIdle(EEPROM_I2C_BUS) );
    
            if(I2CStart(EEPROM_I2C_BUS) != I2C_SUCCESS)
            {
                DBPRINTF("Error: Bus collision during transfer Start\n");
                return FALSE;
            }
        }
    
        // Wait for the signal to complete
        do
        {
            status = I2CGetStatus(EEPROM_I2C_BUS);
    
        } while ( !(status & I2C_START) );
    
        return TRUE;
    }
    
    /*******************************************************************************
      Function:
        BOOL TransmitOneByte( UINT8 data )
    
      Summary:
        This transmits one byte to the EEPROM.
    
      Description:
        This transmits one byte to the EEPROM, and reports errors for any bus
        collisions.
    
      Precondition:
        The transfer must have been previously started.
    
      Parameters:
        data    - Data byte to transmit
    
      Returns:
        TRUE    - Data was sent successfully
        FALSE   - A bus collision occured
    
      Example:
        
        TransmitOneByte(0xAA);
        
    
      Remarks:
        This is a blocking routine that waits for the transmission to complete.
      *****************************************************************************/
    
    BOOL TransmitOneByte( UINT8 data )
    {
        // Wait for the transmitter to be ready
        while(!I2CTransmitterIsReady(EEPROM_I2C_BUS));
    
        // Transmit the byte
        if(I2CSendByte(EEPROM_I2C_BUS, data) == I2C_MASTER_BUS_COLLISION)
        {
            DBPRINTF("Error: I2C Master Bus Collision\n");
            return FALSE;
        }
    
        // Wait for the transmission to finish
        while(!I2CTransmissionHasCompleted(EEPROM_I2C_BUS));
    
        return TRUE;
    }
    
    /*******************************************************************************
      Function:
        void StopTransfer( void )
    
      Summary:
        Stops a transfer to/from the EEPROM.
    
      Description:
        This routine Stops a transfer to/from the EEPROM, waiting (in a
        blocking loop) until the Stop condition has completed.
    
      Precondition:
        The I2C module must have been initialized & a transfer started.
    
      Parameters:
        None.
    
      Returns:
        None.
    
      Example:
        
        StopTransfer();
        
    
      Remarks:
        This is a blocking routine that waits for the Stop signal to complete.
      *****************************************************************************/
    
    void StopTransfer( void )
    {
        I2C_STATUS  status;
    
        // Send the Stop signal
        I2CStop(EEPROM_I2C_BUS);
    
        // Wait for the signal to complete
        do
        {
            status = I2CGetStatus(EEPROM_I2C_BUS);
    
        } while ( !(status & I2C_STOP) );
    }
    
    // ****************************************************************************
    // ****************************************************************************
    // Application Main Entry Point
    // ****************************************************************************
    // ****************************************************************************
    
    int main(void)
    {
        UINT8               i2cData[10];
        I2C_7_BIT_ADDRESS   SlaveAddress;
        int                 Index;
        int                 DataSz;
        UINT32              actualClock;
        BOOL                Acknowledged;
        BOOL                Success = TRUE;
        UINT8               i2cbyte;
    
        // Initialize debug messages (when supported)
        DBINIT();
    
        // Set the I2C baudrate
        actualClock = I2CSetFrequency(EEPROM_I2C_BUS, GetPeripheralClock(), I2C_CLOCK_FREQ);
        if ( abs(actualClock-I2C_CLOCK_FREQ) > I2C_CLOCK_FREQ/10 )
        {
            DBPRINTF("Error: I2C1 clock frequency (%u) error exceeds 10%%.\n", (unsigned)actualClock);
        }
    
        // Enable the I2C bus
        I2CEnable(EEPROM_I2C_BUS, TRUE);
    
        //
        // Send the data to EEPROM to program one location
        //
    
        // Initialize the data buffer
        I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, EEPROM_ADDRESS, I2C_WRITE);
        i2cData[0] = SlaveAddress.byte;
        i2cData[1] = 0x05;              // EEPROM location to program (high address byte)
        i2cData[2] = 0x40;              // EEPROM location to program (low address byte)
        i2cData[3] = 0xAA;              // Data to write
        DataSz = 4;
    
        // Start the transfer to write data to the EEPROM
        if( !StartTransfer(FALSE) )
        {
            while(1);
        }
    
        // Transmit all data
        Index = 0;
        while( Success && (Index < DataSz) )
        {
            // Transmit a byte
            if (TransmitOneByte(i2cData[Index]))
            {
                // Advance to the next byte
                Index++;
    
                // Verify that the byte was acknowledged
                if(!I2CByteWasAcknowledged(EEPROM_I2C_BUS))
                {
                    DBPRINTF("Error: Sent byte was not acknowledged\n");
                    Success = FALSE;
                }
            }
            else
            {
                Success = FALSE;
            }
        }
    
        // End the transfer (hang here if an error occured)
        StopTransfer();
        if(!Success)
        {
            while(1);
        }
    
        // Wait for EEPROM to complete write process, by polling the ack status.
        Acknowledged = FALSE;
        do
        {
            // Start the transfer to address the EEPROM
            if( !StartTransfer(FALSE) )
            {
                while(1);
            }
    
            // Transmit just the EEPROM's address
            if (TransmitOneByte(SlaveAddress.byte))
            {
                // Check to see if the byte was acknowledged
                Acknowledged = I2CByteWasAcknowledged(EEPROM_I2C_BUS);
            }
            else
            {
                Success = FALSE;
            }
    
            // End the transfer (stop here if an error occured)
            StopTransfer();
            if(!Success)
            {
                while(1);
            }
    
        } while (Acknowledged != TRUE);
    
        //
        // Read the data back from the EEPROM.
        //
    
        // Initialize the data buffer
        I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, EEPROM_ADDRESS, I2C_WRITE);
        i2cData[0] = SlaveAddress.byte;
        i2cData[1] = 0x05;              // EEPROM location to read (high address byte)
        i2cData[2] = 0x40;              // EEPROM location to read (low address byte)
        DataSz = 3;
    
        // Start the transfer to read the EEPROM.
        if( !StartTransfer(FALSE) )
        {
            while(1);
        }
    
        // Address the EEPROM.
        Index = 0;
        while( Success & (Index < DataSz) )
        {
            // Transmit a byte
            if (TransmitOneByte(i2cData[Index]))
            {
                // Advance to the next byte
                Index++;
            }
            else
            {
                Success = FALSE;
            }
    
            // Verify that the byte was acknowledged
            if(!I2CByteWasAcknowledged(EEPROM_I2C_BUS))
            {
                DBPRINTF("Error: Sent byte was not acknowledged\n");
                Success = FALSE;
            }
        }
    
        // Restart and send the EEPROM's internal address to switch to a read transfer
        if(Success)
        {
            // Send a Repeated Started condition
            if( !StartTransfer(TRUE) )
            {
                while(1);
            }
    
            // Transmit the address with the READ bit set
            I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, EEPROM_ADDRESS, I2C_READ);
            if (TransmitOneByte(SlaveAddress.byte))
            {
                // Verify that the byte was acknowledged
                if(!I2CByteWasAcknowledged(EEPROM_I2C_BUS))
                {
                    DBPRINTF("Error: Sent byte was not acknowledged\n");
                    Success = FALSE;
                }
            }
            else
            {
                Success = FALSE;
            }
        }
    
        // Read the data from the desired address
        if(Success)
        {
            if(I2CReceiverEnable(EEPROM_I2C_BUS, TRUE) == I2C_RECEIVE_OVERFLOW)
            {
                DBPRINTF("Error: I2C Receive Overflow\n");
                Success = FALSE;
            }
            else
            {
                while(!I2CReceivedDataIsAvailable(EEPROM_I2C_BUS));
                i2cbyte = I2CGetByte(EEPROM_I2C_BUS);
            }
    
        }
    
        // End the transfer (stop here if an error occured)
        StopTransfer();
        if(!Success)
        {
            while(1);
        }
    
        // Validate the data read
        if( i2cbyte != 0xAA )
        {
            DBPRINTF("Error: Verify failed\n");
        }
        else
        {
            DBPRINTF("Success\n");
        }
    
        // Example complete
        while(1);
    }
  8. In the above program, the EEPROM is being written with a value AA and read from the memory to verify if it written correctly. To verify the result access the watch window from Window > Debugging > Watches or you can use the shortcut key Alt+Shift+2. In the watch window panel that opens on the MPLAB X IDE, enter the new watch as i2cbyte, in the blank <Enter new watch> area.
  9. In the program editor window, put a breakpoint by clicking on the line number  on the while statement near the end of the program.
  10. Click on Debug Project icon shown below,                                                 analogread mplab3
  11. Once the program halts its execution at the line with the breakpoint, click on Watches window below the code area. You can observe the output value being reflected in the i2cbyte variable as shown below.serialcomm1
This verifies the operation of writing into and reading from EEPROM memory through the I2C serial communication. To get more information on working of I2C serial communication visit the wikipedia website by clicking here. In our application EEPROM on the IOshield is the slave device and PIC controller on chipKIT Uno32 board acts as the master device. 
VN:F [1.9.22_1171]
Rating: 3.6/10 (8 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Analog Read using MPLAB X IDE

Overview:

In this project you will learn to use a basic functionality of chipKIT board in MPLAB X IDE, which is to read an analog value and output the corresponding digital reading for it. A potentiometer is a  three-terminal resistor with a sliding contact that forms an adjustable voltage divider. Using a potentiometer measuring instrument, you could measure the electric potential. In this example we use the potentiometer in the chipKIT Basic IO shield. Find the same project using MPIDE here.

Hardware Used:

To do the analog read project, you require the following hardware devices.

  • chipKIT Uno 32
  • chipKIT Basic IO shield
  • PICkit® 3 In-Circuit Debugger/Programmer
  • USB cable
  • 6 pin header to connect chipKIT board and PICkit® 3

Reference:

The reference guide for each board, schematics and other resources are available on their individual homepages:

Procedure:

  1. Connect the hardware devices. The PICkit® 3 should be connected to the chipKIT Uno32 board through a suitable header and use the USB cable to connect the PICkit® 3 to your PC.
  2. Place the IO shield on top of the Uno32 board with a bit of a firm press. A0-potentiometer of the IO shield will be used as peripheral for Uno32 board, in this excercise.
  3. Once the hardware setup is made and the device drivers are updated for PICkit® 3 on your computer, launch MPLAB X (Start>All Programs>Microchip>MPLAB X IDE>MPLAB X IDE vx.xx on Window® Machines ).
  4. Create a new project through File>New Project. In the pop up new project window, select Standalone Project  under Projects  and click Next. Under Family scroll and select 32-bit MCUs (PIC32). Note the processor number from the chipKIT board’s reference manual and enter it under the Device  option. Click Next.
  5. Select PICkit3 in the Hardware Tools, click Next. Select XC32 (v1.20) under Compiler Toolchains, click Next. Give a project name to create the project.
  6. In the Project tab on the left side of the MPLAB X IDE, right click on Source Files > New > C Main File.. and give a file name for main source code. Once the dot c file opens, select all the codes in the file and replace it with the codes below.
    #include <plib.h>
    #include <xc.h>
    
    #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
    #pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1
    #define SYS_FREQ (80000000L)
    
    unsigned int channel4;	// conversion result as read from result buffer
    unsigned int offset;	// buffer offset to point to the base of the idle buffer
    
    int main(void)
    {
        // Configure the device for maximum performance but do not change the PBDIV
        // Given the options, this function will change the flash wait states and
        // enable prefetch cache but will not change the PBDIV. The PBDIV value
        // is already set via the pragma FPBDIV option above..
        SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    
        // configure and enable the ADC
        CloseADC10();    // ensure the ADC is off before setting the configuration
    
        // define setup parameters for OpenADC10
                    // Turn module on | ouput in integer | trigger mode auto | enable autosample
        #define PARAM1  ADC_MODULE_ON | ADC_FORMAT_INTG | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON
    
        // define setup parameters for OpenADC10
                    // ADC ref external    | disable offset test    | disable scan mode | perform 2 samples | use dual buffers | use alternate mode
        #define PARAM2  ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_OFF | ADC_SAMPLES_PER_INT_9 | ADC_ALT_BUF_OFF | ADC_ALT_INPUT_OFF
    
        // define setup parameters for OpenADC10
        //                   use ADC internal clock | set sample time
        #define PARAM3  ADC_CONV_CLK_INTERNAL_RC | ADC_SAMPLE_TIME_15
    
        // define setup parameters for OpenADC10
        // do not assign channels to scan
        #define PARAM4    SKIP_SCAN_ALL
    
        // define setup parameters for OpenADC10
                    // set AN2 as analog inputs
        #define PARAM5    ENABLE_AN2_ANA
    
            // use ground as neg ref for A | use AN2 for input A
    
         // configure to sample AN2
        SetChanADC10( ADC_CH0_NEG_SAMPLEA_NVREF | ADC_CH0_POS_SAMPLEA_AN2); // configure to sample AN2
        OpenADC10( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5 ); // configure ADC using parameter define above
    
        EnableADC10(); // Enable the ADC
    
      while ( ! mAD1GetIntFlag() ) { } // wait for the first conversion to complete so there will be vaild data in ADC result registers
    
        // the result of the conversion is available in channel4.
        while (1)
        {
    
            channel4 = ReadADC10(0);          // read the result of channel 4 conversion from the idle buffer
    
        }
    
        return 0;
    }
  7. To read the potentiometer value, access the watch window from Window > Debugging > Watches or you can use the shortcut key Alt+Shift+2. In the watch window panel that opens on the MPLAB X IDE, enter the new watch as channel4, in the blank <Enter new watch> area as shown below in the figure.                                                                                                                                                          analogread mplab1
  8. In the program editor window, put a breakpoint by clicking on the line number after the code line
     channel4 = ReadADC10(0);          // read the result of channel 4 conversion from the idle buffer
    That is on the line with the closing braces of the while loop. This should create a red box in the number line as shown in the figure below,                                                     analogread mplab2
  9. Click on Debug Project icon shown below,                                                 analogread mplab3
  10. Once the program halts its execution at the line with the breakpoint, click on Watches output window, right click on the expand button under Value column and select Display value column as > Decimal. The value that appear in this column for channel4 variable corresponds to the potentiometer reading which is read in the range of 0 to 1023. A value 0 corresponds to 0 volts and a value 1023 corresponds to 3.3 volts.
  11. Now, click on Continue button from the top pane and observe the value of channel4 to change and reflect the potentiometer reading as described before.
  12. If you would like to change the potentiometer knob and see a different value, then, change the potentiometer knob and click on the Reset button on the top pane. This will initialize the variables back to zero. Clicking on the Play button on the top pane, will get your changed  potentiometer value on the Watches window. Below is a screenshot showing the potentiometer value for 3.3 volts being read in the Watch window.  analogread mplab4
VN:F [1.9.22_1171]
Rating: 5.7/10 (6 votes cast)
VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)

Wifi shield configuration from SD card

CKEasyWifiConfig

A library for the Digilent chipKIT development boards. It lets you configure the wifi settings of the digilent wifi shield from a configuration file on the SD card. Library main page : http://kurdymalloy.github.io/CKEasyWifiConfig

Why

Problem

In most example sketches that you will find, the wifi settings are always hard-coded in the sketch; this is kind of problematic if every time that you want to connect to a different network you have to change code and rebuild the sketch and reload it on the board.

Solution

This library will let you configure the wifi shield with settings read from a configuration file saved on a SD card loaded on the shield. So to change the settings, you just have to change the configuration file on the SD card. This is a lot better especially when your device is deployed in a project.

Installation

The project files are available at : https://github.com/KurdyMalloy/CKEasyWifiConfig This is arduino’s standard way of installing a custom library:
  • Copy the folder named “CKEasyWifiConfig” from the repository to the sub-folder  /libraries/ under your sketchbook directory.
  • Use the “NetConf.cfg” file from the root of the repository as a template for your configuration file that will go on the SD card.

Dependencies

The library is dependent on four other libraries: You need to include these in your main sketch before you include this one. This library was tested with mpide 0023.

Configuration File

The configuration file included in the project is already self-documented. Any line beginning with the character ‘#’ or ‘/’ will be ignored and considered a comment. The parameter names in the file are case sensitive, they need to be uppercase. Here are the possible values for each parameters: SECURITY:
  • OPEN
  • WPA2_WITH_KEY
  • WPA2_WITH_PASS_PHRASE
  • WPA_WITH_KEY
  • WPA_WITH_PASS_PHRASE
  • WPA_AUTO_WITH_KEY
  • WPA_AUTO_WITH_PASS_PHRASE
  • WEP_40
  • WEP_104
IP:
  • A valid ipv4 address in the form xxx.xxx.xxx.xxx
  • DHCP or left blank to use dhcp
SSID:
  • The ssid of your network; it is usually case sensitive.
KEY:
  • Your key in hexadecimal if you can provide it.
KEYCHAR:
  • Your key if you want to provide it in text.
KEYINDEX:
  • The index of your key if it is indexed
Important: the KEY and KEYCHAR parameters are mutually exclusive; if you provide both, the last one read in the file will be the one that is used. Example of a configuration file to connect with dhcp and an hexadecimal wpa2 key :
SECURITY:WPA_AUTO_WITH_KEY
SSID:MYNETWORK
IP:DHCP
KEY:5312826e170e6d0ef8691670cabc5c9c3072cf8c003e4ee541a499d060746cfa
Example of a configuration file to connect with a static address and a wpa2 passphrase key :
SECURITY:WPA_AUTO_WITH_PASS_PHRASE
SSID:MYNETWORK
IP:192.168.1.252
KEYCHAR:hermionegranger

Usage

There are two example projects provided with the library; one to use a configuration file on the card and one where you can pass the security infos in the code. To use the library, make sure that you include all the dependency libraries before you include CKEasyWifiConfig. If you want the library to output some debugging information in the serial port, make sure to define “CKEASYWIFICONFIG_SERIAL_DEBUG” before you include the library. You will also have to make sure that you setup the serial port before you call the “Setup()” method of the library. It is also very important to initialize the SD card before you call the “Setup()” method of the CKEasyWifiConfig class since it will use it. Example:
#include <SD.h>
#include <Streaming.h>
#include <WiFiShieldOrPmodWiFi.h>  // This is for the MRF24WBxx on a pmodWiFi or WiFiShield
//#include <WiFiShieldOrPmodWiFi_G.h> // This is for the MRF24WGxx on a pmodWiFi or WiFiShield
#include <DNETcK.h>
#include <DWIFIcK.h>

// Remove the next line to stop the serial debugging of the library
#define CKEASYWIFICONFIG_SERIAL_DEBUG  
#include <CKEasyWifiConfig.h>

//To enable serial debugging in the main sketch
#define USE_SERIAL_DEBUG  

// Name of the config file on the SD card
char networkConfigFile[] = "NetConf.cfg";

CKEasyWifiConfig networkConfig(networkConfigFile);

void setup() {
  // put your setup code here, to run once:

  #ifdef USE_SERIAL_DEBUG
    Serial.begin(9600);
    Serial << "Initializing SD card..." << endl;
  #endif

  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  if (!SD.begin(4)) {
    #ifdef USE_SERIAL_DEBUG
      Serial << "SD Card initialization failed!" << endl;
    #endif
    return;
  }
  else
  {
    #ifdef USE_SERIAL_DEBUG
      Serial << "SD Card initialization success." << endl;
      if (SD.exists(networkConfigFile))
        Serial << "Network Config File --> " << networkConfigFile << " is present on the SD card." << endl;
      else
        Serial << "Network Config File --> " << networkConfigFile << " is NOT present on the SD card." << endl;
    #endif // USE_SERIAL_DEBUG
  }

  // Call the initialization
  networkConfig.Setup();
}

void loop() {
  // put your main code here, to run repeatedly: 

  // every pass through loop(), keep the IP stack alive
  DNETcK::periodicTasks(); 
}

Limitations

The SD card library only supports file names in the 8.3 format. So your configuration file and any sub-folder that you want to put it in, need to have a name in this format. Due to some architecture differences; this library is not really suitable for the arduino platform. The arduino has a very different memory model especially to store static stuff into the flash memory (PROGMEM). This code was not designed with that in mind and take fully advantage of the fact that the PIC architecture is much easier to code for. Also since there is a lot more space available on the chipKIT platform, more time was spent developing for the usability of the library than on trying to reduce its size. The dependency to the Digilent networking libraries is also a factor to the non-portability of the library.  
VN:F [1.9.22_1171]
Rating: 6.5/10 (2 votes cast)
VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)

Install MPLAB X IDE and XC32 compiler

MPLAB X is a open source cross platform that is used to develop applications based on PIC micro controllers. MPLAB X IDE is similar to MPIDE except that compiling the code before running it is possible in MPLAB X. All the library functions and more supported by MPIDE are supported by MPLAB X IDE. In this section, you will be guided through step-by-step instructions on installing MPLAB X IDE and it’s necessary XC compilers. Followed by, you can do a tutorial on Quick start blinky LED project to test and get acquainted with MPLAB X IDE which you have installed in your computer.

Installing MPLAB X IDE

  1. Access the page www.microchip.com/mplab in a new tab. In the MPLAB X IDE page, click on the red button under MPLAB X Links that’s says “MPLAB® X Free Download”. In the “Downloads” list that appears, download MPLAB® X IDE vx.xx for the OS you have.                                                                                                                                                                      
  2. Once the download is complete, extract MPLABX-vx.xx-windows-installer.exe and run the application as shown below,                                                                                                         
  3. In the setup window that pops up, select next.
  4. Accept the license agreement and click next.
  5. Save the software in a folder, preferably in the default directory and click next.
  6. At this point, setup is complete and you are ready to install the IDE. Click next in the Setup window for to begin the installation process.Once the installation is completed, you will be prompted to install a compiler. To program in C, you will need a compiler. To program for the chipKIT platform, you will need the MPLAB XC32 compiler for 32-bit devices. Leave the checkbox checked and click finish.                                                                     mplab9

Installing MPLAB X C32 compiler

  1. In the browser page that automatically opens up, scroll to the Downloads section on the left pane and download the XC32 compiler for your OS.                                                                                  mplab10
  2. Once the download is complete, extract xc32-vx.xx-windows-installer.exe and run the application as shown below,                                                                                                                                      mplab11
  3. In the setup window that pops up, select next. Accept the license agreement, choose the installer, choose installation type and keep proceeding on by clicking next.
  4. In the License activation window, leave the Activation Key blank and click next, to download the compiler in free mode. Click yes in the next window to confirm that you wish to install the FREE version of the compiler.
  5. Save the software in a folder, preferably in the default directory and click next to begin installation. Click next in the following window without any changes. Start the setup by clicking next in the ready to install window and the installation will start.Once the installation is complete, click finish. Double click on MPLAB X IDE vx.xx icon in the start menu or desktop to launch the program. Your desktop would look like this.                                        mplab23
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Alternative (to MPIDE) Build Tools

Here are some build tools which you can consider using as an alternative to MPIDE:

Using chipKIT compatible Arduino-based Makefile

Here is the link on the topic – Blog Posting by Christopher Peplin To download the chipKIT.mk Makefile from github, click on – git repository

Using avrdude-gui tool to install hex file onto chipKIT board without MPIDE

1. Downloaded avrdude-gui and unzipped. 2. Replaced avrdude.exe that came with it with the avrdude.exe that is in MPIDE: mpide-0022-windows-20110822\hardware\tools\avr\bin\avrdude.exe Also needed to grap the libusb0.dll from the same location and place it into the avrdude-gui dir. 3. Replaced the avrdude.conf file with the avrdude.conf that is in MPIDE: mpide-0022-windows-20110822\hardware\tools\avr\etc\avrdude.conf 4. The GUI program only recognizes the first 3 COM ports so I had to remap my Uno32 to COM2. 5. Dropped my hex file into the avrdude-gui dir. 6. Run the program and selected the following parameters (for Uno32): Target Device: 32MX320F128H Programmer: stk500v2 Flash: my_hex_file.hex 7. Clicked the Flash Program button.
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

avrdude and the chipKIT Platform

The bootloader on the chipKIT is based on the same bootloader that I developed for the mega2560. It uses stk500v2 protocol.

Avrdude can be used from the command line with the chipKIT boards or any other board that has the bootloader installed The command would be something like this >avrude -c stk500v2 -p pic32 -P /dev/tty.usbmodem1234 -b 115200 -U flash:w:filename.hex Or, under Windows(If you’ve copied avrdude.exe and avrdude.conf into the MPLABX bin folder): “C:\Program Files\Microchip\MPLABX\mplab_ide\bin\avrdude.exe” -C”C:\Program Files\Microchip\MPLABX\mplab_ide\bin\avrdude.conf” -v -p32MX795F512L -cstk500v2 -P COM40 -b 115200 -U flash:w:pic32_template_1.production.hex

Getting an hex file for chipKIT

When using mpide, default is to remove all the intermediate files between the mpide source of your project (.mpe file) and code uploaded on the chipKIT. But all the files generated by mpide (including the hex file) can be kept by changing mpide preference file. From Linux:
  1. close any running mpide
  2. edit ~/.mpide/preferences.txt
  3. look for preproc.save_build_files attribute
  4. Set it to true: preproc.save_build_files=true
  5. save the preference file
Now, all temporary files from build command will be kept. To locate the right directory with your build, from mpide, press the “shift” key while starting the build/verify command. You will have details about the build process (commands, outputs, path …) in mpide output console. Example:
/opt/mpide-0023-linux32-20111221/hardware/pic32/compiler/pic32-tools/bin/pic32-g++  -O2  -c  -mno-smart-io  -w  -fno-exceptions  -ffunction-sections  -fdata-sections  -G1024  -g  -mdebugger  -Wcast-align  -mprocessor=32MX320F128H  -DF_CPU=80000000L  -DARDUINO=23  -D_BOARD_UNO_  -Danything_you_want  -Danything=1   -I/home/fred/Arduino/Serial2   -I/opt/mpide-0023-linux32-20111221/hardware/pic32/cores/pic32   -I/opt/mpide-0023-linux32-20111221/hardware/pic32/variants/Uno32    /tmp/build6773645236763377018.tmp/Serial2.cpp  -o  /tmp/build6773645236763377018.tmp/Serial2.cpp.o

...

/opt/mpide-0023-linux32-20111221/hardware/pic32/compiler/pic32-tools/bin/pic32-ar  rcs  /tmp/build6773645236763377018.tmp/core.a  /tmp/build6773645236763377018.tmp/main.cpp.o
/opt/mpide-0023-linux32-20111221/hardware/pic32/compiler/pic32-tools/bin/pic32-g++  -Os  -Wl,--gc-sections  -mdebugger  -mprocessor=32MX320F128H  -o  /tmp/build6773645236763377018.tmp/Serial2.cpp.elf  /tmp/build6773645236763377018.tmp/Serial2.cpp.o    /tmp/build6773645236763377018.tmp/core.a  -L/tmp/build6773645236763377018.tmp  -lm  -T  /opt/mpide-0023-linux32-20111221/hardware/pic32/cores/pic32/chipKIT-UNO32-application-32MX320F128L.ld
/opt/mpide-0023-linux32-20111221/hardware/pic32/compiler/pic32-tools/bin/pic32-objcopy  -O  ihex  -j  .eeprom  --set-section-flags=.eeprom=alloc,load  --no-change-warnings  --change-section-lma  .eeprom=0  /tmp/build6773645236763377018.tmp/Serial2.cpp.elf  /tmp/build6773645236763377018.tmp/Serial2.cpp.eep
/opt/mpide-0023-linux32-20111221/hardware/pic32/compiler/pic32-tools/bin/pic32-bin2hex  -a  /tmp/build6773645236763377018.tmp/Serial2.cpp.elf
Binary sketch size: 10748 bytes (of a 126976 byte maximum)
  • temporary directory is /tmp/build6773645236763377018.tmp/
  • Hex file will be named /tmp/build6773645236763377018.tmp/Serial2.cpp.hex
WARNING: the temporary directory will be removed when mpide will be closed. You have to backup the hex file before closing mpide. To go back to initial configuration (files removed after each build), just set the preproc.save_build_files attribute to false
preproc.save_build_files=false

Using AVRDUDE from Linux console

copy avrdude.conf file from mpide to ~/.avrduderc, example:
cp /opt/mpide-0023-linux32-20111221/hardware/tools/avrdude.conf ~/.avrdude.rc
Use ever avrdude from mpide or from your own Linux distro… Here are details about avrdude from Ubuntu Precise Penguin:
dpkg-query -l avrdude
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                             Version                          Description
+++-================================-================================-================================================================================
ii  avrdude                          5.11.1-1                         software for programming Atmel AVR microcontrollers
Check if the avrdude configuration file from mpide is used, and which PIC32 devices are available:
fred@kat:~/MPLABXProjects/Blink$ avrdude -p ?

Valid parts are:
  pic32-440 = 32MX440F512H    [/home/fred/.avrduderc:16438]
  pic32-460 = 32MX460F512L    [/home/fred/.avrduderc:16251]
  pic32-360 = 32MX320F128H    [/home/fred/.avrduderc:16054]
  pic32-360 = 32MX320F064H    [/home/fred/.avrduderc:15863]
  pic32-360 = 32MX360F512L    [/home/fred/.avrduderc:15672]
  pic32 = 32MX795F512L    [/home/fred/.avrduderc:15483]

...
We can see that pic32-360 has to be used for Uno32 (32MX320F128H) Example, with:
  • avrdude from Ubuntu distro (Precise Penguin – avrdude 5.11.1)
  • Uno32 located on /dev/ttyUSB0
  • hex file build by using mpide
fred@kat:~/MPLABXProjects$ avrdude -P /dev/ttyUSB0 -p pic32-360  -b 115200 -c stk500v2 -v -v -U flash:w:Haribo.cpp.hex

avrdude: Version 5.11.1, compiled on Oct 30 2011 at 10:37:28
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/fred/.avrduderc"

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : stk500v2
         Overriding Baud Rate          : 115200
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
Oops… Upload error ? I have to press the Uno32 reset button, then code is uploaded:
         AVR Part                      : 32MX320F128H
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    131072  256    512  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500V2
         Description     : Atmel STK500 Version 2.x firmware
         Programmer Model: AVRISP
         Hardware Version: 15
         Firmware Version Master : 2.10
         Vtarget         : 0.0 V
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x504943
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: current erase-rewrite cycle count is -1145324613 (if being tracked)
avrdude: erasing chip
avrdude: reading input file "Haribo.cpp.hex"
avrdude: input file Haribo.cpp.hex auto detected as Intel Hex
avrdude: writing flash (32664 bytes):

Writing | ################################################## | 100% 9.15s

avrdude: 32664 bytes of flash written
avrdude: verifying flash memory against Haribo.cpp.hex:
avrdude: load data flash data from input file Haribo.cpp.hex:
avrdude: input file Haribo.cpp.hex auto detected as Intel Hex
avrdude: input file Haribo.cpp.hex contains 32664 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 3.29s

avrdude: verifying ...
avrdude: 32664 bytes of flash verified

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Using AVRDUDE from within MPLAB X

To use avrdude to upload a hex file you just built in MPLAB X, there are a couple steps you need to follow:
  1. (optional) From the MPIDE install folder, copy (as an example) C:\Program Files\mpide-0023-windows-20120122-test\hardware\tools\avr\bin\avrdude.exe to someplace you want to put avrdude and its configuration file, like C:\Program Files\Microchip\MPLABX\mplab_ide\bin\avrdude.exe
  2. (optional) From the MPIDE install folder, copy (as an example) C:\Program Files\mpide-0023-windows-20120122-test\hardware\tools\avr\etc\avrdude.conf to someplace you want to put avrdude and its configuration file, like C:\Program Files\Microchip\MPLABX\mplab_ide\bin\avrdude.conf
  3. From within MPLABX, open the properties for your current project. Select the Building/Loading screen, then enter the following for “Execute this line after build” (and check the box as well):
    • “C:\Program Files\Microchip\MPLABX\mplab_ide\bin\avrdude.exe” -C”C:\Program Files\Microchip\MPLABX\mplab_ide\bin\avrdude.conf” -v -p32MX795F512L -cstk500v2 -P COM40 -b 115200 -U flash:w:${ImagePath}
    • (Note that you will need to substitute the proper COM port number of your board, as well as the actual location of avrdude.exe and avrdude.conf into this command line. Also, if you’re not using an MX795 you’ll have to update that as well.)
  4. Make sure you have copied the proper linker script into your project. For example, if you’re using a chipKIT MAX32 board, just copy the chipKIT-MAX32-application-32MX795F512L.ld file from C:\Program Files\mpide-0023-windows-20120122-test\hardware\pic32\cores\pic32 into your MPLABX project folder, and then add that file to the Linker Files folder in the Project Properties.
If all of the paths are set up properly, you should get an automatic download every time you rebuild your project in MPLABX. Many times, I need to reset my chipKIT board in order to get the download to work, even though I don’t need to do this when using MPIDE. I’m not sure why this is – if anyone can suggest a workaround, that would really help.
VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)