Hello Guys..
I have Arduino UNO and A USB Host Shield From Sparkfun..
The Problem is that when we attach USB Host Shield with Arduino UNO, it grabs/reserves the SPI pins..
This creates a new problem that i cant attach another Slave to SPI Port..
I Have Tried to select multiple slaves but failed..
Any Suggestion about how to handle multiple SPI Slaves by attaching USB Host Shield With Arduino?
The SPI bus can be shared but each device on the bus must have it's own SS signal/pin. The host shield uses pin 10 as SS, so any shield with a SPI device using another SS pin should work without changes. If the other shield uses the same SS pin you might have to cut the pin an re-wire it or a go-between shield (which does more ore less the same).
pylon:
The SPI bus can be shared but each device on the bus must have it's own SS signal/pin. The host shield uses pin 10 as SS, so any shield with a SPI device using another SS pin should work without changes. If the other shield uses the same SS pin you might have to cut the pin an re-wire it or a go-between shield (which does more ore less the same).
I am using another SS pin which is A5 pin. But Nothing Happend With that 2nd Slave Device..
The Sketch i am using is... But Nothing Happening On 2nd Slave Device. No Data Receiving..
#include <avr/pgmspace.h>
#include <avrpins.h>
#include <max3421e.h>
#include <usbhost.h>
#include <usb_ch9.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <address.h>
#include <hidboot.h>
#include <printhex.h>
#include <message.h>
#include <hexdump.h>
#include <parsetools.h>
#include "SPI.h"
#define SS2 A5
class MouseRptParser : public MouseReportParser
{
protected:
virtual void OnMouseMove (MOUSEINFO *mi);
virtual void OnLeftButtonUp (MOUSEINFO *mi);
virtual void OnLeftButtonDown (MOUSEINFO *mi);
virtual void OnRightButtonUp (MOUSEINFO *mi);
virtual void OnRightButtonDown (MOUSEINFO *mi);
virtual void OnMiddleButtonUp (MOUSEINFO *mi);
virtual void OnMiddleButtonDown (MOUSEINFO *mi);
};
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
Serial.print("dx=");
Serial.print(mi->dX, DEC);
Serial.print(" dy=");
Serial.println(mi->dY, DEC);
};
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
{
Serial.println("L Butt Up");
};
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
{
Serial.println("L Butt Dn");
};
void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
{
Serial.println("R Butt Up");
};
void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi)
{
Serial.println("R Butt Dn");
};
void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi)
{
Serial.println("M Butt Up");
};
void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)
{
Serial.println("M Butt Dn");
};
USB Usb;
USBHub Hub(&Usb);
HIDBoot<HID_PROTOCOL_MOUSE> Mouse(&Usb);
uint32_t next_time;
MouseRptParser Prs;
void setup()
{
pinMode(SS2, OUTPUT);
//digitalWrite(SS2,LOW);
Serial.begin( 115200 );
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
next_time = millis() + 5000;
Mouse.SetReportParser(0,(HIDReportParser*)&Prs);
}
void loop()
{
// Disable Default SS Pin Of USB Host Shield:
digitalWrite(SS,HIGH);
// Enable 2nd Slave:
digitalWrite(SS2,LOW);
// send value via SPI To 2nd Slave:
SPI.transfer('1');
// Disable 2nd Slave
digitalWrite(SS2,HIGH);
// Enable USB Host Shield Again
digitalWrite(SS,LOW);
/////////////////////////////////////
Usb.Task();
////////////////////////////////////
// Disable Default SS Pin Of USB Host Shield:
digitalWrite(SS,HIGH);
// Enable 2nd Slave:
digitalWrite(SS2,LOW);
// send value via SPI To 2nd Slave:
SPI.transfer('1');
// Disable 2nd Slave
digitalWrite(SS2,HIGH);
// Enable USB Host Shield Again
digitalWrite(SS,LOW);
}
What kind of device is your device 2?
Please use the code tags (# button in the form) for all code, else there are problems for us reading it.
Sory for the uggly Code.. By The Way, the 2nd device(SPI Slave) is another Arduino on BreadBoard.
SPI is, by nature, a "shareable", or stackable connection. You can stack shields on the ICSP header.
The problem is that very few (if any) shields come with stackaber headers on the ICSP / SPI pins.
I solved this problem by chaging the pins in the header for extended pins, making the header stackable.
Here's what I talking about (the upper shield is the USB host shield):
More images here: http://arduino.cc/forum/index.php/topic,126197.0.html
but it does have a breadboard area where the ICSP header would be. Solder one on?
Problem Solved...
Using Usb Host Shield, We can connect more than one SPI slaves on Arduino.
This is the sample code for communicating with other SPI slave by SelaveSelect2 (SS2) on Pin 6
#include <avr/pgmspace.h>
#include <avrpins.h>
#include <max3421e.h>
#include <usbhost.h>
#include <usb_ch9.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <address.h>
#include <hidboot.h>
#include <printhex.h>
#include <message.h>
#include <hexdump.h>
#include <parsetools.h>
#include "SPI.h"
#define SS2 6
class MouseRptParser : public MouseReportParser
{
protected:
virtual void OnMouseMove (MOUSEINFO *mi);
virtual void OnLeftButtonUp (MOUSEINFO *mi);
virtual void OnLeftButtonDown (MOUSEINFO *mi);
virtual void OnRightButtonUp (MOUSEINFO *mi);
virtual void OnRightButtonDown (MOUSEINFO *mi);
virtual void OnMiddleButtonUp (MOUSEINFO *mi);
virtual void OnMiddleButtonDown (MOUSEINFO *mi);
};
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
Serial.print("dx=");
Serial.print(mi->dX, DEC);
Serial.print(" dy=");
Serial.println(mi->dY, DEC);
};
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
{
Serial.println("L Butt Up");
};
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
{
Serial.println("L Butt Dn");
digitalWrite(SS2,LOW); // Use any pin except 10,11,12 or 13
SPI.transfer('1');
digitalWrite(SS2,HIGH);
};
void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
{
Serial.println("R Butt Up");
};
void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi)
{
Serial.println("R Butt Dn");
digitalWrite(SS2,LOW); // Use any pin except 10,11,12 or 13
SPI.transfer('0');
digitalWrite(SS2,HIGH);
};
void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi)
{
Serial.println("M Butt Up");
};
void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)
{
Serial.println("M Butt Dn");
};
USB Usb;
USBHub Hub(&Usb);
HIDBoot<HID_PROTOCOL_MOUSE> Mouse(&Usb);
uint32_t next_time;
MouseRptParser Prs;
void setup()
{
pinMode(SS2,OUTPUT);
digitalWrite(SS2,HIGH);
Serial.begin( 115200 );
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
next_time = millis() + 5000;
Mouse.SetReportParser(0,(HIDReportParser*)&Prs);
SPI.begin();
SPCR = 0x51;
}
void loop()
{
Usb.Task();
}
Thanx To Kristian Lauszus for solving This Problem...
How did you solve this? I believe people who read this is as curious as me.
Might be a little to late to ask, but i am very curious of how yasiralijaved got it going.
I have a USB HOST Shield + Arduino Ethernet Shield using it on an Arduino MEGA 2560. I have looked and gone through so many forums and i have tried so many libraries. i have done the hardware Hacks, to get these 2 shields to work together and i can get only one at a time. the one that normally works is the one that connects to the ICSP of the MEGA, so which ever is mounted on the MEGA is the one that will work.
i have changed the USBcore.h file from <p10, p9> to <p5, p9> and i have cut the jumper SS pin (10) on the USB Shield 2.0 and hardwired it to PIN5. in the firmware i have set it up as an output and set it to HIGH.
is there something else that i am missing?
I'm in the middle of wiring up the same thing and therefore do not have a proven solution to the problem, however it is my understanding that the SPI connections on the Mega are pins 50-53 . My plan is to wire 10-13 on the usbhost to those pins and bypass 10-13 on the Mega.
Hello. I recently figured out how to connect a SparkFun USB host shield to the Mega. There were issues because the SparkFun shield is one which doesn't use the ICSP header. You may find my post on the SparkFun boards useful...