STM32 Nucleo to Arduino Uno SPI Communication NSS bit not working

Thread Starter

z_iron

Joined May 24, 2020
23
I'm programming an STM32L47RG Nucleo (Master) to communicate with an Arduino Uno (Slave) via SPI but have an issue i cant seem to figure out.
Capture.JPG
From my understanding, the Arduino will only recieve data via the MOSI line when the NSS (or CS) line is pulled low and the NSS pin will only be pulled low when the SSOE (Slave select output enable) bit is enabled and the SPE (SPI Peripheral Enable) bit is also enabled given the SSM (Slave select management) bit is zero. Disabling the SPE bit will bring NSS back high and the Arduino wont recieve data.

The STM32 is sending and the slave does not send anything back. Here is my code for the main.c STM32 file:


C:
int main(void){

    char user_data[] = "Test";

    SPI2_GPIOInits();
    SPI2_Inits();
    GPIO_ButtonInit();
    GPIO_LEDInit();

    SPI_SSOEConfig(SPI2,ENABLE);

    while(1){
        while(GPIO_ReadPin(GPIOC,13) == CLEAR)
        {
            GPIO_TogglePin(GPIOA,5);

            //to avoid button de-bouncing related issues 200ms of delay
            //delay();

            //enable the SPI2 peripheral
            SPI_PeripheralControl(SPI2,ENABLE);
            GPIO_TogglePin(GPIOA,5);
            //first send length information

            uint8_t dataLen = strlen(user_data);
            SPI_Send(SPI2,&dataLen,1);
            GPIO_TogglePin(GPIOA,5);
            //to send data
            SPI_Send(SPI2,(uint8_t*)user_data,strlen(user_data));

            //lets confirm SPI is not busy
            while( SPI_GetFlagStatus(SPI2,SPI_BUSY_FLAG));
            //GPIO_TogglePin(GPIOA,5);
            //Disable the SPI2 peripheral
            SPI_PeripheralControl(SPI2,DISABLE);
        }

    }
    return 0;
}
I'm reading the NSS bit via the serial monitor on the Arduino side. It is always high and turns low for a brief moment when SPI2_GPIOInits() is called then goes high again. (All Init functions are correct). The issue is that after SPI_SSOEConfig(SPI2,ENABLE) is called and then SPI_PeripheralControl(SPI2,ENABLE) is called, NSS should be pulled low right? yet I'm still reading a high value from the Arduino and its not recieving anything.

Capture3.JPG
Single stepping through each line you can see on the side SPE and SSOE are both enabled.

Untitled.jpg
I'm using a logic level converter from spark fun (https://www.sparkfun.com/products/12009) between the two boards. The diagram above shows my layout. The 5v and 3.3v pins on the Nucleo are from the arduino connector pins (not the morpho pins).

Why is the NSS bit still being read as high and the Arduino not recieving data?
 

Attachments

Top