1

dear helpers and coding gods, i want to make an pong game with spi connection to the dot matrix on a stm32f0 with the program aplication keill, and the hardware, MAX7219 Dot matrix module 8x8 Communicate with SPI1 communication to the 8x8 LED matrix. Dot matrix connected to 5v, gnd, pa7, pa4 and pa5 and the

my question is how can i write stuff to the screen with an spi connection to play the game eventionaly but first an h or some other simple thing. because i dont know what im doing wrong. dac has nothing to do with the program.

below here is my code to just write an h to the schreen so i can begin to code the game. but het does not write annuthing and my edditor keill says implicit declaration of the function SPI_I2S_SendData

/******************************************************************************
 * File           : Main program - Single Mode
 *****************************************************************************/
#include "stm32f0xx.h"
#include "stm32f0_discovery.h"
#include "helper.h"
#include "stm32f0xx_gpio.h"
//#include "stm32f0xx_spi.h"


/* SPI1 pin definition */
#define SPI1_SCK_PIN    GPIO_Pin_5
#define SPI1_MISO_PIN   GPIO_Pin_4
#define SPI1_MOSI_PIN   GPIO_Pin_7
#define SPI1_GPIO_PORT  GPIOA
#define SPI1_GPIO_CLK   RCC_AHBPeriph_GPIOA

/* MAX7219 command definitions */
#define MAX7219_NOOP            0x00
#define MAX72`19_DIGIT0          0x01
#define MAX7219_DIGIT1          0x02
#define MAX7219_DIGIT2          0x03
#define MAX7219_DIGIT3          0x04
#define MAX7219_DIGIT4          0x05
#define MAX7219_DIGIT5          0x06
#define MAX7219_DIGIT6          0x07
#define MAX7219_DIGIT7          0x08
#define MAX7219_DECODEMODE      0x09
#define MAX7219_INTENSITY       0x0A
#define MAX7219_SCANLIMIT       0x0B
#define MAX7219_SHUTDOWN        0x0C
#define MAX7219_DISPLAYTEST     0x0F

/* Function prototypes */
void SPI1_Init(void);
void MAX7219_Init(void);
void MAX7219_SendData(uint8_t reg, uint8_t data);

int main(void)
{
    /* Initialize SPI1 */
    SPI1_Init();

    /* Initialize MAX7219 */
    MAX7219_Init();

    /* Main loop */
    while (1)
    {
        /* Display a "H" character on the matrix */
        MAX7219_SendData(MAX7219_DIGIT0, 0x7E);
        MAX7219_SendData(MAX7219_DIGIT1, 0x09);
        MAX7219_SendData(MAX7219_DIGIT2, 0x09);
        MAX7219_SendData(MAX7219_DIGIT3, 0x7E);
        MAX7219_SendData(MAX7219_DIGIT4, 0x00);
        MAX7219_SendData(MAX7219_DIGIT5, 0x00);
        MAX7219_SendData(MAX7219_DIGIT6, 0x00);
        MAX7219_SendData(MAX7219_DIGIT7, 0x00);
    }
}

/* Initialize SPI1 */
void SPI1_Init(void)
{
    SPI_InitTypeDef SPI_InitStruct;
    GPIO_InitTypeDef GPIO_InitStruct;

    /* Enable SPI1 and GPIOA clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
    RCC_AHBPeriphClockCmd(SPI1_GPIO_CLK, ENABLE);

    /* Configure SPI1 pins: SCK, MISO and MOSI */
    GPIO_InitStruct.GPIO_Pin = SPI1_SCK_PIN | SPI1_MISO_PIN | SPI1_MOSI_PIN;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(SPI1_GPIO_PORT, &GPIO_InitStruct);

    /* Connect SPI1 pins to AF */
    GPIO_PinAFConfig(SPI1_GPIO_PORT, GPIO_PinSource5, GPIO_AF_0); // SCK
    GPIO_PinAFConfig(SPI1_GPIO_PORT, GPIO_PinSource6, GPIO_AF_0); // MISO
    GPIO_PinAFConfig(SPI1_GPIO_PORT, GPIO_PinSource7, GPIO_AF_0); // MOSI

    /* Configure SPI1 */
    SPI_StructInit(&SPI_InitStruct);
    SPI_InitStruct.SPI_Mode = SPI_Mode_Master;
    SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b;
    SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low;
    SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge;
    SPI_InitStruct.SPI_NSS = SPI_NSS_Soft;
    SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
    SPI_Init(SPI1, &SPI_InitStruct);

    /* Enable SPI1 */
    SPI_Cmd(SPI1, ENABLE);
}

/* Initialize MAX7219 */
void MAX7219_Init(void)
{
    /* Configure SPI1 */
    SPI1_Init();

    /* Send initialization data to MAX7219 */
    MAX7219_SendData(MAX7219_SCANLIMIT, 0x07);    // Display all digits
    MAX7219_SendData(MAX7219_DECODEMODE, 0x00);   // No decoding
    MAX7219_SendData(MAX7219_SHUTDOWN, 0x01);      // Normal operation
    MAX7219_SendData(MAX7219_DISPLAYTEST, 0x00);  // No display test
    MAX7219_SendData(MAX7219_INTENSITY, 0x0F);     // Maximum intensity
}

/* Send data to MAX7219 */
void MAX7219_SendData(uint8_t reg, uint8_t data)
{
    /* Select MAX7219 */
    GPIO_ResetBits(GPIOA, GPIO_Pin_4);

    /* Send data */
    SPI_I2S_SendData(SPI1, reg);
    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) != RESET) {}
    SPI_I2S_SendData(SPI1, data);
    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) != RESET) {}

    /* Deselect MAX7219 */
    GPIO_SetBits(GPIOA, GPIO_Pin_4);
}


// ----------------------------------------------------------------------------
// Function prototypes
// ----------------------------------------------------------------------------
void DAC_Setup(void);

// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
int main2(void)
{
  uint32_t i;
  
  // Configure LED3 and LED4 on STM32F0-Discovery
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
  
  // Initialize User Button on STM32F0-Discovery
  STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);
  
  DAC_Setup();
  
  while(1)
  {
    // Assuming Uled = 1.8 V
    // (4095 * 1.8) / 3 = 2457

    for(i=4095; i>2457; i--)
    {
      Delay(SystemCoreClock/8/1000);
      DAC_SetChannel1Data(DAC_Align_12b_R, i);
    }

    for(i=2457; i<=4095; i++)
    {
      Delay(SystemCoreClock/8/1000);
      DAC_SetChannel1Data(DAC_Align_12b_R, i);
    }
  }
}

/**
  * @brief  This function sets PA4 to analog mode and initializes
  *         DAC1.
  * @param  None
  * @retval None
  */
void DAC_Setup(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  DAC_InitTypeDef  DAC_InitStructure;
 
  //(+) Enable DAC APB1 clock to get write access to DAC registers
  //    using RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE)
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
  
  //(+) Configure DAC_OUT1 (DAC_OUT1: PA4) in analog mode
  //    using GPIO_Init() function  
  GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  
  //(+) Configure the DAC channel using DAC_Init()
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);
  
  //(+) Enable the DAC channel using DAC_Cmd()
  DAC_Cmd(DAC_Channel_1, ENABLE);
}

i tryed multiple things, MAX7219_SendData(MAX7219_SCANLIMIT, 0x07); SPI_I2S_SendData(SPI1, reg); and even digitalWrite(clock_pin,1); but nothing works.

  • Well, for starters, the MCU runs at 3.3V, while the peripheral IC runs at 5V. Does your 5V device recognize 3.3V signals? Are MCU's pins that interface with 5V signal actually 5V-tolerant? Implicit declaration could mean you messed up something with function declaration in header. In fact, that warning could be the reason it doesn't work. Compilation with some warnings (including this one) actually produces wrong code (wrong comparing to what you intended it to be). So the whole thing just does the wrong thing. – Ilya May 12 '23 at 14:28

0 Answers0