3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Twitter Mood Light - The World's Mood in a Box

Step 7Programming step 1: SPI UART

Programming step 1: SPI UART
«
  • SPIUart.jpg
  • example6.jpg
The WiFly Shield equips your Arduino with the ability to connect to 802.11b/g wireless networks.
The featured components of the shield are:
  • a Roving Network's RN-131G wireless module
  • SC16IS750 SPI-to-UART chip. 
Serial Peripheral Interface Bus (or SPI) is a "four wire" serial bus capable of high rates of data transmission. A serial bus allows data to be sent serially (synchronously), i.e. one bit at a time, rather than in parallel (asynchronous)

The Universal asynchronous receiver/transmitter (or UART) is a type of asynchronous receiver/transmitter, a piece of computer hardware that translates data between parallel and serial forms.
  1. The PC communicates over UART with the Arduino through pins RX and TX
  2. The Arduino communicates over SPI with the SPI-UART chip on the WiFly shield (SC16IS750 SPI-to-UART chip) though pins 10-13 (CS, MOSI, MISO, SCLK respectively)
  3. The RN-131G wireless module accesses network and send/receive serial data over UART.
The SPI-to-UART bridge is used to allow for faster transmission speed and to free up the Arduino's UART.

The code below is based on a number of sources, but primarily from this tutorial over at sparkfun:
www.sparkfun.com/commerce/tutorial_info.php 
WiFly Wireless Talking SpeakJet Server


/* Test if the SPI<->UART bridge has been set up correctly by writing a test
   character via SPI and reading it back.
   returns true if success
*/
bool WiFly::TestSPI_UART_Bridge()
{
 // Perform read/write test to check if SPI<->UART bridge is working
 
 // write a character to the scratchpad register.
 WriteByteToRegister(SPR, 0x55);
 
 char data = ReadCharFromWiFly(SPR);
 
 if(data == 0x55)
 {
    return true;
 }
 else
 {
    m_printer->println("Failed to init SPI<->UART chip");
    return false;
 }
}
 
/* A series of register writes to initialize the SC16IS750 SPI-UART bridge chip
   see http://www.tinyclr.com/downloads/Shield/FEZ_Shields_WiFly.cs
*/
void WiFly::SPI_UART_Init(void)
{
 WriteByteToRegister(LCR,0x80); // 0x80 to program baudrate
 WriteByteToRegister(DLL,SPI_Uart_config.DivL); //0x50 = 9600 with Xtal = 12.288MHz
 WriteByteToRegister(DLM,SPI_Uart_config.DivM);
 
 WriteByteToRegister(LCR, 0xBF); // access EFR register
 WriteByteToRegister(EFR, SPI_Uart_config.Flow); // enable enhanced registers
 WriteByteToRegister(LCR, SPI_Uart_config.DataFormat); // 8 data bit, 1 stop bit, no parity
 WriteByteToRegister(FCR, 0x06); // reset TXFIFO, reset RXFIFO, non FIFO mode
 WriteByteToRegister(FCR, 0x01); // enable FIFO mode
}


« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
29
Followers
1
Author:RandomMatrix