z Wyświetlaczami VFD 1x16 oraz klawiaturą, IR i kilkoma diodami.

Płytka ta posiada na pokładzie sterownik PT6302LQ-001 sterujący wyświetlaczem LCD oraz PT6958 czyli sterownik klawiatury i led

Na początek trzeba było rozwiązać zagadkę , który pin jest czym na złączu 10 pin , miernik w łapkę i szukamy
Złącze to tradycyjne 2x5IDC które musiałem wyciąć i tym sposobem została taśma 10 przewodowa, a jej połączenia są następujące:
(nie opisuję tak jak 2 IDC -- liczę od przewodu czerwonego)
1 -- IR DATA -- sygnał z odbiornika podczerwieni
2 -- GND
3 -- CLK (6302 i 6958)
4 -- DIN (6302 i 6958)
5 -- CS (6958)
6 -- nie znalazłem
7 -- CS (6302)
8 -- nie znalazłem
9 -- VCC 5V
10 -- RST (6302)

Do testów będzie użyta płytka STM32Butterfly2 z STM32F107VC
Tym sposobem powstała wstępna biblioteka obsługująca wyświetlacz z użyciem bibliotek HAL
-----> PT6302.h
- #ifndef __PT6302_H
- #define __PT6302_H
- #include "stm32f1xx_hal.h"
- // Struktura kontekstu panelu VFD
- typedef struct {
- SPI_HandleTypeDef *hspi;
- GPIO_TypeDef *stb_port;
- uint16_t stb_pin;
- } PT6302_HandleTypeDef;
- // Prototypy funkcji
- void PT6302_Init(PT6302_HandleTypeDef *h);
- void PT6302_Clear(PT6302_HandleTypeDef *h);
- void PT6302_SetBrightness(PT6302_HandleTypeDef *h, uint8_t level);
- void PT6302_DisplayOn(PT6302_HandleTypeDef *h, uint8_t on);
- void PT6302_WriteData(PT6302_HandleTypeDef *h, uint8_t addr, const char *text);
- void PT6302_Print(PT6302_HandleTypeDef *h, const char *text);
- #endif
- #include "pt6302.h"
- #include <string.h>
- #define PT6302_CMD_DISPLAY_MODE 0x00
- #define PT6302_CMD_DATA_SET 0x40
- #define PT6302_CMD_ADDR_SET 0xC0
- #define PT6302_CMD_DISPLAY_CTRL 0x80
- // --- Wewnętrzna funkcja przesyłania bajtu przez SPI ---
- static void PT6302_Send(PT6302_HandleTypeDef *h, uint8_t data)
- {
- HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_RESET);
- HAL_SPI_Transmit(h->hspi, &data, 1, HAL_MAX_DELAY);
- HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_SET);
- }
- // --- Inicjalizacja wyświetlacza ---
- void PT6302_Init(PT6302_HandleTypeDef *h)
- {
- HAL_Delay(50);
- PT6302_Send(h, PT6302_CMD_DISPLAY_MODE | 0x03); // tryb 16 znaków, 1 linia
- PT6302_SetBrightness(h, 7);
- PT6302_DisplayOn(h, 1);
- PT6302_Clear(h);
- }
- // --- Włączenie/wyłączenie wyświetlacza ---
- void PT6302_DisplayOn(PT6302_HandleTypeDef *h, uint8_t on)
- {
- PT6302_Send(h, PT6302_CMD_DISPLAY_CTRL | (on ? 0x08 : 0x00) | 0x07);
- }
- // --- Jasność (0–7) ---
- void PT6302_SetBrightness(PT6302_HandleTypeDef *h, uint8_t level)
- {
- if (level > 7) level = 7;
- PT6302_Send(h, PT6302_CMD_DISPLAY_CTRL | 0x08 | level);
- }
- // --- Wyczyść wyświetlacz ---
- void PT6302_Clear(PT6302_HandleTypeDef *h)
- {
- char buf[16];
- memset(buf, ' ', sizeof(buf));
- PT6302_WriteData(h, 0x00, buf);
- }
- // --- Zapis tekstu od danej pozycji ---
- void PT6302_WriteData(PT6302_HandleTypeDef *h, uint8_t addr, const char *text)
- {
- uint8_t len = strlen(text);
- HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_RESET);
- uint8_t cmd = PT6302_CMD_ADDR_SET | addr;
- HAL_SPI_Transmit(h->hspi, &cmd, 1, HAL_MAX_DELAY);
- HAL_SPI_Transmit(h->hspi, (uint8_t*)text, len, HAL_MAX_DELAY);
- HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_SET);
- }
- // --- Skrót: wydrukuj od początku ---
- void PT6302_Print(PT6302_HandleTypeDef *h, const char *text)
- {
- PT6302_WriteData(h, 0x00, text);
- }
- #ifndef __PT6958_H
- #define __PT6958_H
- #include "stm32f1xx_hal.h"
- typedef struct {
- SPI_HandleTypeDef *hspi;
- GPIO_TypeDef *stb_port;
- uint16_t stb_pin;
- } PT6958_HandleTypeDef;
- void PT6958_Init(PT6958_HandleTypeDef *h);
- void PT6958_SetLED(PT6958_HandleTypeDef *h, uint8_t led_index, uint8_t state);
- uint16_t PT6958_ReadKeys(PT6958_HandleTypeDef *h);
- #endif
--- PT6958.c
- #include "pt6958.h"
- #define PT6958_CMD_WRITE_DISPLAY 0x40
- #define PT6958_CMD_ADDR_SET 0xC0
- #define PT6958_CMD_DISPLAY_CTRL 0x80
- static void PT6958_Send(PT6958_HandleTypeDef *h, uint8_t data)
- {
- HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_RESET);
- HAL_SPI_Transmit(h->hspi, &data, 1, HAL_MAX_DELAY);
- HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_SET);
- }
- void PT6958_Init(PT6958_HandleTypeDef *h)
- {
- PT6958_Send(h, PT6958_CMD_WRITE_DISPLAY);
- PT6958_Send(h, PT6958_CMD_DISPLAY_CTRL | 0x0F); // Display ON, brightness max
- }
- void PT6958_SetLED(PT6958_HandleTypeDef *h, uint8_t led_index, uint8_t state)
- {
- uint8_t addr = 0x00 + led_index;
- uint8_t data = state ? 0xFF : 0x00;
- HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_RESET);
- uint8_t cmd = PT6958_CMD_ADDR_SET | addr;
- HAL_SPI_Transmit(h->hspi, &cmd, 1, HAL_MAX_DELAY);
- HAL_SPI_Transmit(h->hspi, &data, 1, HAL_MAX_DELAY);
- HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_SET);
- }
- uint16_t PT6958_ReadKeys(PT6958_HandleTypeDef *h)
- {
- uint8_t cmd = 0x42;
- uint8_t buf[2] = {0};
- HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_RESET);
- HAL_SPI_Transmit(h->hspi, &cmd, 1, HAL_MAX_DELAY);
- HAL_SPI_Receive(h->hspi, buf, 2, HAL_MAX_DELAY);
- HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_SET);
- return (buf[1] << 8) | buf[0];
- }
Nie mniej powinno zadziałać. W załączniku noty obu układów: