cancel
Showing results for 
Search instead for 
Did you mean: 

Why my SPI doesn't work?

RDois
Associate II

I'm want to communicate with a 1.54 inc epaper waveshare screen via half-duplex SPI from my nucleo STM32L433RCxT board. I use CUBEMX, HAL library, TrueStudio and ST-Link Utility.

I have a problem. Whenever I try to send anything with use of the SPI when the screen is connected to the board the program fails. It's untraceable mistake. I've already tried to debug it on my own and with a guy who code STMs for a living and didn't manage to find any reason of the problem.

When the screen isn't connected to the board the program executes without failure.

All I do in the code is:

#include "main.h"
#include "stm32l4xx_hal.h"
#include "image.h"
#include <stdbool.h>
 
 
SPI_HandleTypeDef hspi1;
 
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);
 
void system_init() {
	HAL_Init();
	SystemClock_Config();
	MX_GPIO_Init();
	MX_SPI1_Init();
	HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_SET);
}
 
void send_command_154(uint8_t data) {
	HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_RESET);
	HAL_GPIO_WritePin(DC_GPIO_Port, DC_Pin, GPIO_PIN_RESET);
	HAL_SPI_Transmit(&hspi1, &data, 1, 1000);
	while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
	HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_SET);
}
 
int main(void)
{
	system_init();
	send_command_154(0x01);
 
		while (1) {
			HAL_GPIO_TogglePin(user_led_GPIO_Port, user_led_Pin);
			HAL_Delay(500);
		}
 
}

What could be the reason of that issue. Will be super glad if anyone help me move on with this. Cause it's already a whole week I cannot figure out how to move on. Seriously.

2 REPLIES 2

> Whenever I try to send anything with use of the SPI when the screen is connected to the board the program fails.

> When the screen isn't connected to the board the program executes without failure.

If there's no readback or pin sensing which would change internal state of the code based on whether the display is connected or not, it's a hardware problem.

JW

T J
Lead

you need to install a serial port and start transmitting to a debug screen...