2017-07-24 05:31 AM
Hi there,
I have alot of problems with SPWF04S and its SPI interface. From the datasheet this is what should happen:
TX:
1. The communication starts with the host sending the write SYNC word (0x02), 2. followed by header information, and then payload, when applicable. 3. Once the command has been analyzed by the device, it asserts the IRQ interrupt line.RX:
1. Then the host detects the interrupts and then 2. writes the read SYNC word (0x02) and 3. starts to generate the clock. 4. The device then clears the interrupt line and prepares the response. 5. The host then reads continuously until the SYNC pattern is detected. 6. All data until that point is discarded. 7. The SYNC word is then followed by headers and then payload, when applicable.for a start, as im not sure which diagrams are correct and which are not, im not sure what the default state of the module is. is irq default low or high? do I need to receive a message already?
If I attach it to my arduino uno and hook it up to the oscilloscope I can see that the IRQ line is initially LOW. so I do as stated and start with sending my test packet {0x02, 0x00, 0x02, 0x01, 0x00} ('AT' alone) and wait for the IRQ line to go back up. This never happens! No matter if I keep CS low while waiting or not.
So can someone PLEASE give me a list of steps how the communication SHOULD work? Btw, I have no interrupt on that pin, so I can only check it from time to time
Best regards
2017-07-24 10:44 PM
So I figured this out myself, here is some working arduino uno code, seems this only works up to 1 MHz without having an interrupt:
#include 'SPI.h'
SPISettings setting = SPISettings(1000000, MSBFIRST, SPI_MODE0);byte CMD_1[5] = {0x02, 0x00, 0x02, 0x01, 0x00};byte CMD_2[5] = {0x02, 0x00, 0x02, 0x02, 0x00};byte CMD_3[5] = {0x02, 0x00, 0x02, 0x03, 0x00};byte CMD_4[11] = {0x02, 0x00, 0x08, 0x05, 0x01, 0x05, 0x62, 0x75, 0x69, 0x6C, 0x64};byte RX_BUF[256];int INTpin = 9;int CSpin = 18;void setup() { Serial.begin(115200); Serial.println('SPWF04SA WIFI test program start.'); SPI.begin(); digitalWrite(CSpin, INPUT_PULLUP); digitalWrite(INTpin, INPUT_PULLUP); digitalWrite(11, INPUT_PULLUP); pinMode(INTpin, INPUT); pinMode(CSpin, OUTPUT); Serial.println('Setup SPI done.');}void loop() { if (Serial.available() > 0) { int b = Serial.read(); switch(b) { case 49: Serial.println('Sending 'AT'...'); SendSPI(CMD_1, 5); break; case 50: Serial.println('Sending 'AT+S.HELP'...'); SendSPI(CMD_2, 5); break; case 51: Serial.println('Sending 'AT+S.STS'...'); SendSPI(CMD_3, 5); break; case 52: Serial.println('Sending 'AT+S.STS=build'...'); SendSPI(CMD_4, 11); break; default: Serial.println('Unknown Command'); break; } } while(!digitalRead(INTpin)) CheckRX();}void CheckRX(){ Serial.print('RX:'); SPI_start(); SPI.transfer(2); RX_BUF[0] = 2; for(int i=0;i<4;i++) RX_BUF[i+1] = SPI.transfer(0); int size = (RX_BUF[4] << 8) + RX_BUF[3]; for(int i=0; i < size; i++) RX_BUF[i+5] = SPI.transfer(0); SPI_end(); PrintBuff(size);}void SendSPI(byte* buf, int len){ SPI_start(); for(int i=0;i<len;i++) SPI.transfer(buf[i]); SPI_end();}void PrintBuff(int size){ for(int i=0; i < 5 + size; i++) { if(i < 5) { if(RX_BUF[i] < 0x10) Serial.print('0'); Serial.print(RX_BUF[i], HEX); Serial.print(' '); } else Serial.print((char)RX_BUF[i]); } if(RX_BUF[3 + size] != 0xD && RX_BUF[4 + size] != 0xA) Serial.println();}void SPI_start(){ SPI.beginTransaction(setting); digitalWrite(CSpin, LOW);}void SPI_end(){ digitalWrite(CSpin, HIGH); SPI.endTransaction();}If it doesnt work right away, I use the reset button for now, but I guess this could be done by a GPIO later too
2018-02-07 01:39 AM
Hi bernd,
if you are doing 8 left shift , you will loose the RX_BUF[4] right...?
int size = (RX_BUF[4] << 8) + RX_BUF[3];