Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Question about SPI


  • Please log in to reply
15 replies to this topic

#1 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 03 January 2011 - 12:05 AM

What are the differences between SPI and the other thing that uses TX and RX? I understand that SPI has a clock so the shift register (lets use that as an example) knows when to read the other pin for a HIGH or LOW. but then how does the TX and RX communicate? how does it know when to get the data? Are they both Serial types of communication or not? Any info is appreciated, links are good too. Thanks!

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 January 2011 - 12:12 AM

Hi Omar, UARTs use TX/RX wires to communicate similarly to SPI. Except that SPI only sends/receives data when the SPI clock line goes up and down. UARTs send/receive data on a regular basis (as set by the serial port's bps rate). With UARTs, both sides have to agree to a speed before starting the communication--and there's some logic that happens in the UART receiver at each end to stay in sync after every byte (i.e. using "stop bits"). With SPI, the master decides the speed and time of the transfer...and the slave just grabs a byte when the polarity of the line changes. Chris

#3 klotz

klotz

    Advanced Member

  • Members
  • PipPipPip
  • 60 posts

Posted 03 January 2011 - 12:19 AM

What are the differences between SPI and the other thing that uses TX and RX? I understand that SPI has a clock so the shift register (lets use that as an example) knows when to read the other pin for a HIGH or LOW. but then how does the TX and RX communicate? how does it know when to get the data? Are they both Serial types of communication or not? Any info is appreciated, links are good too. Thanks!


I don't know how much time you have to read stuff, and we could spend a lot of time asking and answering questions so I thought that it may be helpful to supply you with a link to the Wikki page that describes SPI. This may be way more than you wanted to know but there are nuances to using SPI that are not immediately apparent and which many of us take for granted. So here is the Wikki link ( and yes I read it and it is a good description on Jan 2, 2010 :D You know how Wikkipedia can be )
http://en.wikipedia....l_Interface_Bus

#4 klotz

klotz

    Advanced Member

  • Members
  • PipPipPip
  • 60 posts

Posted 03 January 2011 - 12:25 AM

What are the differences between SPI and the other thing that uses TX and RX? I understand that SPI has a clock so the shift register (lets use that as an example) knows when to read the other pin for a HIGH or LOW. but then how does the TX and RX communicate? how does it know when to get the data? Are they both Serial types of communication or not? Any info is appreciated, links are good too. Thanks!

Tx and Rx are used for Asynchronous Serial communication which is sometimes described as "self clocking". This is misleading to most users in that the data rate must generally be agreed upon before hand as Chris has stated, the selfclocking come from the method for detecting the begining of the data octet or byte. Here is the Wikkipedia page that describes this http://en.wikipedia....ver/transmitter as before I can only vouch for the correctness as of Jan 2, 2010 when I read it. :D

If I had a choice, I would use SPI over TX/RX because it is easier for me to use. If available and if the distance is not too great I would prefer I2C over SPI.

Edited by klotz, 03 January 2011 - 12:28 AM.


#5 Frank

Frank

    Advanced Member

  • Members
  • PipPipPip
  • 62 posts
  • LocationNorth Waterboro Maine

Posted 03 January 2011 - 01:47 AM

If available and if the distance is not too great I would prefer I2C over SPI.

Could you break this down a bit more? Distance being what? If I have a central Netduino in the house, and several scattered around the property, what's the prefered for 50 -200 ft, CAT5 cable?
Retired -stone sculptor -macro photographer- novice but avid Go player - Geek

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 January 2011 - 02:03 AM

If I have a central Netduino in the house, and several scattered around the property, what's the prefered for 50 -200 ft, CAT5 cable?


The preferred method there is TCP/IP networking :)

Chris

#7 klotz

klotz

    Advanced Member

  • Members
  • PipPipPip
  • 60 posts

Posted 03 January 2011 - 03:28 PM

If available and if the distance is not too great I would prefer I2C over SPI.

Could you break this down a bit more? Distance being what? If I have a central Netduino in the house, and several scattered around the property, what's the prefered for 50 -200 ft, CAT5 cable?


I would not use I2C or SPI for those distances. In the first case, one should not think of I2C or SPI as a protocol for anything say outside the box. Both are intended for communication between ICs or small peripherals, like ethernet chips, lCD displays and the like.
If I have to go more than a couple of feet, then I would start to concider one of the interconnect serial protocols like Async (TTL, RS232, or RS485.)
Then if we are in the range of Room to Room or greater I would concider ethernet.
So in answer to you direct question. At 50-200ft, especially if you have already installed CAT5, go ethernet. The shields for 'duinos are cheap and .NETMF makes it easy to program.

#8 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 03 January 2011 - 04:16 PM

This doc talks about extending one wire to 200m: http://www.maxim-ic....ndex.mvp/id/148

#9 segu

segu

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationLima - Peru

Posted 04 January 2011 - 02:46 AM

If we are talking of "extend the original distance" look at NXP I2C for long-distance communications :)

#10 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 04 January 2011 - 02:51 AM

Thank you all for your help, now I think I need to learn more about this I2C... I haven't used it yet.

#11 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 09 January 2011 - 07:51 PM

I have another question....

I use this code to setup the spi for the nokia 5100 screen I am using.
 SPI.Configuration spiConfiguration = new SPI.Configuration(
                latch,            
                false,                 // IC is accessed when chip select is low
                0,                     // setup time 0 ms
                0,                     // hold chip select 0 ms after transfer
                false,                 // clock line is low if device is not selected
                true,                  // data is sampled at leading edge of clock
                2000,                 
                SPI.SPI_module.SPI1   
                );
I was wondering what the clock rate number that I put in translates to.... Like I have 2000 there, what is that in Hertz? It says kHz so is that 2 MHz? or something else?

also how do I go convert something like 4 Mega bits per second to Herts?

Thanks

#12 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 09 January 2011 - 09:08 PM

Like I have 2000 there, what is that in Hertz? It says kHz so is that 2 MHz?

Yes, 2000 kHz = 2 MHz.

also how do I go convert something like 4 Mega bits per second to Hertz?

In case of SPI the value of bitrate (data transfer speed) equals to clock frequency, because it requires one clock pulse to transfer one bit (there is no protocol overhead). Thus, to achieve bit rate of 4 MHz, you need the clock to run at 4 MHz.

#13 AlfredBr

AlfredBr

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationConnecticut, USA

Posted 09 January 2011 - 10:15 PM

Yes, 2000 kHz = 2 MHz.


In case of SPI the value of bitrate (data transfer speed) equals to clock frequency, because it requires one clock pulse to transfer one bit (there is no protocol overhead). Thus, to achieve bit rate of 4 MHz, you need the clock to run at 4 MHz.


I've gone up to 9500 successfully with that screen, but normally set it to 4000 (per the datasheet).

#14 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 09 January 2011 - 10:42 PM

I've gone up to 9500 successfully with that screen, but normally set it to 4000 (per the datasheet).

Great I was running it at half the speed! Now it should have a much faster refresh rate right?

#15 AlfredBr

AlfredBr

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationConnecticut, USA

Posted 09 January 2011 - 11:01 PM

Great I was running it at half the speed! Now it should have a much faster refresh rate right?


I have not noticed much difference...it is only 504 bytes that is moving. I imagine that the liquid crystal phase change in going to be the limiting factor.

#16 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 09 January 2011 - 11:39 PM

I imagine that the liquid crystal phase change in going to be the limiting factor.

Yeah I've noticed that it takes a little time fading out... oh well, it still runs pretty well




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.