Gameboy SPI connection to link cable

Greetings everyone,

I’m currently working, with a friend, on a project about the creation of an Ethernet link cable for the Nintendo Gameboy.
The communication protocol is some kind of SPI but without a slave select.
My friend wrote a program on the gameboy (just a simple sending of “Hello World”) and I’m supposed to receive it with a Nucleo F303K8 (I will soon change to a NUCLEO-F746ZG) using its spi ports (A4 for clock, A5 for MISO and A6 for MOSI).

I’ve received the message using a logic port analyser (helping me finding that it’s in spi mode 3) so now, i’m looking to get in on the nucleo. But … I don’t receive any message …
Here is my code :
#include “mbed.h”

Serial pc(SERIAL_TX, SERIAL_RX);



SPISlave device(A6, A5, A4, A3); // mosi, miso, sclk, ssel
DigitalOut led(LED3);
int main()
{
    pc.baud(115200);
    led = 1;
    device.format(8,3);
    device.frequency(8192);
    for(int i = 0; i<6; i++)
    {
        led=!led;
        wait_ms(50);    
    }
    pc.printf("Demarrage SPI\n");
    while(1) {
       if(device.receive()) {
           pc.printf("reçu");
           int v = device.read();   // Read byte from master
           pc.printf("On a recu le byte : %d \n", v);
        }
    }
}

(Yep it’s in french but don’t worry, i’m pretty sure it’s not the source of my problem)

Don’t you have the idea why I receive nothing ? (I don’t even enter in the if statement)

Thanks you very much.

Hi,

I would check that mosi & miso are as they shoud - now you have slave. Then I would check ```
device.frequency(8192); is correct.

One problem might happened because sending of “Hello World” have 11 bytes. On the while loop you try to read those as fast as possible but you have printf()s in the loop.
I would also add
device.reply(0x00); // Prime SPI with first reply
before while loop. And after you have device.read() add again device device.reply(0x00);

In the end I would try SPI Slave with SPI Master which another MbedOS board with the same format setting and frequency. Now the problem is that you can’t be sure what the Gameboy SPI is sending. If you test with known SPI Master and Slave works then you know that format or frequency is wrong.

Regards,
Pekka

Hi

You say “it’s in spi mode 3”

and then you try and use 4 pins for the device:
SPISlave device(A6, A5, A4, A3); // mosi, miso, sclk, ssel

Maybe can you try to remove the unused pin (ssel) from the device selection using NC (not connected)

hope this helps …

Thank you for your suggestions,
adding device.reply changed nothing. Also, I verified all of the datas (like the mode or the frequency of the clock)
Also, I don’t think the printf will cause a problem for the moment … because I don’t enter the if even one time.
I will try using a master.

Have you tried SPISlave device(A6, A5, A4, NC); ??

Thats it ! Now I enter in the if but i don’t have the good byte.
I think it is the cause of the printf, i will write it in a table !
I’ll be back soon.

Thank you so much !