chipKIT® Development Platform

Inspired by Arduino™

How to change Chip Select Pin for Wifi Module?

Created Wed, 19 Aug 2015 08:41:59 +0000 by Lukas


Lukas

Wed, 19 Aug 2015 08:41:59 +0000

Hello,

i'm using the UNO32 with MPIDE. The chipKit WiFi Shield needs Pin 10 for Chip Select of the Wifi module, the SD card needs Pin 4.

Problem: My PIN 10 is broken and I want to use a other Pin as Chip Select. I am searching now for two days (!) where I can change the definition.

Additional information:

  • I described my problem also here: [url]https://forum.digilentinc.com/topic/877-change-cs-pin-from-wifi-shield/[/url]
  • I use a sd card and the MRF24WG0MA wifi module instead of the wifi shield but it works the same way.
  • I will use the following librarys:
#include <SD.h>
#include <Streaming.h>
#include <WiFiShieldOrPmodWiFi_G.h>
#include <DNETcK.h>
#include <DWIFIcK.h>
#include <DSPI.h>
#include <Wire.h>
#include <CKEasyWifiConfig.h>

Any advice helps, please let me know.

Thank you


majenko

Wed, 19 Aug 2015 09:40:06 +0000

Are you sure your pin 10 is broken? Pin 10 is a rather special pin in that its operation is controlled by jumper J4.

The normal position for JP4 is the RD4 position. The digital pin number for the microcontroller signal RD4 is 10. With JP4 in the RD4 position, digital pin 10 is connected to the pin labeled[sic] 10 on the board. The alternate position for JP4 is the RG9 position. The digital pin number for the microcontroller signal RG9 is 44. With JP4 in the RG9 position, digital pin 44 is connected to the pin labeled[sic] 10 on the board, and digital pin 10 is not connected.

The WiFi library is set up to use pin 44 not pin 10 as can be seen from the file libraries/WiFiShieldOrPmodWiFi_G/Uno32-MRF24WG.x

All the pins are defined in there:

#define WF_CS_TRIS          (TRISGbits.TRISG9)
    #define WF_CS_IO            (LATGbits.LATG9)
    #define WF_SDI_TRIS         (TRISGbits.TRISG7)
    #define WF_SCK_TRIS         (TRISGbits.TRISG6)
    #define WF_SDO_TRIS         (TRISGbits.TRISG8)
    #define WF_RESET_TRIS       (TRISDbits.TRISD6)
    #define WF_RESET_IO         (LATDbits.LATD6)
    #define WF_INT_TRIS         (TRISDbits.TRISD8)  // INT1
    #define WF_INT_IO           (PORTDbits.RD8)
    #define WF_HIBERNATE_TRIS   (TRISDbits.TRISD5)
    #define WF_HIBERNATE_IO     (PORTDbits.RD5)

They are defined as the chip's internal port/pin names, so you will need to cross-reference with the Uno32's user guide to work out which pin numbers on the board equate to which internal pin names.

For instance, in the user guide, pin 10 is listed as PMWR/OC5/IC5/CN13/RD4 which is not used there. Instead the CS pin is G9, which if you look in the pin tables, is pin 44.

So to use the WiFi shield you need to ensure that jumper J4 is in the "SPI Slave" position (it's not actually switching anything to slave mode, it's just routing the signal to the SS2 pin on the chip which the WiFi shield happens to be using as the chip select line. The default pin 10 is routed to a PWM capable output to allow a PWM signal on that pin for Arduino compatibility).

Also note that for the WiFi shield it's not actually using pin 10, but is using the SS pin of the 6-pin SPI header at the end of the board (these pins are linked direct to pins 10-13 anyway).

If you really do want/need to change the pin mapping you will need to look up the chip's internal name for your desired pin in the Uno32 user's manual and change the WF_CS_* macros in the file above accordingly.


Lukas

Wed, 19 Aug 2015 10:53:56 +0000

Thank you for your effort majenko.

Are you sure your pin 10 is broken?

The JP 4 is set to RG 9 as you said. I´m sure it already worked because i was able to receive images from the sd card on my Android App over wifi. I'm confused with the naming of the pins...in my view pin 10 is the pin on the board labeled with the 10. And i know that he can either set to RD4 or RG9 with the jumper J4. And if i compare the code they are using G9 (like you said).

#define WF_CS_TRIS			(TRISGbits.TRISG9)
#define WF_CS_IO			(LATGbits.LATG9)

Could i change it to use pin 9 on the board as slave select like this?

#define WF_CS_TRIS			(TRISDbits.TRISD3)
#define WF_CS_IO			(LATDbits.LATD3)

majenko

Wed, 19 Aug 2015 11:23:14 +0000

Pin 10 is the pin labelled 10 on the board when JP4 is in one position. When it is in the other position pin 10 goes nowhere. Instead the pin labelled as 10 on the board becomes pin 44.

And yes, you can change those entries to D3 to switch it to using pin 9 instead of pin 44. Or you could change them to D4 so it uses pin 10 when JP4 is set to the default pin 10 position, which would mean no re-wiring.