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.
- The PC communicates over UART with the Arduino through pins RX and TX
- 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)
- 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
}