Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Teensy 3.x / SPI communication with "Wifly Shield" by "Sparkfun"

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    18

    Teensy 3.x / SPI communication with "Wifly Shield" by "Sparkfun"

    Hello there,

    I am trying to connect a WiFly Shield from Sarkfun to a Teensy 3.1 using a Serial Peripheral Interface (SPI). ( https://www.sparkfun.com/products/9954 )
    For this i use the SPI.h lib and the SPI pins on Teensy (10-13 | SS-CLK) connected to the SPI Pins on the WiFly Shield (10-13 | SS-CLK).
    The WiFly uses a Uart-Bridge chip by "NXP" called "SC16IS750". The datasheet as well as all sample sketches for the Arduino Uno show the following specs:


    • 14 MHz crystal
    • SPI_MODE0
    • 4MHz
    • MSBFIRST

    ( https://www.sparkfun.com/datasheets/...40_750_760.pdf )

    Now alway when i try to perform a simple test by writing to and reading from a register (0x07 << 3) I read a 255 in every case.
    When i switch the SPI setting to mode2 I get more or less random Numbers between 128 and 255 by reading from the Register.
    What am i doing wrong ?! I tried nearly everything to find a way to get the SPI working but failed anytime.
    Here is a sketch I use for testing:

    Code:
    
    #include <SPI.h>
    
    
    SPISettings TeensySettings(4000000, MSBFIRST, SPI_MODE0);
    
    
    void setup() {
      
      pinMode(SS, OUTPUT);
      digitalWrite(SS, LOW);
      pinMode(MOSI, OUTPUT);
      digitalWrite(MOSI, LOW);
      pinMode(MISO, INPUT_PULLUP);
      pinMode(SCK, OUTPUT);
      digitalWrite(SCK, LOW);
        
      SPI.begin();
      
      Serial.begin(9600);
      while(!Serial);    // waiting for Serial port to be opened 
    
    
      Serial.println("START SPI TEST \n\n");
      
    }
    
    
    void loop(){
     
      const byte value = 0xAA;     // Value to be written 0xff 0=>255 // 0xee => 246 // 0x10 => 128
      const byte adress = 0x07; // Register adress
      
      writeRegister(adress, value);    // write a value into register with adress "adress"
    
    
      readRegister(adress);   // read value stored in register with adress "adress" 
      
      delay(500);
      
      Serial.println();
      Serial.println("------");
      Serial.println();
    }
    
    
    void writeRegister(uint8_t registerAddress, uint8_t data) {
        
      SPI.beginTransaction(TeensySettings);
      digitalWrite(10,LOW);
      delay(100);
      
      SPI.transfer(registerAddress << 3);
      SPI.transfer(data);
    
    
      delay(100);
      digitalWrite(10,HIGH);
      SPI.endTransaction();
      
    }
    
    
    uint8_t readRegister(uint8_t registerAddress) {
    
    
      uint8_t result;
    
    
      SPI.beginTransaction(TeensySettings);
      digitalWrite(10,LOW);
      delay(100);
      
      SPI.transfer( 0x80 | (registerAddress << 3) );
      result = SPI.transfer(0xFF);
      
      delay(100);
      digitalWrite(10,HIGH);
      SPI.endTransaction();
      
      Serial.print("result: ");Serial.println(result); 
      return result;             // in mode0 the result is 255 in any case !! // in mode2 the result is between 128 and 255  
      
    }
    I also tried using the datatype "byte" instead of "uint8_t" and got the same results in both cases.
    i have no idea what i am doing wrong.
    Would be very pleased for any hints and advices !

    best, vinc

    ps.: here is a thread to a similar problem. But there was no answer which neither solved this nor mine problem.
    https://forum.pjrc.com/threads/26418...oto=nextoldest

  2. #2
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,825
    your input numbers suggest that possibly
    • MISO input not connected to the device
    • SS output is not connected to device's NSS or CS* pin
    • Device has no power/ground

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    18
    Thanks for the immediate replay.
    I double-checked the wiring. I connected all four SPI pins as following:

    (* Teensy --> WiFly )
    * pin 10 (CS) --> pin 10 (SS)
    * pin 11 (DOUT) --> pin 11 (MOSI)
    * pin 12 (DIN) --> pin 12 (MISO)
    * pin 13 (SCK) --> pin 11 (SCLK)

    as well as the power supply:

    * WiFly pin Vin to a 5V source
    * WiFly pin Gnd (right next to Vin) to a ground

    the WiFly Shield blinks in the right pattern, therefore all wiring should be fine as far as i am concerned.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •