Wifi with SD Card...

Post any hardware related questions about your WiShield 1.0 here.

Re: Wifi with SD Card...

Postby ArdWifi » Sat Oct 23, 2010 8:47 am

2560 has just arrived... got the WiShield working... just need to get the SDCard going now... :)
ArdWifi
 
Posts: 44
Joined: Wed Feb 03, 2010 8:39 am

Re: Wifi with SD Card...

Postby bdodds » Sun Oct 24, 2010 5:45 pm

Wow, fast shipping on the 2560!! I'm still waiting for mine, though I didn't buy the same day as you did.

So what did you have to do to get the WiShield working?

If you have the latest Fat16 library, I belive it automaticaly knows what the normal pin for SS would be on the Mega 2560.
So to make it work on the pin of your choice you just need to replace "SPI_SS_PIN" in line 77 with the pin # you want to use on the Mage and it should work. :)

Code snippet from my library as it works on my 328.
Code: Select all
uint8_t const SD_CHIP_SELECT_PIN = 6;   //Original setting was "uint8_t const SD_CHIP_SELECT_PIN = SPI_SS_PIN"


I can't wait to find out if this is going to work or if I'll have to go with some other platform...
bdodds
 
Posts: 20
Joined: Tue Oct 19, 2010 6:01 pm
Location: Orange County CA

Re: Wifi with SD Card...

Postby ArdWifi » Mon Oct 25, 2010 1:18 am

Just had to make some changes to spi.h

Will post them here when I have the sd card slot working... I've bought a new one so that I dnt have to butcher the old one. Should be here by wednesday.

Code compiles and installs so should be alright!
ArdWifi
 
Posts: 44
Joined: Wed Feb 03, 2010 8:39 am

Re: Wifi with SD Card...

Postby ArdWifi » Tue Oct 26, 2010 6:30 am

Just got the SDCard working... was as easy as changing the SS_Pin as you said!

just got to get them both working together...

here is the spi.h for the wishield for the mega



Code: Select all
/******************************************************************************

  Filename:      spi.h
  Description:   SPI bus configuration for the WiShield 1.0

******************************************************************************

  TCP/IP stack and driver for the WiShield 1.0 wireless devices

  Copyright(c) 2009 Async Labs Inc. All rights reserved.

  This program is free software; you can redistribute it and/or modify it
  under the terms of version 2 of the GNU General Public License as
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 59
  Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  Contact Information:
  <[email protected]>

   Author               Date        Comment
  ---------------------------------------------------------------
   AsyncLabs         05/01/2009   Initial version
   AsyncLabs         05/29/2009   Adding support for new library

*****************************************************************************/

#ifndef SPI_H_
#define SPI_H_

// Uncomment one line below to
// specify which Arduino pin
// to use as WiShield interrupt
#define USE_DIG0_INTR      // use digital pin 0
//#define USE_DIG8_INTR      // use digital pin 8
#define USE_MEGA
#define USE_PIN_48_ForLED

#ifdef USE_DIG0_INTR
#define ZG2100_ISR_DISABLE()   (EIMSK &= ~(0x01))
#define ZG2100_ISR_ENABLE()      (EIMSK |= 0x01)
#define ZG2100_ISR_GET(X)      (X = EIMSK)
#define ZG2100_ISR_SET(X)      (EIMSK = X)
#endif

#ifdef USE_DIG8_INTR
#define ZG2100_ISR_DISABLE()   (PCMSK0 &= ~(0x01))
#define ZG2100_ISR_ENABLE()      (PCMSK0 |= 0x01)
#define ZG2100_ISR_GET(X)      (X = PCMSK0)
#define ZG2100_ISR_SET(X)      (PCMSK0 = X)
#endif

//AVR Mega168 SPI HAL
#define BIT0                     0x01
#define BIT1                     0x02
#define BIT2                     0x04
#define BIT3                     0x08
#define BIT4                     0x10
#define BIT5                     0x20
#define BIT6                     0x40
#define BIT7                     0x80

#ifdef USE_DIG8_INTR
#define ZG2100_INTR                  BIT0
#endif

#ifdef USE_MEGA // Set up SPI For Arduino Mega 1280 / 2560

#define SPI0_SS_BIT                  BIT0
#define SPI0_SS_DDR                  DDRB
#define SPI0_SS_PORT               PORTB

#define SPI0_SCLK_BIT               BIT1
#define SPI0_SCLK_DDR               DDRB
#define SPI0_SCLK_PORT               PORTB

#define   SPI0_MOSI_BIT               BIT2
#define SPI0_MOSI_DDR               DDRB
#define SPI0_MOSI_PORT               PORTB

#define   SPI0_MISO_BIT               BIT3
#define SPI0_MISO_DDR               DDRB
#define SPI0_MISO_PORT               PORTB

#else // Set up SPI For Arduino Mega 328

#define SPI0_SS_BIT                  BIT2
#define SPI0_SS_DDR                  DDRB
#define SPI0_SS_PORT               PORTB

#define SPI0_SCLK_BIT               BIT5
#define SPI0_SCLK_DDR               DDRB
#define SPI0_SCLK_PORT               PORTB

#define   SPI0_MOSI_BIT               BIT3
#define SPI0_MOSI_DDR               DDRB
#define SPI0_MOSI_PORT               PORTB

#define   SPI0_MISO_BIT               BIT4
#define SPI0_MISO_DDR               DDRB
#define SPI0_MISO_PORT               PORTB

#endif

#define SPI0_WaitForReceive()
#define SPI0_RxData()                (SPDR)

#define SPI0_TxData(Data)            (SPDR = Data)
#define SPI0_WaitForSend()            while( (SPSR & 0x80)==0x00 )

#define SPI0_SendByte(Data)            SPI0_TxData(Data);SPI0_WaitForSend()
#define SPI0_RecvBute()               SPI0_RxData()

// PB4(MISO), PB3(MOSI), PB5(SCK), PB2(/SS)         // CS=1, waiting for SPI start // SPI mode 0, 8MHz
#ifdef USE_MEGA // Set up SPI For Arduino Mega 1280 / 2560

#ifdef USE_DIG8_INTR
#define SPI0_Init()         PRR0 = 0x00;\
                     DDRB  |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT|LEDConn_BIT;\
                     DDRB  &= ~(SPI0_MISO_BIT|ZG2100_INTR);\
                     PORTB = SPI0_SS_BIT;\
                     SPCR  = 0x50;\
                     SPSR  = 0x01

#else
#define SPI0_Init()         PRR0 = 0x00;\
                     DDRB  |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT|LEDConn_BIT;\
                     DDRB  &= ~SPI0_MISO_BIT;\
                     PORTB = SPI0_SS_BIT;\
                     SPCR  = 0x50;\
                     SPSR  = 0x01

#endif


#else // Set up SPI For Arduino Mega 328

#ifdef USE_DIG8_INTR
#define SPI0_Init()                  DDRB  |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT|LEDConn_BIT;\
                              DDRB  &= ~(SPI0_MISO_BIT|ZG2100_INTR);\
                              PORTB = SPI0_SS_BIT;\
                              SPCR  = 0x50;\
                              SPSR  = 0x01
#else
#define SPI0_Init()                  DDRB  |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT|LEDConn_BIT;\
                              DDRB  &= ~SPI0_MISO_BIT;\
                              PORTB = SPI0_SS_BIT;\
                              SPCR  = 0x50;\
                              SPSR  = 0x01
#endif
#endif
//ZG2100 SPI HAL
#define ZG2100_SpiInit               SPI0_Init
#define ZG2100_SpiSendData            SPI0_SendByte
#define ZG2100_SpiRecvData            SPI0_RxData

#ifdef USE_MEGA // Set up SPI For Arduino Mega 1280 / 2560
#define ZG2100_CS_BIT                BIT0
#else // Set up SPI For Arduino Mega 328
#define ZG2100_CS_BIT               BIT2
#endif
#define ZG2100_CS_DDR               DDRB
#define ZG2100_CS_PORT               PORTB

#define ZG2100_CSInit()               (ZG2100_CS_DDR |= ZG2100_CS_BIT)
#define ZG2100_CSon()               (ZG2100_CS_PORT |= ZG2100_CS_BIT)
#define ZG2100_CSoff()               (ZG2100_CS_PORT &= ~ZG2100_CS_BIT)

#ifdef USE_MEGA // Set up SPI For Arduino Mega 1280 / 2560
#ifdef USE_PIN_48_ForLED
#define LEDConn_BIT                 BIT1
#define LEDConn_DDR                  DDRL
#define LEDConn_PORT               PORTL
#else
#define LEDConn_BIT                 BIT6
#define LEDConn_DDR                  DDRH
#define LEDConn_PORT               PORTH
#endif
#else
#define LEDConn_BIT               BIT1
#define LEDConn_DDR               DDRB
#define LEDConn_PORT            PORTB
#endif

#define LED0_BIT               BIT0
#define LED0_DDR               DDRC
#define LED0_PORT               PORTC

#define LED1_BIT               BIT1
#define LED1_DDR               DDRC
#define LED1_PORT               PORTC

#define LED2_BIT               BIT2
#define LED2_DDR               DDRC
#define LED2_PORT               PORTC

#define LED3_BIT               BIT3
#define LED3_DDR               DDRC
#define LED3_PORT               PORTC

#define LED_Init()    (DDRC |= LED0_BIT | LED1_BIT | LED2_BIT | LED3_BIT)

#define LEDConn_on()   (LEDConn_PORT |= LEDConn_BIT)
#define LED0_on()      (LED0_PORT |= LED0_BIT)
#define LED1_on()      (LED0_PORT |= LED1_BIT)
#define LED2_on()      (LED0_PORT |= LED2_BIT)
#define LED3_on()      (LED0_PORT |= LED3_BIT)

#define LEDConn_off()   (LEDConn_PORT &= ~LEDConn_BIT)
#define LED0_off()      (LED0_PORT &= ~LED0_BIT)
#define LED1_off()      (LED0_PORT &= ~LED1_BIT)
#define LED2_off()      (LED0_PORT &= ~LED2_BIT)
#define LED3_off()      (LED0_PORT &= ~LED3_BIT)

#define LED0_toggle()   ((LED0_PORT & LED0_BIT)?(LED0_PORT &= ~LED0_BIT):(LED0_PORT |= LED0_BIT))
#define LED1_toggle()   ((LED0_PORT & LED1_BIT)?(LED0_PORT &= ~LED1_BIT):(LED0_PORT |= LED1_BIT))
#define LED3_toggle()   ((LED0_PORT & LED3_BIT)?(LED0_PORT &= ~LED3_BIT):(LED0_PORT |= LED3_BIT))

#endif /* SPI_H_ */


Wiring is set up as

MEGA pin 50 (MISO) to Wishield Shield pin 12.
MEGA pin 51 (MOSI) to Wishield Shield pin 11.
MEGA pin 52 (SCK) to Wishield Shield pin 13.
MEGA pin 53 (SS) to Wishield Shield pin 10.

bend out pins 10 - 13 on the SD Shield or the Wishield depending which is on the bottom plus the SS/CS one on the sd shield!

mine was

Wishield
SDShield
Arduino Mega

Will retry my sketch now...

also forgot to mention... the onboard LED Won't light up...

#define USE_PIN_48_ForLED sets it up for use on pin 48 stick an LED on 48 and it will light up!
ArdWifi
 
Posts: 44
Joined: Wed Feb 03, 2010 8:39 am

Re: Wifi with SD Card...

Postby ArdWifi » Tue Oct 26, 2010 9:45 am

Making Progress can read a text file in... and a HTML file...

just trying to get images done!
ArdWifi
 
Posts: 44
Joined: Wed Feb 03, 2010 8:39 am

Re: Wifi with SD Card...

Postby bdodds » Tue Oct 26, 2010 11:02 am

I'm still waiting for my Mega to be delivered. Maybe today!!!
bdodds
 
Posts: 20
Joined: Tue Oct 19, 2010 6:01 pm
Location: Orange County CA

Re: Wifi with SD Card...

Postby ArdWifi » Thu Oct 28, 2010 10:21 am

hmmm the bottleneck seems to have moved... I have managed to get a small image 100bytes - 3KB to send...

anything more than that and it seems to fail. close to 3kb takes up to 10 - 20 seconds to load.

i can get the buffer up to about 340 but after that it freezes (no idea why) there is plenty of ram left

Free RAM: 6030

How big is the cache on the wiShield?

I am wondering if it is taking too long in the loop to read files bigger and it isn't getting to call

WiServer.server_task();

often enough to keep it alive

i have tried WiServer.write(buf[i]); and WiServer.print(buf[i]);
Code: Select all
int16_t n;
  uint8_t buf[200];// nothing special about 7, just a lucky number.
  while ((n = file.read(buf, sizeof(buf))) > 0) {
    for (uint8_t i = 0; i < n; i++){
      WiServer.write(buf[i]);
    }
  }


I also tried
Code: Select all
int16_t n;
  uint8_t buf[200];// nothing special about 7, just a lucky number.
  while ((n = file.read(buf, sizeof(buf))) > 0) {
    for (uint8_t i = 0; i < n; i++){
     WiServer.write(buf[i]);
     WiServer.server_task();
    }
  }


I have tried both the Fat16 and the Fat32 version of the SDCard Library and they both work... both with enough ram to do the job on the mega...

I have also tried using both the official WiShield Library and the community one both work the same with regards it dropping out... any guesses?

I am wondering if it is worth doing it as a socket app... but I wouldn't know how to start (do i have to write the HTTP Stuff that way?)

I am also wondering if the uFat library might work better but it seems to be reading from the SDCard fast enough... tried this by removing the bits inside
Code: Select all
while ((n = file.read(buf, sizeof(buf))) > 0) {
and putting a Serial Print at the bottom... it seems it is due to the WiServer code... is it limited to a lower packet size due to constraints on the 328?

Sorry for all the questions just thinking out loud!
ArdWifi
 
Posts: 44
Joined: Wed Feb 03, 2010 8:39 am

Re: Wifi with SD Card...

Postby bdodds » Thu Oct 28, 2010 10:35 am

I got my Mega today and should have time to play with this.

Maybe we should look at using the webserver instead of the wiserver now that we have more room?
bdodds
 
Posts: 20
Joined: Tue Oct 19, 2010 6:01 pm
Location: Orange County CA

Re: Wifi with SD Card...

Postby ArdWifi » Thu Oct 28, 2010 10:48 am

Sounds like a plan!
ArdWifi
 
Posts: 44
Joined: Wed Feb 03, 2010 8:39 am

Re: Wifi with SD Card...

Postby bdodds » Thu Oct 28, 2010 6:07 pm

I replaced my SPI.h with the one you posted here and can no longer compile the sketch...
I only get a flood of errors like this.

/libraries/WiShield/g2100.c:62: error: stray '\240' in program
/libraries/WiShield/g2100.c: In function 'spi_transfer':
/libraries/WiShield/g2100.c: In function 'zg_isr':
/libraries/WiShield/g2100.c:180: error: stray '\302' in program


and on and on...

Changing back to the original spi.h fixes the compile problem... What am I doing wrong?
bdodds
 
Posts: 20
Joined: Tue Oct 19, 2010 6:01 pm
Location: Orange County CA

PreviousNext

Return to WiShield 1.0

Who is online

Users browsing this forum: No registered users and 1 guest