Hello!
I'm new to the microcontroller-world so this might be more of a beginner question.
But I'm trying work with the WiFly-Shield from Sparkfun. For that to work I figure out that I have to setup the onboard SPI-to-Uart chip (SC16IS750 ) [I think it would have been way easier to just use the RN-131-C chip over UART but well… ]
So the first attempt to just drop in the WiFly-Library and try to run the SpiUartTerminal-example didn't work out. Even though I modified the SpiUart.cpp that it should have run with Maple… Therefore I tried the most simple attemp…just writing and reading to the registers. (I know that not all registers are writeable…etc.) BUT all I get back on every register is 0xff…
But according to the datasheet (p14) nearly all should be cleared.
Can somebody please give me a hint what I'm doing wrong?!
Thanks
/Marcus
#define DEFAULT_CHIP_SELECT_PIN 10
#define DEFAULT_SPI_PORT 1
#define SPI_READ_MODE_FLAG 0x80
#include "libmaple.h"
#include "wirish.h"
void write_register(uint8 address, uint8 data);
uint8 read_register(uint8 address);
boolean foo = false;
HardwareSPI WiFly(DEFAULT_SPI_PORT);
void setup() {
WiFly.begin(SPI_9MHZ, MSBFIRST, 0);
pinMode(DEFAULT_CHIP_SELECT_PIN, OUTPUT);
}
void loop() {
if(SerialUSB.available() && foo == false) {
for(int i=0; i<16; i++){
SerialUSB.println("Writing to adress:");
SerialUSB.println( byte(i) << 3, BIN);
write_register(byte(i) << 3, 0x02);
}
delay(20);
for(int i=0; i<16; i++){
SerialUSB.println("Reading from adress:");
SerialUSB.println( byte(i) << 3, BIN);
SerialUSB.println( read_register(byte(i) << 3) );
}
foo = true;
}
}
void select(){
digitalWrite(DEFAULT_CHIP_SELECT_PIN, LOW);
}
void deselect(){
digitalWrite(DEFAULT_CHIP_SELECT_PIN, HIGH);
}
void write_register(uint8 address, uint8 data){
select();
WiFly.write(address);
WiFly.write(data);
deselect();
}
uint8 read_register(uint8 address){
uint8 data;
select();
// see Chapter 11 in Datasheed
WiFly.write(SPI_READ_MODE_FLAG | address);
data = WiFly.read();
deselect();
return data;
}