cancel
Showing results for 
Search instead for 
Did you mean: 

I have a problem with my 8x8 click module, I tried everything with my Stm32 F4.. and I cant get it work. Can someone PLEASE help me?

SSimi.1
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

OK, this is done with a bit-shift operation, which you can of course also insert directly as a parameter.

So, if you want to move bit7 (MSB) 7 bit positions to bit0 to transfer it to the GPIO, as in your example, you should use in line 86:

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, (byte&0x80) >>7);

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

12 REPLIES 12
SSimi.1
Associate II
#define DECODEMODE		0x09
#define POWERMODE		0x0c
#define TESTMODE		0x0f
#define BRIGHTNESS		0x0a
#define SCANLIMIT		0x0b
 
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi3;
 
UART_HandleTypeDef huart2;
 
/* USER CODE BEGIN PV */
 
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI3_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
uint8_t display[38][8]={
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//0
{0x10,0x30,0x50,0x10,0x10,0x10,0x10,0x7c},//1
{0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E},//2
{0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0},//3
{0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8},//4
{0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0},//5
{0x3C,0x20,0x20,0x3C,0x24,0x24,0x3C,0x0},//6
{0x3E,0x22,0x4,0x8,0x8,0x8,0x8,0x8},//7
{0x0,0x3E,0x22,0x22,0x3E,0x22,0x22,0x3E},//8
{0x3E,0x22,0x22,0x3E,0x2,0x2,0x2,0x3E},//9
{0x18,0x24,0x42,0x42,0x7E,0x42,0x42,0x42},//A
{0x3C,0x22,0x22,0x3c,0x22,0x22,0x3C,0x0},//B
{0x3C,0x40,0x40,0x40,0x40,0x40,0x40,0x3C},//C
{0x7C,0x22,0x22,0x22,0x22,0x22,0x22,0x7C},//D
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x7C},//E
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x40},//F
{0x3C,0x40,0x40,0x40,0x4c,0x44,0x44,0x3C},//G
{0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x44},//H
{0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C},//I
{0x3C,0x8,0x8,0x8,0x8,0x8,0x48,0x30},//J
{0x0,0x24,0x28,0x30,0x20,0x30,0x28,0x24},//K
{0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7C},//L
{0x81,0xC3,0xA5,0x99,0x81,0x81,0x81,0x81},//M
{0x0,0x42,0x62,0x52,0x4A,0x46,0x42,0x0},//N
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//O
{0x3C,0x22,0x22,0x22,0x3C,0x20,0x20,0x20},//P
{0x1C,0x22,0x22,0x22,0x22,0x26,0x22,0x1D},//Q
{0x3C,0x22,0x22,0x22,0x3C,0x24,0x22,0x21},//R
{0x0,0x1E,0x20,0x20,0x3E,0x2,0x2,0x3C},//S
{0x0,0x3E,0x8,0x8,0x8,0x8,0x8,0x8},//T
{0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1C},//U
{0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18},//V
{0x0,0x49,0x49,0x49,0x49,0x2A,0x1C,0x0},//W
{0x0,0x41,0x22,0x14,0x8,0x14,0x22,0x41},//X
{0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8},//Y
{0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F},//Z
};
 
char *txt = "Willkommen im Testbildschirm.\r\nWaehle mit dem Button am Shield-Board, welches Testmodi du benutzen moechtest.\r\n";
char *case1 = "1. Hauptmodi\r\n";
char *case2 = "2. 8x8 G Click\r\n";
char *case3 = "3. Proximity Click\r\n";
char *take1 = "Hauptmodi wurde gestartet!\r\n";
char *take2 = "8x8 G Click wurde gestartet!\r\n";
char *take3 = "Proximity Click wurde gestartet!\r\n";
 
uint8_t test [8] = {0x18,0x24,0x42,0x42,0x7E,0x42,0x42,0x42};
 
///////////////////////////////////////////////////////////////////////////////////////////////
void write_byte (uint8_t byte) {
		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1);  // CLK hoch
        HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, byte&0x80);// Auf MSB über MOSI schreiben
	    byte = byte<<1;  // shift the data to the left
	    HAL_SPI_Transmit(&hspi3, &byte, 1, HAL_MAX_DELAY);
	    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0);  // CLK runter
}
 
void write_max (uint8_t address, uint8_t data) {
	//HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_RESET);
	HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,0);
	write_byte (address);
	write_byte (data);
	//HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_SET);
	HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,1);
}
 
void max_init(void) {
	write_max(POWERMODE, 0x00);		 //  power down = 0
	write_max(POWERMODE, 0x01);      //  normal mode = 1
	write_max(TESTMODE, 0x01);       //  test display
	write_max(SCANLIMIT, 0x07);      //  scan limit = 8 LEDs
	write_max(BRIGHTNESS, 0x05);     //  brightness intensity
	write_max(DECODEMODE, 0x00);     //  no decoding
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
int uart_putc(unsigned char c) {
	HAL_UART_Transmit(&huart2, &c, 1, 100);
    return 0;
}
 
void uart_puts (char *s) {
  while (*s) {
    uart_putc(*s);
    s++;
  }
}
/* 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. */
  HAL_Init();
 
  /* 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_SPI3_Init();
  MX_USART2_UART_Init();
  /* USER CODE BEGIN 2 */
  max_init();
  /*for(int i = 0; i < 38; i++) {
  	for(int j = 0; j < 8; j++) {
  		write_max(i, display[i][j-1]);
  	    //HAL_SPI_Transmit(&hspi3, &display[i][j], 1, 100);
  	    while(HAL_SPI_GetState(&hspi3)!=HAL_SPI_STATE_READY);
  	}
  }*/
  /*uart_puts((char *)txt);
  uart_puts((char *)case1);
  uart_puts((char *)case2);
  uart_puts((char *)case3);
  uint8_t choice;
  scanf("%d",choice);
  HAL_UART_Transmit(&huart2, &choice, 1, 100);
 
  switch(choice) {
  case 1:
	  uart_puts((char *)take1);
  case 2:
	  uart_puts((char *)take2);
  case 3:
	  uart_puts((char *)take3);
  }*/
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

TDK
Guru

Where are you getting stuck? Provide some context instead of just dumping code. Can you view signals on a scope?

If you feel a post has answered your question, please click "Accept as Solution".
SSimi.1
Associate II

I cant send signals to the leds. I also cant see signals, because I am not sure, if I use the Logic Analyzer right.

Peter BENSCH
ST Employee

Have you already taken a look at the MAX7219 datasheet? It is operated with 5V and needs at least 3.5V to recognize a logical 1 at the logic inputs.

The STM32 runs at 3.3V and is 5V tolerant on many pins, but then you also need to select/program the correct GPIO mode. However, the GPIO initialization is not visible in your code listing, so nobody can know what you have set there.

Devices that work with 5V logic, such as the MAX7219, must be driven with open-drain and pull-up.

By the way, you've essentially asked this question before, haven't you?

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
SSimi.1
Associate II

I know this fact. Yesterday I was going the configuration with my teacher through and he said, that it is fine and that the 5V thing is not "necessary", because it worked also from other students. The proble ist just in the code and I think its the write_byte function.

Yeah, I asked this question before.

Regards,

Srdjan

Peter BENSCH
ST Employee

Consider what parameters HAL_GPIO_WritePin expects and what you provided in write_byte.

Hint: result of the masked value vs. required parameter

But again - it's purely coincidental that it works if you want to drive a 5V CMOS input with 3.3V CMOS levels. This can also be configured with code, so it's also something like "just in the code".

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
SSimi.1
Associate II

So you mean I should set the value first and then send it via HAL_GPIO_WritePin?

I also changed now the pins on Pull Up and CS on Open Drain

Peter BENSCH
ST Employee

No, I gave a tip so that you can at least find one error (if there are several, which I haven't checked yet). The tip is that you have to look at what HAL_GPIO_WritePin wants as a parameter and then compare that with your passed parameters.

Well, the first two parameters are quite clear and - you'll agree - correct, right? (well, hopefully, because nobody here knows what you have connected to which pin).

Then what about the third parameter, which you calculate directly in the call (which is of course allowed) - what does HAL_GPIO_WritePin want to see there and what values does your calculation result in?

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
SSimi.1
Associate II

The HAL_GPIO_WritePin wants to see just 1 or 0, so this line i "garbage". But how I can write the data to lets say D1 otherwise?

0693W00000JMiTCQA1.png