2022-05-13 07:11 AM
Hi,
I'm not new to coding and have worked with C, JAVA and C# over the years. mostly in VIsual Studio for Unity and Ardunio.
I am currently using a STM32F411RE board to control a few peripherals (temp, VOC and colour) through I2C and want to display the data on a simple 128x64 dot matrix LCD screen through a SPI communication protocol.
This particular screen uses 3 wire SPI, which is fine for this application, all I need to do is write to the screen, no data is required to return on the MISO line.
I am required to use the LL settings for this and basically, as per my research, control this using GPIO pins and running a manual clock.
I tried to use the MX software to make the SPI1 connectivity a Half_Duplex_Master and (because the CS pin is different in MX as to the datasheet and physical board) the software wanted to choose PA4 as the CS pin.
The board, my PCB and the document all show the CS pin (NSS_pin) is PB6 and not PA4. The MX software is automatically selecting PA4 or PA15 for the NSS pin. Why is this different to the datasheet schematic?
Ive setup PB6 to be a GPIO_Output pin and I can get a "char c = 'a'; to show "97" in register "r2" while I step through the debugging tool.
Also,
Where do I start, I have being reading lots of theory about bit banging and bit shifting etc but I just don't know how to get started with getting text on the screen as a display, or even a debugging serial console on the IDE software to try some ideas.
regards,
gareth
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
char message = 'b';
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_I2C1_Init(void);
static void MX_SPI1_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
/* System interrupt init*/
NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_I2C1_Init();
MX_SPI1_Init();
/* USER CODE BEGIN 2 */
//local variables
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
if(LL_GPIO_IsOutputPinSet(GPIOB, SPI1_CS_Pin)) // Set the CS pin - PB6
{
LL_GPIO_ResetOutputPin(GPIOB, SPI1_CS_Pin);
}
SPI1->DR=message; // send the data
while (SPI1->SR & (1<<7)); // wait for the data to finish being sent
if(!LL_GPIO_IsOutputPinSet(GPIOB, SPI1_CS_Pin)) // Set the CS pin - PB6
{
LL_GPIO_SetOutputPin(GPIOB, SPI1_CS_Pin);
}
// reset the CS pin - PB6
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}