Facing issue with nRF7002 & nRF52840 configuration

Hello,

Hardware Setup:

  • nRF7002Ek - Serving as a Wi-Fi Chip.
  • nRF52840DK - Serving as Host Controller.
    • MOSI - p45
    • MISO - p46
    • SCK -  p47
    • CS - p44
  • Power Supply - Powered via USB.

Software Setup:

  • Development Environment: Visual Studio.
  • Framework: mbed

Issue Description: I'm facing an issue with Wi-Fi connectivity with nRF7002 and nRF52840. I am using mbed framework and visual studio.When I attempt to connect with WI-Fi using SPI communication protocol. I consistently receive failed to connect. I am trying with following code.

#include "mbed.h"
#include <PinNames.h>

// SPI setup for nRF7002
SPI spi(p45p46p47); // MOSI, MISO, SCK
DigitalOut cs(p44);     // Chip Select

// Serial interface for debugging
BufferedSerial pc(p6p8);

// WiFi credentials
const char* ssid = "###";
const char* password = "####";


#define SUCCESS_CODE 0x10  
#define FAILURE_CODE 0xFF  

// Initialize nRF7002
void init_nrf7002() {
    cs = 1; // Set CS high
    ThisThread::sleep_for(100ms);
    cs = 0;

    pc.write("Sending CIPHER INIT command...\r\n"strlen("Sending CIPHER INIT command...\r\n"));
    spi.write(0x4F); // CIPHER INIT command
    ThisThread::sleep_for(100ms); // Delay for initialization

    cs = 1;
}

// Send a string via SPI to nRF7002
void send_string(SPI& spiconst char* str) {
    while (*str) {
        spi.write(*str++);
    }
}

// Read a specific status register
uint8_t read_status_register(uint8_t command) {
    cs = 0;
    spi.write(command);  // Send the command
    ThisThread::sleep_for(10ms);
    uint8_t status = spi.write(0x00);  
    cs = 1;
    return status;
}

// Debugging function to print status registers
void debug_status() {
    uint8_t status0 = read_status_register(0x05); // RDSR
    uint8_t status1 = read_status_register(0x1F); // RDSR1
    uint8_t status2 = read_status_register(0x2F); // RDSR2

    char buffer[100];
    sprintf(buffer"Status0: 0x%02X, Status1: 0x%02X, Status2: 0x%02X\r\n"status0status1status2);
    pc.write(bufferstrlen(buffer));
}

// Connect to WiFi using nRF7002
void connect_to_wifi() {
    cs = 0;

    pc.write("Sending WiFi connection command...\r\n"strlen("Sending WiFi connection command...\r\n"));
    spi.write(0x01); // Command for WiFi connection (verify this command)
    ThisThread::sleep_for(100ms); // Delay for command processing

    send_string(spissid);
    send_string(spipassword);

    cs = 1;

    pc.write("Attempting to connect to WiFi...\r\n"strlen("Attempting to connect to WiFi...\r\n"));

    // Wait and check for connection status
    ThisThread::sleep_for(20000ms); // Increased delay for module response

    debug_status();

    uint8_t status = read_status_register(0x05); // RDSR

    if (status == SUCCESS_CODE) {
        pc.write("Connected to WiFi\r\n"strlen("Connected to WiFi\r\n"));
    } else {
        pc.write("Failed to connect to WiFi\r\n"strlen("Failed to connect to WiFi\r\n"));
    }
}

int main() {
    pc.set_baud(115200);
    spi.format(80);  // 8-bit data, Mode 0 (if Mode 0 is required)
    spi.frequency(1000000);  // 1 MHz

    init_nrf7002();
    connect_to_wifi();

    while (true) {
        ThisThread::sleep_for(5000ms);
    }
}

Here is the OUTPUT:

Sending CIPHER INIT command...
Sending WiFi connection command...
Attempting to connect to WiFi...
Status0: 0x00, Status1: 0x00, Status2: 0x00
Failed to connect to Wi-Fi

Any inputs on how can I get my nRF7002 to so anything on the network? I am new to this so I might be making some basic mistake.

Best Regards,

Sana Mulla

Parents Reply Children
Related