Go to Post but look at the bright side, you will now be able to size 1/4-20 nuts with your forearm and i doubt there are many people who can say that :p - Greg Needel [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 17-05-2011, 04:26
sanddrag sanddrag is offline
On to my 16th year in FRC
FRC #0696 (Circuit Breakers)
Team Role: Teacher
 
Join Date: Jul 2002
Rookie Year: 2002
Location: Glendale, CA
Posts: 8,517
sanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond repute
Help with Arduino and SPI

I'm slowly learning Arduino, and I'd like some help interfacing to an SPI device. The device is connected to the proper pins on an Arduino Uno. I understand in concept how it works. I need to send it 16 bits: 8 bits to specify the register, and 8 to make it do something based on the tables in the reference document. And the most significant bit comes first. However, I'm a little hung up on the exact code to make it start doing something. I've only gotten as far as defining all the registers as constants by their hex values. Is that correct? Can anyone who is familiar with such things perhaps provide a simple code example? I searched and couldn't find anything similar that made sense to me.
__________________
Teacher/Engineer/Machinist - Team 696 Circuit Breakers, 2011 - Present
Mentor/Engineer/Machinist, Team 968 RAWC, 2007-2010
Technical Mentor, Team 696 Circuit Breakers, 2005-2007
Student Mechanical Leader and Driver, Team 696 Circuit Breakers, 2002-2004

Last edited by sanddrag : 18-05-2011 at 01:35.
  #2   Spotlight this post!  
Unread 17-05-2011, 09:22
StevenB StevenB is offline
is having FRC withdrawal symptoms.
AKA: Steven Bell
no team
Team Role: College Student
 
Join Date: May 2005
Rookie Year: 2005
Location: Stanford, CA
Posts: 416
StevenB has a reputation beyond reputeStevenB has a reputation beyond reputeStevenB has a reputation beyond reputeStevenB has a reputation beyond reputeStevenB has a reputation beyond reputeStevenB has a reputation beyond reputeStevenB has a reputation beyond reputeStevenB has a reputation beyond reputeStevenB has a reputation beyond reputeStevenB has a reputation beyond reputeStevenB has a reputation beyond repute
Re: Help with Arduino and SPI

Here's some code from my optical mouse project. mDataPin and mClockPin are just integers that refer to the specific pins being manipulated.

Code:
/**
 * Writes an 8-bit value to one of the optical mouse's registers.
 *
 * \param address  The register address to write to.  Valid registers for the ADNS-2610 are 0x00
 * through 0x11.
 * \param value  The value to write.
 */
void Mouse::writeRegister(uint8 address, uint8 value)
{
  address = address | 0x80; // Most significant bit is always 1, since we're doing a write (This only applies to the mouse chip)
  pinMode(mDataPin, OUTPUT); // Only necessary if mDataPin is sometimes used as an input

  // We start by writing the most significant bit first
  for(int i = 0; i < 8; i++)
  {
    digitalWrite(mClockPin, 0); // Set the clock pin low
    digitalWrite(mDataPin, address & 0x80); // Set the data to the next bit
    digitalWrite(mClockPin, 1); // Set the clock pin high
    // Now the chip reads the data pin while we go around the loop
    address = address << 1; // Shift to the next bit
  }

  // Now write the data in exactly the same way
  for(int i = 0; i < 8; i++)
  {
    digitalWrite(mClockPin, 0);
    digitalWrite(mDataPin, value & 0x80);
    digitalWrite(mClockPin, 1);
    value = value << 1;
  }

}
__________________
Need a physics refresher? Want to know if that motor is big enough for your arm? A FIRST Encounter with Physics

2005-2007: Student | Team #1519, Mechanical Mayhem | Milford, NH
2008-2011: Mentor | Team #2359, RoboLobos | Edmond, OK
2014-??: Mentor | Looking for a team...
  #3   Spotlight this post!  
Unread 17-05-2011, 22:54
sanddrag sanddrag is offline
On to my 16th year in FRC
FRC #0696 (Circuit Breakers)
Team Role: Teacher
 
Join Date: Jul 2002
Rookie Year: 2002
Location: Glendale, CA
Posts: 8,517
sanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond repute
Re: Help with Arduino and SPI

I sort of understand the above with the exception of exactly what you're doing with the bit shift.

Has anyone here used the SPI library with Arduino?
__________________
Teacher/Engineer/Machinist - Team 696 Circuit Breakers, 2011 - Present
Mentor/Engineer/Machinist, Team 968 RAWC, 2007-2010
Technical Mentor, Team 696 Circuit Breakers, 2005-2007
Student Mechanical Leader and Driver, Team 696 Circuit Breakers, 2002-2004
  #4   Spotlight this post!  
Unread 17-05-2011, 23:27
unclewaldo unclewaldo is offline
Fabrication/Assembly/Cat Herder
FRC #0911 (WestBots)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: california
Posts: 24
unclewaldo is a jewel in the roughunclewaldo is a jewel in the roughunclewaldo is a jewel in the rough
Re: Help with Arduino and SPI

Try getting a copy of "Arduino Cookbook" [O'Reilly Books] by Michael Margolis
[ISBN978-0-596-80247-9] page 418 ..Chap 13 / problem 13.8 Driving Multidigit, 7-segment Displays Using SPI ... this might be helpful to understand and also for code ...
  #5   Spotlight this post!  
Unread 17-05-2011, 23:31
unclewaldo unclewaldo is offline
Fabrication/Assembly/Cat Herder
FRC #0911 (WestBots)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: california
Posts: 24
unclewaldo is a jewel in the roughunclewaldo is a jewel in the roughunclewaldo is a jewel in the rough
Re: Help with Arduino and SPI

FYI - "Arduino Cookbook" chapter 13 has multiple examples of Communicating Using I2C and SPI with multidigit segmented displays
  #6   Spotlight this post!  
Unread 18-05-2011, 01:36
sanddrag sanddrag is offline
On to my 16th year in FRC
FRC #0696 (Circuit Breakers)
Team Role: Teacher
 
Join Date: Jul 2002
Rookie Year: 2002
Location: Glendale, CA
Posts: 8,517
sanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond reputesanddrag has a reputation beyond repute
Re: Help with Arduino and SPI

Quote:
Originally Posted by unclewaldo View Post
Try getting a copy of "Arduino Cookbook" [O'Reilly Books] by Michael Margolis
[ISBN978-0-596-80247-9] page 418 ..Chap 13 / problem 13.8 Driving Multidigit, 7-segment Displays Using SPI ... this might be helpful to understand and also for code ...
Got the book. That really helps. I was missing the concept of setting the chip select pin low, writing the two bytes, then setting it high. Got my device working now. Thanks.
__________________
Teacher/Engineer/Machinist - Team 696 Circuit Breakers, 2011 - Present
Mentor/Engineer/Machinist, Team 968 RAWC, 2007-2010
Technical Mentor, Team 696 Circuit Breakers, 2005-2007
Student Mechanical Leader and Driver, Team 696 Circuit Breakers, 2002-2004
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 18:51.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi